Merge pull request #1659 from alexanderkyte/stringbuilder-referencesource
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / LogicalCallContext.cs
1 //
2 // System.Runtime.Remoting.Messaging.LogicalCallContext.cs
3 //
4 // Authors:
5 //   Dan Lewis (dihlewis@yahoo.co.uk)
6 //   Lluis Sanchez Gual (lluis@ximian.com)
7 //   Marek Safar (marek.safar@gmail.com)
8 //
9 // 2002 (C) Copyright. Ximian, Inc.
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System.Collections;
34 using System.Runtime.Serialization;
35
36 namespace System.Runtime.Remoting.Messaging 
37 {
38         [Serializable]
39         [System.Runtime.InteropServices.ComVisible (true)]
40         public sealed class LogicalCallContext : ISerializable, ICloneable
41         {
42                 Hashtable _data;
43                 CallContextRemotingData _remotingData = new CallContextRemotingData();
44                 
45                 internal LogicalCallContext ()
46                 {
47                 }
48
49                 internal LogicalCallContext (SerializationInfo info, StreamingContext context)
50                 {
51                         foreach (SerializationEntry entry in info)
52                         {
53                                 if (entry.Name == "__RemotingData")
54                                         _remotingData = (CallContextRemotingData) entry.Value;
55                                 else
56                                         SetData (entry.Name, entry.Value);
57                         }
58                 }
59
60                 public bool HasInfo {
61                         get {
62                                 return _data != null && _data.Count > 0;
63                         }
64                 }
65
66                 public void FreeNamedDataSlot (string name)
67                 {
68                         if (_data != null)
69                                 _data.Remove (name);
70                 }
71
72                 public object GetData (string name)
73                 {
74                         return _data != null ? _data [name] : null;
75                 }
76
77                 public void GetObjectData (SerializationInfo info, StreamingContext context)
78                 {
79                         info.AddValue ("__RemotingData", _remotingData);
80                         if (_data != null)
81                         {
82                                 foreach (DictionaryEntry de in _data)
83                                         info.AddValue ((string)de.Key, de.Value);
84                         }
85                 }
86
87                 public void SetData (string name, object data)
88                 {
89                         if (_data == null) 
90                                 _data = new Hashtable ();
91                         _data [name] = data;
92                 }
93
94                 public object Clone ()
95                 {
96                         LogicalCallContext nc = new LogicalCallContext ();
97                         nc._remotingData = (CallContextRemotingData) _remotingData.Clone ();
98                         if (_data != null)
99                                 nc._data = (Hashtable) _data.Clone ();
100
101                         return nc;
102                 }
103
104                 internal Hashtable Datastore {
105                         get { return _data; }
106                         set { _data = value; }
107                 }
108
109                 internal CallContextRemotingData RemotingData {
110                         get {
111                                 return _remotingData;
112                         }
113                 }
114         }
115
116         [Serializable]
117         internal class CallContextRemotingData : ICloneable
118         {
119                 string _logicalCallID;
120
121                 public string LogicalCallID
122                 {
123                         get { return _logicalCallID; }
124                         set { _logicalCallID = value; }
125                 }
126
127                 public object Clone ()
128                 {
129                         CallContextRemotingData data = new CallContextRemotingData ();
130                         data._logicalCallID = _logicalCallID;
131                         return data;
132                 }
133 }
134 }
135