public sealed class CallContext
{
[ThreadStatic] static Header [] Headers;
+ [ThreadStatic] static Hashtable logicalDatastore;
[ThreadStatic] static Hashtable datastore;
[ThreadStatic] static object hostContext;
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;
+ }
}
-
- [MonoTODO]
+
public static object LogicalGetData (string name)
{
- throw new NotImplementedException ();
+ return LogicalDatastore [name];
}
-
- [MonoTODO]
+
public static void LogicalSetData (string name, object data)
{
- throw new NotImplementedException ();
+ 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;
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)]
{
if (ExecutionContext.IsFlowSuppressed ())
ExecutionContext.RestoreFlow ();
+
+ CallContext.FreeNamedDataSlot ("testlc");
+ }
+
+ [Test]
+ [Category("MobileNotWorking")]
+ public void LogicalGetData_SetData()
+ {
+ var value = "a";
+
+ CallContext.SetData ("testlc", value);
+ var capturedValue = CallContext.LogicalGetData ("testlc");
+
+ Assert.IsNull (capturedValue);
+ }
+
+ [Test]
+ [Category("MobileNotWorking")]
+ public void LogicalGetData_SetDataLogicalThreadAffinative()
+ {
+ var value = new CallContextValue ("a");
+
+ CallContext.SetData ("testlc", value);
+ var capturedValue = CallContext.LogicalGetData ("testlc");
+
+ Assert.AreEqual (value, capturedValue);
+ }
+
+ [Test]
+ [Category("MobileNotWorking")]
+ public void GetData_SetLogicalData()
+ {
+ var value = "a";
+
+ CallContext.LogicalSetData ("testlc", value);
+ var capturedValue = CallContext.GetData ("testlc");
+
+ Assert.AreEqual (value, capturedValue);
+ }
+
+ [Test]
+ [Category("MobileNotWorking")]
+ public void CaptureLogicalCallContext()
+ {
+ var value = "Tester";
+ object capturedValue = null;
+
+ CallContext.LogicalSetData ("testlc", value);
+
+ ExecutionContext ec = ExecutionContext.Capture ();
+ Assert.IsNotNull (ec, "Capture");
+ Assert.AreEqual (value, CallContext.LogicalGetData ("testlc"));
+ CallContext.LogicalSetData ("testlc", null);
+
+ ExecutionContext.Run (ec, new ContextCallback (new Action<object> ((data) => {
+ capturedValue = CallContext.LogicalGetData ("testlc");
+ })), null);
+
+ Assert.AreEqual (value, capturedValue);
+ Assert.AreNotEqual (value, CallContext.LogicalGetData ("testlc"));
}
[Test]