Beispiel #1
0
 public IMessage SyncProcessMessage(IMessage msg)
 {
     try
     {
         LogicalCallContext oldcctx = Message.PropagateCallContextFromMessageToThread(msg);
         if (this._delegate != null)
         {
             this._delegate();
         }
         else
         {
             CallBackHelper       @object = new CallBackHelper(this._eeData, true, this._targetDomainID);
             CrossContextDelegate crossContextDelegate = new CrossContextDelegate(@object.Func);
             crossContextDelegate();
         }
         Message.PropagateCallContextFromThreadToMessage(msg, oldcctx);
     }
     catch (Exception e)
     {
         ReturnMessage returnMessage = new ReturnMessage(e, new ErrorMessage());
         returnMessage.SetLogicalCallContext((LogicalCallContext)msg.Properties[Message.CallContextKey]);
         return(returnMessage);
     }
     return(this);
 }
        /// <summary>
        /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// crosscontextdelegate.BeginInvoke(callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginInvoke(this CrossContextDelegate crosscontextdelegate, AsyncCallback callback)
        {
            if (crosscontextdelegate == null)
            {
                throw new ArgumentNullException("crosscontextdelegate");
            }

            return(crosscontextdelegate.BeginInvoke(callback, null));
        }
 internal TransitionCall(IntPtr targetCtxID, CrossContextDelegate deleg)
 {
     this._sourceCtxID = Thread.CurrentContext.InternalContextID;
     this._targetCtxID = targetCtxID;
     this._delegate = deleg;
     this._targetDomainID = 0;
     this._eeData = IntPtr.Zero;
     this._srvID = new ServerIdentity(null, Thread.GetContextInternal(this._targetCtxID));
     this._ID = this._srvID;
     this._ID.RaceSetChannelSink(CrossContextChannel.MessageSink);
     this._srvID.RaceSetServerObjectChain(this);
 }
Beispiel #4
0
 internal TransitionCall(IntPtr targetCtxID, CrossContextDelegate deleg)
 {
     this._sourceCtxID    = Thread.CurrentContext.InternalContextID;
     this._targetCtxID    = targetCtxID;
     this._delegate       = deleg;
     this._targetDomainID = 0;
     this._eeData         = IntPtr.Zero;
     this._srvID          = new ServerIdentity(null, Thread.GetContextInternal(this._targetCtxID));
     this._ID             = this._srvID;
     this._ID.RaceSetChannelSink(CrossContextChannel.MessageSink);
     this._srvID.RaceSetServerObjectChain(this);
 }
 internal TransitionCall(SerializationInfo info, StreamingContext context)
 {
     if ((info == null) || (context.State != StreamingContextStates.CrossAppDomain))
     {
         throw new ArgumentNullException("info");
     }
     this._props = (IDictionary) info.GetValue("props", typeof(IDictionary));
     this._delegate = (CrossContextDelegate) info.GetValue("delegate", typeof(CrossContextDelegate));
     this._sourceCtxID = (IntPtr) info.GetValue("sourceCtxID", typeof(IntPtr));
     this._targetCtxID = (IntPtr) info.GetValue("targetCtxID", typeof(IntPtr));
     this._eeData = (IntPtr) info.GetValue("eeData", typeof(IntPtr));
     this._targetDomainID = info.GetInt32("targetDomainID");
 }
