2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / corlib / System.Runtime.Remoting.Messaging / LogicalCallContext.cs
blob30398dfa10b40d0f58a2c3c8f75a3d80b86391fa
1 //
2 // System.Runtime.Remoting.Messaging.LogicalCallContext.cs
3 //
4 // Author:
5 // Dan Lewis (dihlewis@yahoo.co.uk)
6 // Lluis Sanchez Gual (lluis@ximian.com)
7 //
8 // 2002 (C) Copyright. Ximian, Inc.
9 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
35 using System.Runtime.Serialization;
37 namespace System.Runtime.Remoting.Messaging
39 [Serializable]
40 [System.Runtime.InteropServices.ComVisible (true)]
41 public sealed class LogicalCallContext : ISerializable, ICloneable
43 Hashtable _data;
44 CallContextRemotingData _remotingData = new CallContextRemotingData();
46 internal LogicalCallContext ()
50 internal LogicalCallContext (SerializationInfo info, StreamingContext context)
52 foreach (SerializationEntry entry in info)
54 if (entry.Name == "__RemotingData")
55 _remotingData = (CallContextRemotingData) entry.Value;
56 else
57 SetData (entry.Name, entry.Value);
61 public bool HasInfo
63 get
65 return (_data != null && _data.Count > 0);
69 public void FreeNamedDataSlot (string name)
71 if (_data != null)
72 _data.Remove (name);
75 public object GetData (string name)
77 if (_data != null) return _data [name];
78 else return null;
81 public void GetObjectData (SerializationInfo info, StreamingContext context)
83 info.AddValue ("__RemotingData", _remotingData);
84 if (_data != null)
86 foreach (DictionaryEntry de in _data)
87 info.AddValue ((string)de.Key, de.Value);
91 public void SetData (string name, object data)
93 if (_data == null) _data = new Hashtable ();
94 _data [name] = data;
97 public object Clone ()
99 LogicalCallContext nc = new LogicalCallContext ();
100 nc._remotingData = (CallContextRemotingData) _remotingData.Clone ();
101 if (_data != null)
103 nc._data = new Hashtable ();
104 foreach (DictionaryEntry de in _data)
105 nc._data [de.Key] = de.Value;
107 return nc;
110 internal Hashtable Datastore
112 get { return _data; }
116 [Serializable]
117 internal class CallContextRemotingData : ICloneable
119 string _logicalCallID;
121 public string LogicalCallID
123 get { return _logicalCallID; }
124 set { _logicalCallID = value; }
127 public object Clone ()
129 CallContextRemotingData data = new CallContextRemotingData ();
130 data._logicalCallID = _logicalCallID;
131 return data;