* BinaryClientFormatterSink.cs: Don't set the request uri here, this will
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels / BinaryCore.cs
1 //
2 // System.Runtime.Remoting.Channels.BinaryCore.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
5 //
6 // 2003 (C) Copyright, Novell, Inc.
7 //
8
9 using System.Collections;
10 using System.Runtime.Remoting.Messaging;
11 using System.Runtime.Serialization;
12 using System.Runtime.Serialization.Formatters;
13 using System.Runtime.Serialization.Formatters.Binary;
14
15 namespace System.Runtime.Remoting.Channels
16 {
17         internal class BinaryCore
18         {
19                 BinaryFormatter _serializationFormatter;
20                 BinaryFormatter _deserializationFormatter;
21                 bool _includeVersions = true;
22                 bool _strictBinding = false;
23                 
24 #if NET_1_1
25                 TypeFilterLevel _filterLevel = TypeFilterLevel.Low;
26 #endif
27                 
28                 public static BinaryCore DefaultInstance = new BinaryCore ();
29                 
30                 public BinaryCore (object owner, IDictionary properties, string[] allowedProperties)
31                 {
32                         foreach(DictionaryEntry property in properties)
33                         {
34                                 string key = (string) property.Key;
35                                 if (Array.IndexOf (allowedProperties, key) == -1)
36                                         throw new RemotingException (owner.GetType().Name + " does not recognize '" + key + "' configuration property");
37                                 
38                                 switch (key)
39                                 {
40                                         case "includeVersions": 
41                                                 _includeVersions = Convert.ToBoolean (property.Value);
42                                                 break;
43                                                 
44                                         case "strictBinding":
45                                                 _strictBinding = Convert.ToBoolean (property.Value);
46                                                 break;
47                                                 
48 #if NET_1_1
49                                         case "typeFilterLevel":
50                                                 if (property.Value is TypeFilterLevel)
51                                                         _filterLevel = (TypeFilterLevel) property.Value;
52                                                 else {
53                                                         string s = (string) property.Value;
54                                                         _filterLevel = (TypeFilterLevel) Enum.Parse (typeof(TypeFilterLevel), s);
55                                                 }
56                                                 break;
57 #endif
58                                                 
59                                 }
60                         }
61                         
62                         Init ();
63                 }
64                 
65                 public BinaryCore ()
66                 {
67                         Init ();
68                 }
69                 
70                 public void Init ()
71                 {
72                         RemotingSurrogateSelector surrogateSelector = new RemotingSurrogateSelector ();
73                         StreamingContext context = new StreamingContext (StreamingContextStates.Remoting, null);
74
75                         _serializationFormatter = new BinaryFormatter (surrogateSelector, context);
76                         _deserializationFormatter = new BinaryFormatter (null, context);
77                         
78 #if NET_1_1
79                         _serializationFormatter.FilterLevel = _filterLevel;
80                         _deserializationFormatter.FilterLevel = _filterLevel;
81 #endif
82                         
83                         if (!_includeVersions)
84                         {
85                                 _serializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
86                                 _deserializationFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
87                         }
88
89                         if (!_strictBinding)
90                         {
91                                 _serializationFormatter.Binder = ChannelCore.SimpleBinder;
92                                 _deserializationFormatter.Binder = ChannelCore.SimpleBinder;
93                         }
94                 }
95                 
96                 public BinaryFormatter Serializer
97                 {
98                         get { return _serializationFormatter; }
99                 }
100                 
101                 public BinaryFormatter Deserializer
102                 {
103                         get { return _deserializationFormatter; }
104                 }
105                 
106 #if NET_1_1
107                 public TypeFilterLevel TypeFilterLevel
108                 {
109                         get { return _filterLevel; }
110                 }
111 #endif
112         }
113 }
114