Beispiel #6
0
        internal TransitionCall(IntPtr targetCtxID, IntPtr eeData, int targetDomainID)
        {
            this._sourceCtxID    = Thread.CurrentContext.InternalContextID;
            this._targetCtxID    = targetCtxID;
            this._delegate       = (CrossContextDelegate)null;
            this._targetDomainID = targetDomainID;
            this._eeData         = eeData;
            this._srvID          = (ServerIdentity)null;
            this._ID             = new Identity("TransitionCallURI", (string)null);
            string objectURI;

            this._ID.RaceSetChannelSink(CrossAppDomainChannel.AppDomainChannel.CreateMessageSink((string)null, (object)new CrossAppDomainData(this._targetCtxID, this._targetDomainID, Identity.ProcessGuid), out objectURI));
        }
 internal TransitionCall(SerializationInfo info, StreamingContext context)
 {
     if ((info == null) || (context.State != StreamingContextStates.CrossAppDomain))
     {
         throw new ArgumentNullException("info");
     }
     this._props          = (IDictionary)info.GetValue("props", typeof(IDictionary));
     this._delegate       = (CrossContextDelegate)info.GetValue("delegate", typeof(CrossContextDelegate));
     this._sourceCtxID    = (IntPtr)info.GetValue("sourceCtxID", typeof(IntPtr));
     this._targetCtxID    = (IntPtr)info.GetValue("targetCtxID", typeof(IntPtr));
     this._eeData         = (IntPtr)info.GetValue("eeData", typeof(IntPtr));
     this._targetDomainID = info.GetInt32("targetDomainID");
 }
 internal TransitionCall(IntPtr targetCtxID, IntPtr eeData, int targetDomainID)
 {
     string str;
     this._sourceCtxID = Thread.CurrentContext.InternalContextID;
     this._targetCtxID = targetCtxID;
     this._delegate = null;
     this._targetDomainID = targetDomainID;
     this._eeData = eeData;
     this._srvID = null;
     this._ID = new Identity("TransitionCallURI", null);
     CrossAppDomainData data = new CrossAppDomainData(this._targetCtxID, this._targetDomainID, Identity.ProcessGuid);
     IMessageSink channelSink = CrossAppDomainChannel.AppDomainChannel.CreateMessageSink(null, data, out str);
     this._ID.RaceSetChannelSink(channelSink);
 }
        internal TransitionCall(IntPtr targetCtxID, IntPtr eeData, int targetDomainID)
        {
            string str;

            this._sourceCtxID    = Thread.CurrentContext.InternalContextID;
            this._targetCtxID    = targetCtxID;
            this._delegate       = null;
            this._targetDomainID = targetDomainID;
            this._eeData         = eeData;
            this._srvID          = null;
            this._ID             = new Identity("TransitionCallURI", null);
            CrossAppDomainData data        = new CrossAppDomainData(this._targetCtxID, this._targetDomainID, Identity.ProcessGuid);
            IMessageSink       channelSink = CrossAppDomainChannel.AppDomainChannel.CreateMessageSink(null, data, out str);

            this._ID.RaceSetChannelSink(channelSink);
        }
Beispiel #10
0
        IntPtr _privateData; // Used for DoCallbackInEE

        // The _delegate should really be on an agile object otherwise
        // the whole point of doing a callBack is moot. However, even if it
        // is not, remoting and serialization together will ensure that
        // everything happens as expected and there is no smuggling.

        internal TransitionCall(
            IntPtr targetCtxID, 
            CrossContextDelegate deleg)
        {
            BCLDebug.Assert(targetCtxID!=IntPtr.Zero, "bad target ctx for call back");
            _sourceCtxID = Thread.CurrentContext.InternalContextID;
            _targetCtxID = targetCtxID;
            _delegate = deleg;
            _targetDomainID = 0;
            _privateData = IntPtr.Zero;

                // We are going to another context in the same app domain
                _srvID = new ServerIdentity(
                                null, 
                                Thread.GetContextInternal(_targetCtxID));
                _ID = _srvID;
                _ID.RaceSetChannelSink(CrossContextChannel.MessageSink);
                _srvID.RaceSetServerObjectChain(this);
                
            //DBG Console.WriteLine("### TransitionCall ctor: " + Int32.Format(_sourceCtxID,"x") + ":" + Int32.Format(_targetCtxID,"x"));
        } // TransitionCall
        public void DoCallBack (CrossContextDelegate deleg) {
            Contract.Requires(deleg != null);

        }
 internal void DoCallBackGeneric(IntPtr targetCtxID, CrossContextDelegate deleg)
 {
     TransitionCall msg = new TransitionCall(targetCtxID, deleg);
     Message.PropagateCallContextFromThreadToMessage(msg);
     IMessage message = this.GetClientContextChain().SyncProcessMessage(msg);
     if (message != null)
     {
         Message.PropagateCallContextFromMessageToThread(message);
     }
     IMethodReturnMessage message2 = message as IMethodReturnMessage;
     if ((message2 != null) && (message2.Exception != null))
     {
         throw message2.Exception;
     }
 }
