using System; using System.Collections; using System.Runtime.InteropServices; using System.Runtime.Remoting.Activation; using System.Runtime.Remoting.Lifetime; using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting.Proxies; using System.Threading; namespace System.Runtime.Remoting.Contexts { /// Defines an environment for the objects that are resident inside it and for which a policy can be enforced. // Token: 0x020003B8 RID: 952 [ComVisible(true)] public class Context { /// Initializes a new instance of the class. // Token: 0x060025E8 RID: 9704 RVA: 0x0007CF64 File Offset: 0x0007B164 public Context() { this.domain_id = Thread.GetDomainID(); this.context_id = 1 + Context.global_count++; } /// Cleans up the backing objects for the nondefault contexts. // Token: 0x060025EA RID: 9706 RVA: 0x0007CFA4 File Offset: 0x0007B1A4 ~Context() { } /// Gets the default context for the current application domain. /// The default context for the namespace. /// /// /// // Token: 0x17000715 RID: 1813 // (get) Token: 0x060025EB RID: 9707 RVA: 0x0007CFDC File Offset: 0x0007B1DC public static Context DefaultContext { get { return AppDomain.InternalGetDefaultContext(); } } /// Gets the context ID for the current context. /// The context ID for the current context. /// /// /// // Token: 0x17000716 RID: 1814 // (get) Token: 0x060025EC RID: 9708 RVA: 0x0007CFE4 File Offset: 0x0007B1E4 public virtual int ContextID { get { return this.context_id; } } /// Gets the array of the current context properties. /// The current context properties array; otherwise, null if the context does not have any properties attributed to it. /// /// /// // Token: 0x17000717 RID: 1815 // (get) Token: 0x060025ED RID: 9709 RVA: 0x0007CFEC File Offset: 0x0007B1EC public virtual IContextProperty[] ContextProperties { get { if (this.context_properties == null) { return new IContextProperty[0]; } return (IContextProperty[])this.context_properties.ToArray(typeof(IContextProperty[])); } } // Token: 0x17000718 RID: 1816 // (get) Token: 0x060025EE RID: 9710 RVA: 0x0007D028 File Offset: 0x0007B228 internal bool IsDefaultContext { get { return this.context_id == 0; } } // Token: 0x17000719 RID: 1817 // (get) Token: 0x060025EF RID: 9711 RVA: 0x0007D034 File Offset: 0x0007B234 internal bool NeedsContextSink { get { return this.context_id != 0 || (Context.global_dynamic_properties != null && Context.global_dynamic_properties.HasProperties) || (this.context_dynamic_properties != null && this.context_dynamic_properties.HasProperties); } } /// Registers a dynamic property implementing the interface with the remoting service. /// true if the property was successfully registered; otherwise, false. /// The dynamic property to register. /// The object/proxy for which the is registered. /// The context for which the is registered. /// Either or its name is null, or it is not dynamic (it does not implement ). /// Both an object as well as a context are specified (both and are not null). /// /// /// // Token: 0x060025F0 RID: 9712 RVA: 0x0007D084 File Offset: 0x0007B284 public static bool RegisterDynamicProperty(IDynamicProperty prop, ContextBoundObject obj, Context ctx) { DynamicPropertyCollection dynamicPropertyCollection = Context.GetDynamicPropertyCollection(obj, ctx); return dynamicPropertyCollection.RegisterDynamicProperty(prop); } /// Unregisters a dynamic property implementing the interface. /// true if the object was successfully unregistered; otherwise, false. /// The name of the dynamic property to unregister. /// The object/proxy for which the is registered. /// The context for which the is registered. /// The parameter is null. /// Both an object as well as a context are specified (both and are not null). /// /// /// // Token: 0x060025F1 RID: 9713 RVA: 0x0007D0A0 File Offset: 0x0007B2A0 public static bool UnregisterDynamicProperty(string name, ContextBoundObject obj, Context ctx) { DynamicPropertyCollection dynamicPropertyCollection = Context.GetDynamicPropertyCollection(obj, ctx); return dynamicPropertyCollection.UnregisterDynamicProperty(name); } // Token: 0x060025F2 RID: 9714 RVA: 0x0007D0BC File Offset: 0x0007B2BC private static DynamicPropertyCollection GetDynamicPropertyCollection(ContextBoundObject obj, Context ctx) { if (ctx == null && obj != null) { if (RemotingServices.IsTransparentProxy(obj)) { RealProxy realProxy = RemotingServices.GetRealProxy(obj); return realProxy.ObjectIdentity.ClientDynamicProperties; } return obj.ObjectIdentity.ServerDynamicProperties; } else { if (ctx != null && obj == null) { if (ctx.context_dynamic_properties == null) { ctx.context_dynamic_properties = new DynamicPropertyCollection(); } return ctx.context_dynamic_properties; } if (ctx == null && obj == null) { if (Context.global_dynamic_properties == null) { Context.global_dynamic_properties = new DynamicPropertyCollection(); } return Context.global_dynamic_properties; } throw new ArgumentException("Either obj or ctx must be null"); } } // Token: 0x060025F3 RID: 9715 RVA: 0x0007D158 File Offset: 0x0007B358 internal static void NotifyGlobalDynamicSinks(bool start, IMessage req_msg, bool client_site, bool async) { if (Context.global_dynamic_properties != null && Context.global_dynamic_properties.HasProperties) { Context.global_dynamic_properties.NotifyMessage(start, req_msg, client_site, async); } } // Token: 0x1700071A RID: 1818 // (get) Token: 0x060025F4 RID: 9716 RVA: 0x0007D184 File Offset: 0x0007B384 internal static bool HasGlobalDynamicSinks { get { return Context.global_dynamic_properties != null && Context.global_dynamic_properties.HasProperties; } } // Token: 0x060025F5 RID: 9717 RVA: 0x0007D1A0 File Offset: 0x0007B3A0 internal void NotifyDynamicSinks(bool start, IMessage req_msg, bool client_site, bool async) { if (this.context_dynamic_properties != null && this.context_dynamic_properties.HasProperties) { this.context_dynamic_properties.NotifyMessage(start, req_msg, client_site, async); } } // Token: 0x1700071B RID: 1819 // (get) Token: 0x060025F6 RID: 9718 RVA: 0x0007D1D0 File Offset: 0x0007B3D0 internal bool HasDynamicSinks { get { return this.context_dynamic_properties != null && this.context_dynamic_properties.HasProperties; } } // Token: 0x1700071C RID: 1820 // (get) Token: 0x060025F7 RID: 9719 RVA: 0x0007D1EC File Offset: 0x0007B3EC internal bool HasExitSinks { get { return !(this.GetClientContextSinkChain() is ClientContextTerminatorSink) || this.HasDynamicSinks || Context.HasGlobalDynamicSinks; } } /// Returns a specific context property, specified by name. /// The specified context property. /// The name of the property. /// /// /// // Token: 0x060025F8 RID: 9720 RVA: 0x0007D214 File Offset: 0x0007B414 public virtual IContextProperty GetProperty(string name) { if (this.context_properties == null) { return null; } foreach (object obj in this.context_properties) { IContextProperty contextProperty = (IContextProperty)obj; if (contextProperty.Name == name) { return contextProperty; } } return null; } /// Sets a specific context property by name. /// The actual context property. /// There is an attempt to add properties to the default context. /// The context is frozen. /// The property or the property name is null. /// /// /// // Token: 0x060025F9 RID: 9721 RVA: 0x0007D2A4 File Offset: 0x0007B4A4 public virtual void SetProperty(IContextProperty prop) { if (prop == null) { throw new ArgumentNullException("IContextProperty"); } if (this == Context.DefaultContext) { throw new InvalidOperationException("Can not add properties to default context"); } if (this.frozen) { throw new InvalidOperationException("Context is Frozen"); } if (this.context_properties == null) { this.context_properties = new ArrayList(); } this.context_properties.Add(prop); } /// Freezes the context, making it impossible to add or remove context properties from the current context. /// The context is already frozen. /// /// /// // Token: 0x060025FA RID: 9722 RVA: 0x0007D314 File Offset: 0x0007B514 public virtual void Freeze() { if (this.context_properties != null) { foreach (object obj in this.context_properties) { IContextProperty contextProperty = (IContextProperty)obj; contextProperty.Freeze(this); } } } /// Returns a class representation of the current context. /// A class representation of the current context. // Token: 0x060025FB RID: 9723 RVA: 0x0007D390 File Offset: 0x0007B590 public override string ToString() { return "ContextID: " + this.context_id; } // Token: 0x060025FC RID: 9724 RVA: 0x0007D3A8 File Offset: 0x0007B5A8 internal IMessageSink GetServerContextSinkChain() { if (this.server_context_sink_chain == null) { if (Context.default_server_context_sink == null) { Context.default_server_context_sink = new ServerContextTerminatorSink(); } this.server_context_sink_chain = Context.default_server_context_sink; if (this.context_properties != null) { for (int i = this.context_properties.Count - 1; i >= 0; i--) { IContributeServerContextSink contributeServerContextSink = this.context_properties[i] as IContributeServerContextSink; if (contributeServerContextSink != null) { this.server_context_sink_chain = contributeServerContextSink.GetServerContextSink(this.server_context_sink_chain); } } } } return this.server_context_sink_chain; } // Token: 0x060025FD RID: 9725 RVA: 0x0007D438 File Offset: 0x0007B638 internal IMessageSink GetClientContextSinkChain() { if (this.client_context_sink_chain == null) { this.client_context_sink_chain = new ClientContextTerminatorSink(this); if (this.context_properties != null) { foreach (object obj in this.context_properties) { IContextProperty contextProperty = (IContextProperty)obj; IContributeClientContextSink contributeClientContextSink = contextProperty as IContributeClientContextSink; if (contributeClientContextSink != null) { this.client_context_sink_chain = contributeClientContextSink.GetClientContextSink(this.client_context_sink_chain); } } } } return this.client_context_sink_chain; } // Token: 0x060025FE RID: 9726 RVA: 0x0007D4E8 File Offset: 0x0007B6E8 internal IMessageSink CreateServerObjectSinkChain(MarshalByRefObject obj, bool forceInternalExecute) { IMessageSink messageSink = new StackBuilderSink(obj, forceInternalExecute); messageSink = new ServerObjectTerminatorSink(messageSink); messageSink = new LeaseSink(messageSink); if (this.context_properties != null) { for (int i = this.context_properties.Count - 1; i >= 0; i--) { IContextProperty contextProperty = (IContextProperty)this.context_properties[i]; IContributeObjectSink contributeObjectSink = contextProperty as IContributeObjectSink; if (contributeObjectSink != null) { messageSink = contributeObjectSink.GetObjectSink(obj, messageSink); } } } return messageSink; } // Token: 0x060025FF RID: 9727 RVA: 0x0007D560 File Offset: 0x0007B760 internal IMessageSink CreateEnvoySink(MarshalByRefObject serverObject) { IMessageSink messageSink = EnvoyTerminatorSink.Instance; if (this.context_properties != null) { foreach (object obj in this.context_properties) { IContextProperty contextProperty = (IContextProperty)obj; IContributeEnvoySink contributeEnvoySink = contextProperty as IContributeEnvoySink; if (contributeEnvoySink != null) { messageSink = contributeEnvoySink.GetEnvoySink(serverObject, messageSink); } } } return messageSink; } // Token: 0x06002600 RID: 9728 RVA: 0x0007D5F4 File Offset: 0x0007B7F4 internal static Context SwitchToContext(Context newContext) { return AppDomain.InternalSetContext(newContext); } // Token: 0x06002601 RID: 9729 RVA: 0x0007D5FC File Offset: 0x0007B7FC internal static Context CreateNewContext(IConstructionCallMessage msg) { Context context = new Context(); foreach (object obj in msg.ContextProperties) { IContextProperty contextProperty = (IContextProperty)obj; if (context.GetProperty(contextProperty.Name) == null) { context.SetProperty(contextProperty); } } context.Freeze(); foreach (object obj2 in msg.ContextProperties) { IContextProperty contextProperty2 = (IContextProperty)obj2; if (!contextProperty2.IsNewContextOK(context)) { throw new RemotingException("A context property did not approve the candidate context for activating the object"); } } return context; } /// Executes code in another context. /// The delegate used to request the callback. /// /// /// // Token: 0x06002602 RID: 9730 RVA: 0x0007D704 File Offset: 0x0007B904 public void DoCallBack(CrossContextDelegate deleg) { lock (this) { if (this.callback_object == null) { Context context = Context.SwitchToContext(this); this.callback_object = new ContextCallbackObject(); Context.SwitchToContext(context); } } this.callback_object.DoCallBack(deleg); } /// Allocates an unnamed data slot. /// A local data slot. /// /// /// // Token: 0x06002603 RID: 9731 RVA: 0x0007D774 File Offset: 0x0007B974 public static LocalDataStoreSlot AllocateDataSlot() { return new LocalDataStoreSlot(false); } /// Allocates a named data slot. /// A local data slot object. /// The required name for the data slot. /// /// /// // Token: 0x06002604 RID: 9732 RVA: 0x0007D77C File Offset: 0x0007B97C public static LocalDataStoreSlot AllocateNamedDataSlot(string name) { object syncRoot = Context.namedSlots.SyncRoot; LocalDataStoreSlot localDataStoreSlot2; lock (syncRoot) { LocalDataStoreSlot localDataStoreSlot = Context.AllocateDataSlot(); Context.namedSlots.Add(name, localDataStoreSlot); localDataStoreSlot2 = localDataStoreSlot; } return localDataStoreSlot2; } /// Frees a named data slot on all the contexts. /// The name of the data slot to free. /// /// /// // Token: 0x06002605 RID: 9733 RVA: 0x0007D7DC File Offset: 0x0007B9DC public static void FreeNamedDataSlot(string name) { object syncRoot = Context.namedSlots.SyncRoot; lock (syncRoot) { Context.namedSlots.Remove(name); } } /// Retrieves the value from the specified slot on the current context. /// Returns the data associated with . /// The data slot that contains the data. /// /// /// // Token: 0x06002606 RID: 9734 RVA: 0x0007D830 File Offset: 0x0007BA30 public static object GetData(LocalDataStoreSlot slot) { Context currentContext = Thread.CurrentContext; Context context = currentContext; object obj; lock (context) { if (currentContext.datastore != null && slot.slot < currentContext.datastore.Length) { obj = currentContext.datastore[slot.slot]; } else { obj = null; } } return obj; } /// Looks up a named data slot. /// Returns a local data slot. /// The data slot name. /// /// /// // Token: 0x06002607 RID: 9735 RVA: 0x0007D8AC File Offset: 0x0007BAAC public static LocalDataStoreSlot GetNamedDataSlot(string name) { object syncRoot = Context.namedSlots.SyncRoot; LocalDataStoreSlot localDataStoreSlot2; lock (syncRoot) { LocalDataStoreSlot localDataStoreSlot = Context.namedSlots[name] as LocalDataStoreSlot; if (localDataStoreSlot == null) { localDataStoreSlot2 = Context.AllocateNamedDataSlot(name); } else { localDataStoreSlot2 = localDataStoreSlot; } } return localDataStoreSlot2; } /// Sets the data in the specified slot on the current context. /// The data slot where the data is to be added. /// The data that is to be added. /// /// /// // Token: 0x06002608 RID: 9736 RVA: 0x0007D920 File Offset: 0x0007BB20 public static void SetData(LocalDataStoreSlot slot, object data) { Context currentContext = Thread.CurrentContext; Context context = currentContext; lock (context) { if (currentContext.datastore == null) { currentContext.datastore = new object[slot.slot + 2]; } else if (slot.slot >= currentContext.datastore.Length) { object[] array = new object[slot.slot + 2]; currentContext.datastore.CopyTo(array, 0); currentContext.datastore = array; } currentContext.datastore[slot.slot] = data; } } // Token: 0x04000ECB RID: 3787 private int domain_id; // Token: 0x04000ECC RID: 3788 private int context_id; // Token: 0x04000ECD RID: 3789 private UIntPtr static_data; // Token: 0x04000ECE RID: 3790 private static IMessageSink default_server_context_sink; // Token: 0x04000ECF RID: 3791 private IMessageSink server_context_sink_chain; // Token: 0x04000ED0 RID: 3792 private IMessageSink client_context_sink_chain; // Token: 0x04000ED1 RID: 3793 private object[] datastore; // Token: 0x04000ED2 RID: 3794 private ArrayList context_properties; // Token: 0x04000ED3 RID: 3795 private bool frozen; // Token: 0x04000ED4 RID: 3796 private static int global_count; // Token: 0x04000ED5 RID: 3797 private static Hashtable namedSlots = new Hashtable(); // Token: 0x04000ED6 RID: 3798 private static DynamicPropertyCollection global_dynamic_properties; // Token: 0x04000ED7 RID: 3799 private DynamicPropertyCollection context_dynamic_properties; // Token: 0x04000ED8 RID: 3800 private ContextCallbackObject callback_object; } }