mscorlib(4.0.0.0) API with additions
CallContext.cs
2 using System.Security;
4 using System.Threading;
5 
7 {
10  [SecurityCritical]
11  [ComVisible(true)]
12  public sealed class CallContext
13  {
14  internal static IPrincipal Principal
15  {
16  [SecurityCritical]
17  get
18  {
19  return Thread.CurrentThread.GetExecutionContextReader().LogicalCallContext.Principal;
20  }
21  [SecurityCritical]
22  set
23  {
24  Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext.Principal = value;
25  }
26  }
27 
31  public static object HostContext
32  {
33  [SecurityCritical]
34  get
35  {
36  ExecutionContext.Reader executionContextReader = Thread.CurrentThread.GetExecutionContextReader();
37  object hostContext = executionContextReader.IllogicalCallContext.HostContext;
38  if (hostContext == null)
39  {
40  hostContext = executionContextReader.LogicalCallContext.HostContext;
41  }
42  return hostContext;
43  }
44  [SecurityCritical]
45  set
46  {
47  ExecutionContext mutableExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();
48  if (value is ILogicalThreadAffinative)
49  {
50  mutableExecutionContext.IllogicalCallContext.HostContext = null;
51  mutableExecutionContext.LogicalCallContext.HostContext = value;
52  }
53  else
54  {
55  mutableExecutionContext.IllogicalCallContext.HostContext = value;
56  mutableExecutionContext.LogicalCallContext.HostContext = null;
57  }
58  }
59  }
60 
61  private CallContext()
62  {
63  }
64 
65  internal static LogicalCallContext SetLogicalCallContext(LogicalCallContext callCtx)
66  {
67  ExecutionContext mutableExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();
68  LogicalCallContext logicalCallContext = mutableExecutionContext.LogicalCallContext;
69  mutableExecutionContext.LogicalCallContext = callCtx;
70  return logicalCallContext;
71  }
72 
76  [SecurityCritical]
77  public static void FreeNamedDataSlot(string name)
78  {
79  ExecutionContext mutableExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();
80  mutableExecutionContext.LogicalCallContext.FreeNamedDataSlot(name);
81  mutableExecutionContext.IllogicalCallContext.FreeNamedDataSlot(name);
82  }
83 
88  [SecurityCritical]
89  public static object LogicalGetData(string name)
90  {
91  return Thread.CurrentThread.GetExecutionContextReader().LogicalCallContext.GetData(name);
92  }
93 
94  private static object IllogicalGetData(string name)
95  {
96  return Thread.CurrentThread.GetExecutionContextReader().IllogicalCallContext.GetData(name);
97  }
98 
103  [SecurityCritical]
104  public static object GetData(string name)
105  {
106  object obj = LogicalGetData(name);
107  if (obj == null)
108  {
109  return IllogicalGetData(name);
110  }
111  return obj;
112  }
113 
118  [SecurityCritical]
119  public static void SetData(string name, object data)
120  {
121  if (data is ILogicalThreadAffinative)
122  {
123  LogicalSetData(name, data);
124  return;
125  }
126  ExecutionContext mutableExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();
127  mutableExecutionContext.LogicalCallContext.FreeNamedDataSlot(name);
128  mutableExecutionContext.IllogicalCallContext.SetData(name, data);
129  }
130 
135  [SecurityCritical]
136  public static void LogicalSetData(string name, object data)
137  {
138  ExecutionContext mutableExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();
139  mutableExecutionContext.IllogicalCallContext.FreeNamedDataSlot(name);
140  mutableExecutionContext.LogicalCallContext.SetData(name, data);
141  }
142 
146  [SecurityCritical]
147  public static Header[] GetHeaders()
148  {
149  LogicalCallContext logicalCallContext = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
150  return logicalCallContext.InternalGetHeaders();
151  }
152 
156  [SecurityCritical]
157  public static void SetHeaders(Header[] headers)
158  {
159  LogicalCallContext logicalCallContext = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
160  logicalCallContext.InternalSetHeaders(headers);
161  }
162  }
163 }
static Thread CurrentThread
Gets the currently running thread.
Definition: Thread.cs:134
Marks an object that can propagate outside of an T:System.AppDomain in a T:System....
Defines the basic functionality of a principal object.
Definition: IPrincipal.cs:8
Definition: __Canon.cs:3
static object HostContext
Gets or sets the host context associated with the current thread.
Definition: CallContext.cs:32
static void SetHeaders(Header[] headers)
Sets the headers that are sent along with the method call.
Definition: CallContext.cs:157
static void LogicalSetData(string name, object data)
Stores a given object in the logical call context and associates it with the specified name.
Definition: CallContext.cs:136
Manages the execution context for the current thread. This class cannot be inherited.
static Header [] GetHeaders()
Returns the headers that are sent along with the method call.
Definition: CallContext.cs:147
Provides a set of properties that are carried with the execution code path. This class cannot be inhe...
Definition: CallContext.cs:12
Defines the out-of-band data for a call.
Definition: Header.cs:8
Provides a set of properties that are carried with the execution code path during remote method calls...
static object GetData(string name)
Retrieves an object with the specified name from the T:System.Runtime.Remoting.Messaging....
Definition: CallContext.cs:104
Specifies that the class can be serialized.
static void FreeNamedDataSlot(string name)
Empties a data slot with the specified name.
Definition: CallContext.cs:77
static void SetData(string name, object data)
Stores a given object and associates it with the specified name.
Definition: CallContext.cs:119
static object LogicalGetData(string name)
Retrieves an object with the specified name from the logical call context.
Definition: CallContext.cs:89
Creates and controls a thread, sets its priority, and gets its status.
Definition: Thread.cs:18