Beispiel #13
0
        //IMessage::SyncProcessMessage
        public IMessage SyncProcessMessage(IMessage msg)
        {
            BCLDebug.Assert(
                Thread.CurrentContext.InternalContextID == _targetCtxID,
                "Transition message routed to wrong context");

            try
            {
                LogicalCallContext oldcctx = Message.PropagateCallContextFromMessageToThread(msg);
                if (_delegate != null)
                {
                _delegate();            
                }
                else
                {
                    // This is the cross appdomain case, so we need to construct
                    //   the delegate and call on it.
                    CallBackHelper cb = new CallBackHelper(
                                            _privateData,
                                            true /*fromEE*/,
                                            _targetDomainID); 
                    CrossContextDelegate ctxDel = new CrossContextDelegate(cb.Func);
                    ctxDel(); 
                }
                Message.PropagateCallContextFromThreadToMessage(msg, oldcctx);
            }

            catch (Exception e)
            {
                ReturnMessage retMsg = new ReturnMessage(e, new ErrorMessage());
                retMsg.SetLogicalCallContext(
                    (LogicalCallContext) msg.Properties[Message.CallContextKey]);
                return retMsg;
            }

            return this;    
        }
 internal static void DoCallBackFromEE(IntPtr targetCtxID, IntPtr privateData, int targetDomainID)
 {
     if (targetDomainID == 0)
     {
         CallBackHelper helper = new CallBackHelper(privateData, true, targetDomainID);
         CrossContextDelegate deleg = new CrossContextDelegate(helper.Func);
         Thread.CurrentContext.DoCallBackGeneric(targetCtxID, deleg);
     }
     else
     {
         TransitionCall msg = new TransitionCall(targetCtxID, privateData, targetDomainID);
         Message.PropagateCallContextFromThreadToMessage(msg);
         IMessage message = Thread.CurrentContext.GetClientContextChain().SyncProcessMessage(msg);
         Message.PropagateCallContextFromMessageToThread(message);
         IMethodReturnMessage message2 = message as IMethodReturnMessage;
         if ((message2 != null) && (message2.Exception != null))
         {
             throw message2.Exception;
         }
     }
 }
Beispiel #15
0
		public void DoCallBack (CrossContextDelegate deleg)
		{
			lock (this)
			{
				if (callback_object == null) {
					Context oldContext = Context.SwitchToContext (this);
					callback_object = new ContextCallbackObject ();
					Context.SwitchToContext (oldContext);
				}
			}
			
			callback_object.DoCallBack (deleg);
		}
Beispiel #16
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static void DoCallBackFromEE(
            IntPtr targetCtxID, IntPtr privateData, int targetDomainID)
        {
            Contract.Assert(targetCtxID != IntPtr.Zero, "Bad transition context");
                
            /*DBG Console.WriteLine("private DoCallBackFromEE: targetCtx: " 
            + Int32.Format(targetCtxID,"x") 
            + " PvtData: " + Int32.Format(privateData,"x"));DBG*/

            if (targetDomainID == 0)
            {
                CallBackHelper cb = new CallBackHelper(
                                            privateData,
                                            true /*fromEE*/,
                                            targetDomainID); 
                CrossContextDelegate ctxDel = new CrossContextDelegate(cb.Func);
                Thread.CurrentContext.DoCallBackGeneric(targetCtxID, ctxDel);                                                                     
            }
            else
            {
                // for x-appdomain calls, we can't pass a delegate since that 
                //   would require us to deserialize it on the other side which
                //   is not allowed for non-public methods.
                TransitionCall msgCall = new TransitionCall(targetCtxID, privateData, targetDomainID);           
            
                Message.PropagateCallContextFromThreadToMessage(msgCall);
                //DBG Console.WriteLine("CallBackGeneric starting!");
                IMessage retMsg = Thread.CurrentContext.GetClientContextChain().SyncProcessMessage(msgCall); 
                Message.PropagateCallContextFromMessageToThread(retMsg);
            
                IMethodReturnMessage msg = retMsg as IMethodReturnMessage;
                if (null != msg)
                {
                    if (msg.Exception != null)
                        throw msg.Exception;
                }
            }
        } // DoCallBackFromEE
 public void DoCallBack(CrossContextDelegate deleg)
 {
 }
        protected override void CreateSendOrPostCallback(SendOrPostCallback d, object state)
        {
            CrossContextDelegate ccd = () => d(state);

            m_context.DoCallBack(ccd);
        }
 public IMessage SyncProcessMessage(IMessage msg)
 {
     try
     {
         LogicalCallContext oldcctx = Message.PropagateCallContextFromMessageToThread(msg);
         if (this._delegate != null)
         {
             this._delegate();
         }
         else
         {
             CallBackHelper helper = new CallBackHelper(this._eeData, true, this._targetDomainID);
             CrossContextDelegate delegate2 = new CrossContextDelegate(helper.Func);
             delegate2();
         }
         Message.PropagateCallContextFromThreadToMessage(msg, oldcctx);
     }
     catch (Exception exception)
     {
         ReturnMessage message = new ReturnMessage(exception, new ErrorMessage());
         message.SetLogicalCallContext((LogicalCallContext) msg.Properties[Message.CallContextKey]);
         return message;
     }
     return this;
 }
