Inheritance: MarshalByRefObject
		public static IInterceptionHandler GetInterceptor(ContextBoundObject instance)
		{
			foreach (var @int in interceptors)
			{
			    if (@int.Key == instance)
			    {
			        return @int.Value;
			    }
			}

			return null;
		}
コード例 #2
0
 internal static extern Object AlwaysUnwrap(ContextBoundObject obj);
コード例 #3
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Object Wrap(ContextBoundObject obj, Object proxy, bool fCreateSinks) 
        {
            Message.DebugOut("Entering Wrap for context " + Thread.CurrentContext + "\n");

            if ((null != obj) && (!IsTransparentProxy(obj))) 
            {
                Contract.Assert(obj.GetType().IsContextful,"objType.IsContextful"); 
                Message.DebugOut("Wrapping object \n"); 
                Identity idObj = null;
 
                if (proxy != null)
                {
                    // We will come here for strictly x-context activations
                    // since a proxy has already been created and supplied 
                    // through the construction message frame (GetThisPtr()).
                    RealProxy rp = GetRealProxy(proxy); 
                    if (rp.UnwrappedServerObject == null) 
                    {
                        rp.AttachServerHelper(obj); 
                    }
                    idObj = MarshalByRefObject.GetIdentity(obj);
                }
                else 
                {
                    // Proxy is null when Wrap() is called the second 
                    // time during activation 
                    // It also will be null when a ContextBoundObject
                    // is being activated from a remote client. 
                    idObj = IdentityHolder.FindOrCreateServerIdentity(
                                obj,
                                null,
                                IdOps.None); 
                }
 
                //********************WARNING******************************* 
                // Always create the proxy before calling out to user code
                // so that any recursive calls by JIT to wrap will return this 
                // proxy.
                //**********************************************************
                // Get the proxy represented by the identity object
                proxy = GetOrCreateProxy(idObj, proxy, true); 

                // EXTENSIBILITY: 
                GetRealProxy(proxy).Wrap(); 

                if (fCreateSinks) 
                {
                    IMessageSink chnlSink = null;
                    IMessageSink envoySink = null;
                    // Create the envoy sinks and channel sink 
                    CreateEnvoyAndChannelSinks((MarshalByRefObject)proxy, null, out chnlSink, out envoySink);
 
                    // Set the envoy and channel sinks in a thread safe manner 
                    SetEnvoyAndChannelSinks(idObj, chnlSink, envoySink);
                } 

                // This will handle the case where we call Wrap() with
                // a null proxy for real remote activation of ContextFul types.
                RealProxy rp2 = GetRealProxy(proxy); 
                if (rp2.UnwrappedServerObject == null)
                { 
                    rp2.AttachServerHelper(obj); 
                }
                Message.DebugOut("Leaving Wrap with proxy \n"); 
                return proxy;
            }
            else
            { 
                Message.DebugOut("Leaving Wrap with passed in object\n");
 
                // Default return value is the object itself 
                return obj;
            } 
        } // Wrap
コード例 #4
0
 [System.Security.SecurityCritical]  // auto-generated
 internal static Object Wrap(ContextBoundObject obj)
 { 
     return Wrap(obj, null, true);
 } 
コード例 #5
0
        public static bool UnregisterDynamicProperty(String name, ContextBoundObject obj, Context ctx)
        {
            // name, obj, ctx arguments should be exactly the same as a previous
            // RegisterDynamicProperty call
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (obj != null && ctx != null)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NonNullObjAndCtx"));
            }
            Contract.EndContractBlock();

            bool fUnregister = false;

            if (obj != null)
            {
                // ctx is ignored and must be null.
                fUnregister = IdentityHolder.RemoveDynamicProperty(obj, name);
            }
            else
            {
                // ctx may or may not be null
                fUnregister = Context.RemoveDynamicProperty(ctx, name);
            }

            return fUnregister;
        }
