{
[Serializable]
+ [System.Runtime.InteropServices.ComVisible (true)]
public sealed class CallContext
{
[ThreadStatic] static Header [] Headers;
+ [ThreadStatic] static Hashtable logicalDatastore;
[ThreadStatic] static Hashtable datastore;
+ [ThreadStatic] static object hostContext;
private CallContext ()
{
}
+ public static object HostContext {
+ get { return hostContext; }
+ set { hostContext = value; }
+ }
+
// public methods
public static void FreeNamedDataSlot (string name)
{
Datastore.Remove (name);
+ LogicalDatastore.Remove (name);
}
public static object GetData (string name)
{
- return Datastore [name];
+ if (LogicalDatastore.ContainsKey (name)) {
+ return LogicalDatastore [name];
+ } else {
+ return Datastore [name];
+ }
}
public static void SetData (string name, object data)
{
- Datastore [name] = data;
+ if (data is ILogicalThreadAffinative) {
+ LogicalSetData (name, data);
+ } else {
+ LogicalDatastore.Remove (name);
+ Datastore [name] = data;
+ }
+ }
+
+ public static object LogicalGetData (string name)
+ {
+ return LogicalDatastore [name];
+ }
+
+ public static void LogicalSetData (string name, object data)
+ {
+ Datastore.Remove (name);
+ LogicalDatastore [name] = data;
}
public static Header[] GetHeaders ()
internal static LogicalCallContext CreateLogicalCallContext (bool createEmpty)
{
LogicalCallContext ctx = null;
- if (datastore != null) {
- foreach (DictionaryEntry entry in datastore)
- if (entry.Value is ILogicalThreadAffinative) {
- if (ctx == null) ctx = new LogicalCallContext ();
- ctx.SetData ((string)entry.Key, entry.Value);
- }
+ if (logicalDatastore != null) {
+ ctx = new LogicalCallContext ();
+ foreach (DictionaryEntry entry in logicalDatastore) {
+ ctx.SetData ((string)entry.Key, entry.Value);
+ }
}
if (ctx == null && createEmpty)
internal static object SetCurrentCallContext (LogicalCallContext ctx)
{
- object oldData = datastore;
+ object oldData = new object[] { datastore, logicalDatastore };
if (ctx != null && ctx.HasInfo)
- datastore = (Hashtable) ctx.Datastore.Clone ();
+ logicalDatastore = (Hashtable) ctx.Datastore.Clone ();
else
- datastore = null;
+ logicalDatastore = null;
return oldData;
}
- internal static void UpdateCurrentCallContext (LogicalCallContext ctx)
+ internal static void UpdateCurrentLogicalCallContext (LogicalCallContext ctx)
{
Hashtable data = ctx.Datastore;
+ if (data == null)
+ return;
+
foreach (DictionaryEntry entry in data)
- SetData ((string)entry.Key, entry.Value);
+ LogicalSetData ((string)entry.Key, entry.Value);
}
internal static void RestoreCallContext (object oldContext)
{
- datastore = (Hashtable) oldContext;
+ object[] contextArray = (object[])oldContext;
+ datastore = (Hashtable)contextArray [0];
+ logicalDatastore = (Hashtable)contextArray [1];
}
private static Hashtable Datastore
return r;
}
}
+
+ private static Hashtable LogicalDatastore
+ {
+ get {
+ Hashtable r = logicalDatastore;
+ if (r == null)
+ return logicalDatastore = new Hashtable ();
+ return r;
+ }
+ }
}
+ [System.Runtime.InteropServices.ComVisible (true)]
public interface ILogicalThreadAffinative
{
}