Beispiel #20
0
        [System.Security.SecurityCritical]  // auto-generated_required
        public void DoCallBack(CrossContextDelegate deleg)
        {
            /*DBG Console.WriteLine("public DoCallBack: targetCtx: " 
            + Int32.Format(this.InternalContextID,"x")); DBG*/
                
            if (deleg == null)
            {
                throw new ArgumentNullException("deleg");
            }
            Contract.EndContractBlock();

            if ((_ctxFlags & CTX_FROZEN) == 0)
            {
                throw new RemotingException( 
                    Environment.GetResourceString(
                        "Remoting_Contexts_ContextNotFrozenForCallBack"));
            }

            Context currCtx = Thread.CurrentContext;
            if (currCtx == this)
            {
                // We are already in the target context, just execute deleg
                // NOTE: If in the future we decide to leave the context
                // and reenter it for this case we will need to change 
                // Context::RequestCallBack method in VM also!
                deleg();
            }
            else
            {                               
                // We pass 0 for target domain ID for x-context case.
                currCtx.DoCallBackGeneric(this.InternalContextID, deleg);
                GC.KeepAlive(this);
            }
        }
Beispiel #21
0
        } // TransitionCall


        // This constructor should be used for cross appdomain case.
        internal TransitionCall(IntPtr targetCtxID, IntPtr privateData, int targetDomainID)
            {
            BCLDebug.Assert(targetCtxID != IntPtr.Zero, "bad target ctx for call back");
            BCLDebug.Assert(targetDomainID != 0, "bad target ctx for call back");

            _sourceCtxID = Thread.CurrentContext.InternalContextID;
            _targetCtxID = targetCtxID;
            _delegate = null;
            _targetDomainID = targetDomainID;
            _privateData = privateData;
            

            // In the cross domain case, the client side just has a base Identity
            // and the server domain has the Server identity. We fault in the latter
            // when requested later.

                // We are going to a context in another app domain
                _srvID = null;
                _ID = new Identity("TransitionCallURI", null);

                // Create the data needed for the channel sink creation
            CrossAppDomainData data = 
                new CrossAppDomainData(_targetCtxID,
                                       _targetDomainID,
                                       Identity.ProcessGuid);
                String unUsed;
                IMessageSink channelSink =
                CrossAppDomainChannel.AppDomainChannel.CreateMessageSink(
                                                        null, //uri
                                                        data, //channelData
                                                        out unUsed);//out objURI

                BCLDebug.Assert(channelSink != null, "X-domain transition failure");
                _ID.RaceSetChannelSink(channelSink);
        } // TransitionCall
Beispiel #22
0
 [System.Security.SecurityCritical]  // auto-generated
 internal void DoCallBackGeneric(
     IntPtr targetCtxID, CrossContextDelegate deleg)
 {               
     TransitionCall msgCall = new TransitionCall(targetCtxID, deleg);           
     
     Message.PropagateCallContextFromThreadToMessage(msgCall);
     //DBG Console.WriteLine("CallBackGeneric starting!");
     IMessage retMsg = this.GetClientContextChain().SyncProcessMessage(msgCall); 
     if (null != retMsg)
     {
         Message.PropagateCallContextFromMessageToThread(retMsg);
     }
     
     IMethodReturnMessage msg = retMsg as IMethodReturnMessage;
     if (null != msg)
     {
         if (msg.Exception != null)
             throw msg.Exception;
     }
     //DBG Console.WriteLine("CallBackGeneric finished!");
 }
Beispiel #23
0
        } // TransitionCall
        

        internal TransitionCall(SerializationInfo info, StreamingContext context) 
        {
            if (info == null || (context.State != StreamingContextStates.CrossAppDomain))
            {
                throw new ArgumentNullException("info");
            }
            
            _props = (IDictionary)info.GetValue("props", typeof(IDictionary));
            _delegate = (CrossContextDelegate) info.GetValue("delegate", typeof(CrossContextDelegate));
            _sourceCtxID  = new IntPtr(info.GetInt32("sourceCtxID"));
            _targetCtxID  = new IntPtr(info.GetInt32("targetCtxID"));
            _privateData = new IntPtr(info.GetInt32("privateData"));
            
            _targetDomainID = info.GetInt32("targetDomainID");
            BCLDebug.Assert(_targetDomainID != 0, "target domain should be non-zero");
        }
Beispiel #24
0
		public void DoCallBack (CrossContextDelegate deleg)
		{
		}
 public void DoCallBack(CrossContextDelegate deleg)
 {
     if (deleg == null)
     {
         throw new ArgumentNullException("deleg");
     }
     if ((this._ctxFlags & 2) == 0)
     {
         throw new RemotingException(Environment.GetResourceString("Remoting_Contexts_ContextNotFrozenForCallBack"));
     }
     Context currentContext = Thread.CurrentContext;
     if (currentContext == this)
     {
         deleg();
     }
     else
     {
         currentContext.DoCallBackGeneric(this.InternalContextID, deleg);
         GC.KeepAlive(this);
     }
 }