コード例 #6
0
        public static bool RegisterDynamicProperty(IDynamicProperty prop, ContextBoundObject obj, Context ctx)
        {
            bool fRegistered = false;

            if (prop == null || prop.Name == null || !(prop is IContributeDynamicSink))
            {
                throw new ArgumentNullException("prop");
            }
            if (obj != null && ctx != null)
            {
                // Exactly one of these is allowed to be non-null.
                throw new ArgumentException(Environment.GetResourceString("Argument_NonNullObjAndCtx"));
            }
            if (obj != null)
            {
                // ctx is ignored and must be null.
                fRegistered = IdentityHolder.AddDynamicProperty(obj, prop);                
            }
            else
            {
                // ctx may or may not be null
                fRegistered = Context.AddDynamicProperty(ctx, prop);
            }

            return fRegistered;
        }
        public static bool UnregisterDynamicProperty (string name, ContextBoundObject obj, Context ctx) {
            Contract.Requires(name != null);
            Contract.Requires(obj == null || ctx == null);

          return default(bool);
        }
        public static bool RegisterDynamicProperty (IDynamicProperty prop, ContextBoundObject obj, Context ctx) {
            Contract.Requires(prop != null);
            Contract.Requires(obj == null || ctx == null);

          return default(bool);
        }
 public static bool RegisterDynamicProperty(IDynamicProperty prop, ContextBoundObject obj, System.Runtime.Remoting.Contexts.Context ctx)
 {
   return default(bool);
 }
コード例 #10
0
		static void ContextBoundObjectInterceptor(ContextBoundObject instance)
		{
			//Context bound object interceptor
			var interceptor = new ContextBoundObjectInterceptor();
			var canIntercept = interceptor.CanIntercept(instance);
			var myProxy = interceptor.Intercept(instance, null, new MyHandler()) as IMyType;
			//var proxy = myProxy as IInterceptionProxy;
			//var otherInterceptor = proxy.Interceptor;
			var result = myProxy.MyMethod();
			Assert.AreEqual(20, result);
		}
		public InterceptionMessageSink(ContextBoundObject target, IMessageSink next)
		{
			this.Target = target;
			this.NextSink = next;
		}
 internal static object Wrap(ContextBoundObject obj, object proxy, bool fCreateSinks)
 {
     if ((obj == null) || IsTransparentProxy(obj))
     {
         return obj;
     }
     Identity idObj = null;
     if (proxy != null)
     {
         RealProxy proxy2 = GetRealProxy(proxy);
         if (proxy2.UnwrappedServerObject == null)
         {
             proxy2.AttachServerHelper(obj);
         }
         idObj = MarshalByRefObject.GetIdentity(obj);
     }
     else
     {
         idObj = IdentityHolder.FindOrCreateServerIdentity(obj, null, 0);
     }
     proxy = GetOrCreateProxy(idObj, proxy, true);
     GetRealProxy(proxy).Wrap();
     if (fCreateSinks)
     {
         IMessageSink chnlSink = null;
         IMessageSink envoySink = null;
         CreateEnvoyAndChannelSinks((MarshalByRefObject) proxy, null, out chnlSink, out envoySink);
         SetEnvoyAndChannelSinks(idObj, chnlSink, envoySink);
     }
     RealProxy realProxy = GetRealProxy(proxy);
     if (realProxy.UnwrappedServerObject == null)
     {
         realProxy.AttachServerHelper(obj);
     }
     return proxy;
 }
 internal static extern object Unwrap(ContextBoundObject obj);
コード例 #14
0
 public static bool UnregisterDynamicProperty(string name, ContextBoundObject obj, Context ctx)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if ((obj != null) && (ctx != null))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_NonNullObjAndCtx"));
     }
     if (obj != null)
     {
         return IdentityHolder.RemoveDynamicProperty(obj, name);
     }
     return RemoveDynamicProperty(ctx, name);
 }
コード例 #15
0
 public static bool RegisterDynamicProperty(IDynamicProperty prop, ContextBoundObject obj, Context ctx)
 {
     if (((prop == null) || (prop.Name == null)) || !(prop is IContributeDynamicSink))
     {
         throw new ArgumentNullException("prop");
     }
     if ((obj != null) && (ctx != null))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_NonNullObjAndCtx"));
     }
     if (obj != null)
     {
         return IdentityHolder.AddDynamicProperty(obj, prop);
     }
     return AddDynamicProperty(ctx, prop);
 }