예제 #1
0
        internal static IMessageCtrl DoAsyncDispatch(IMessage reqMsg, IMessageSink replySink)
        {
            object[]       args           = new object[4];
            ServerIdentity serverIdentity = InternalSink.GetServerIdentity(reqMsg);

            if (RemotingServices.CORProfilerTrackRemotingAsync())
            {
                Guid id = Guid.Empty;
                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    object obj = reqMsg.Properties[(object)"CORProfilerCookie"];
                    if (obj != null)
                    {
                        id = (Guid)obj;
                    }
                }
                RemotingServices.CORProfilerRemotingServerReceivingMessage(id, true);
                if (replySink != null)
                {
                    replySink = (IMessageSink) new ServerAsyncReplyTerminatorSink(replySink);
                }
            }
            Context serverContext = serverIdentity.ServerContext;

            args[0] = (object)reqMsg;
            args[1] = (object)replySink;
            args[2] = (object)Thread.CurrentContext;
            args[3] = (object)serverContext;
            InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(CrossContextChannel.DoAsyncDispatchCallback);

            return((IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(serverContext, ftnToCall, args));
        }
        internal static object SyncProcessMessageCallback(object[] args)
        {
            IMessage msg      = args[0] as IMessage;
            Context  context  = args[1] as Context;
            IMessage message2 = null;

            if (RemotingServices.CORProfilerTrackRemoting())
            {
                Guid empty = Guid.Empty;
                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    object obj2 = msg.Properties["CORProfilerCookie"];
                    if (obj2 != null)
                    {
                        empty = (Guid)obj2;
                    }
                }
                RemotingServices.CORProfilerRemotingServerReceivingMessage(empty, false);
            }
            context.NotifyDynamicSinks(msg, false, true, false, true);
            message2 = context.GetServerContextChain().SyncProcessMessage(msg);
            context.NotifyDynamicSinks(message2, false, false, false, true);
            if (RemotingServices.CORProfilerTrackRemoting())
            {
                Guid guid2;
                RemotingServices.CORProfilerRemotingServerSendingReply(out guid2, false);
                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    message2.Properties["CORProfilerCookie"] = guid2;
                }
            }
            return(message2);
        }
예제 #3
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static IMessageCtrl DoAsyncDispatch(IMessage reqMsg, IMessageSink replySink)
        {
            Object[] args = new Object[] { null, null, null, null };

            ServerIdentity srvID = GetServerIdentity(reqMsg);

            // If active, notify the profiler that an asynchronous remoting message was received.
            if (RemotingServices.CORProfilerTrackRemotingAsync())
            {
                Guid g = Guid.Empty;

                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    Object obj = reqMsg.Properties["CORProfilerCookie"];
                    if (obj != null)
                    {
                        g = (Guid)obj;
                    }
                }

                RemotingServices.CORProfilerRemotingServerReceivingMessage(g, true);

                // Only wrap the replySink if the call wants a reply
                if (replySink != null)
                {
                    // Now wrap the reply sink in our own so that we can notify the profiler of
                    // when the reply is sent.  Upon invocation, it will notify the profiler
                    // then pass control on to the replySink passed in above.
                    IMessageSink profSink =
                        new ServerAsyncReplyTerminatorSink(replySink);

                    // Replace the reply sink with our own
                    replySink = profSink;
                }
            }

            IMessageCtrl msgCtrl = null;
            Context      srvCtx  = srvID.ServerContext;

            //if (srvCtx.IsThreadPoolAware)
            //{
            // this is the case when we do not queue the work item since the
            // server context claims to be doing its own threading.

            args[0] = reqMsg;
            args[1] = replySink;
            args[2] = Thread.CurrentContext;
            args[3] = srvCtx;

            InternalCrossContextDelegate xctxDel = new InternalCrossContextDelegate(DoAsyncDispatchCallback);

            msgCtrl = (IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(srvCtx, xctxDel, args);

            //}

            return(msgCtrl);
        } // DoDispatch
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessage msg = InternalSink.ValidateMessage(reqMsg);

            object[]     args = new object[4];
            IMessageCtrl ctrl = null;

            if (msg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(msg);
                }
                return(ctrl);
            }
            ServerIdentity serverIdentity = InternalSink.GetServerIdentity(reqMsg);

            if (RemotingServices.CORProfilerTrackRemotingAsync())
            {
                Guid empty = Guid.Empty;
                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    object obj2 = reqMsg.Properties["CORProfilerCookie"];
                    if (obj2 != null)
                    {
                        empty = (Guid)obj2;
                    }
                }
                RemotingServices.CORProfilerRemotingServerReceivingMessage(empty, true);
                if (replySink != null)
                {
                    IMessageSink sink = new ServerAsyncReplyTerminatorSink(replySink);
                    replySink = sink;
                }
            }
            Context serverContext = serverIdentity.ServerContext;

            if (serverContext.IsThreadPoolAware)
            {
                args[0] = reqMsg;
                args[1] = replySink;
                args[2] = Thread.CurrentContext;
                args[3] = serverContext;
                InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(CrossContextChannel.AsyncProcessMessageCallback);
                return((IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(serverContext, ftnToCall, args));
            }
            AsyncWorkItem item = null;

            item = new AsyncWorkItem(reqMsg, replySink, Thread.CurrentContext, serverIdentity);
            WaitCallback callBack = new WaitCallback(item.FinishAsyncWork);

            ThreadPool.QueueUserWorkItem(callBack);
            return(ctrl);
        }
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            IMessage message = InternalSink.ValidateMessage(reqMsg);

            object[]     array  = new object[4];
            IMessageCtrl result = null;

            if (message != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(message);
                }
            }
            else
            {
                ServerIdentity serverIdentity = InternalSink.GetServerIdentity(reqMsg);
                if (RemotingServices.CORProfilerTrackRemotingAsync())
                {
                    Guid id = Guid.Empty;
                    if (RemotingServices.CORProfilerTrackRemotingCookie())
                    {
                        object obj = reqMsg.Properties["CORProfilerCookie"];
                        if (obj != null)
                        {
                            id = (Guid)obj;
                        }
                    }
                    RemotingServices.CORProfilerRemotingServerReceivingMessage(id, true);
                    if (replySink != null)
                    {
                        IMessageSink messageSink = new ServerAsyncReplyTerminatorSink(replySink);
                        replySink = messageSink;
                    }
                }
                Context serverContext = serverIdentity.ServerContext;
                if (serverContext.IsThreadPoolAware)
                {
                    array[0] = reqMsg;
                    array[1] = replySink;
                    array[2] = Thread.CurrentContext;
                    array[3] = serverContext;
                    InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(CrossContextChannel.AsyncProcessMessageCallback);
                    result = (IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(serverContext, ftnToCall, array);
                }
                else
                {
                    AsyncWorkItem @object  = new AsyncWorkItem(reqMsg, replySink, Thread.CurrentContext, serverIdentity);
                    WaitCallback  callBack = new WaitCallback(@object.FinishAsyncWork);
                    ThreadPool.QueueUserWorkItem(callBack);
                }
            }
            return(result);
        }
예제 #6
0
        internal static object SyncProcessMessageCallback(object[] args)
        {
            IMessage msg1    = args[0] as IMessage;
            Context  context = args[1] as Context;

            if (RemotingServices.CORProfilerTrackRemoting())
            {
                Guid id = Guid.Empty;
                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    object obj = msg1.Properties[(object)"CORProfilerCookie"];
                    if (obj != null)
                    {
                        id = (Guid)obj;
                    }
                }
                RemotingServices.CORProfilerRemotingServerReceivingMessage(id, false);
            }
            IMessage msg2 = msg1;
            int      num1 = 0;
            int      num2 = 1;
            int      num3 = 0;
            int      num4 = 1;

            context.NotifyDynamicSinks(msg2, num1 != 0, num2 != 0, num3 != 0, num4 != 0);
            IMessage message = context.GetServerContextChain().SyncProcessMessage(msg1);
            IMessage msg3    = message;
            int      num5    = 0;
            int      num6    = 0;
            int      num7    = 0;
            int      num8    = 1;

            context.NotifyDynamicSinks(msg3, num5 != 0, num6 != 0, num7 != 0, num8 != 0);
            if (RemotingServices.CORProfilerTrackRemoting())
            {
                Guid id;
                RemotingServices.CORProfilerRemotingServerSendingReply(out id, false);
                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    message.Properties[(object)"CORProfilerCookie"] = (object)id;
                }
            }
            return((object)message);
        }
예제 #7
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Object SyncProcessMessageCallback(Object[] args)
        {
            IMessage reqMsg   = args[0] as IMessage;
            Context  srvCtx   = args[1] as Context;
            IMessage replyMsg = null;

            // If profiling of remoting is active, must tell the profiler that we have received
            // a message.
            if (RemotingServices.CORProfilerTrackRemoting())
            {
                Guid g = Guid.Empty;

                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    Object obj = reqMsg.Properties["CORProfilerCookie"];

                    if (obj != null)
                    {
                        g = (Guid)obj;
                    }
                }

                RemotingServices.CORProfilerRemotingServerReceivingMessage(g, false);
            }

            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");

            // Server side notifications for dynamic sinks are done
            // in the x-context channel ... this is to maintain
            // symmetry of the point of notification between
            // the client and server context
            srvCtx.NotifyDynamicSinks(
                reqMsg,
                false,          // bCliSide
                true,           // bStart
                false,          // bAsync
                true);          // bNotifyGlobals

            replyMsg = srvCtx.GetServerContextChain().SyncProcessMessage(reqMsg);
            srvCtx.NotifyDynamicSinks(
                replyMsg,
                false,          // bCliSide
                false,          // bStart
                false,          // bAsync
                true);          // bNotifyGlobals

            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");

            // If profiling of remoting is active, must tell the profiler that we are sending a
            // reply message.
            if (RemotingServices.CORProfilerTrackRemoting())
            {
                Guid g;

                RemotingServices.CORProfilerRemotingServerSendingReply(out g, false);

                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    replyMsg.Properties["CORProfilerCookie"] = g;
                }
            }
            return(replyMsg);
        }
예제 #8
0
        [System.Security.SecurityCritical]  // auto-generated
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call starting!!\n");
            // One way Async notifications may potentially pass a null reply sink.
            IMessage errMsg = ValidateMessage(reqMsg);

            Object[] args = new Object[] { null, null, null, null };

            IMessageCtrl msgCtrl = null;

            if (errMsg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(errMsg);
                }
            }
            else
            {
                ServerIdentity srvID = GetServerIdentity(reqMsg);

                // If active, notify the profiler that an asynchronous remoting message was received.
                if (RemotingServices.CORProfilerTrackRemotingAsync())
                {
                    Guid g = Guid.Empty;

                    if (RemotingServices.CORProfilerTrackRemotingCookie())
                    {
                        Object obj = reqMsg.Properties["CORProfilerCookie"];

                        if (obj != null)
                        {
                            g = (Guid)obj;
                        }
                    }

                    RemotingServices.CORProfilerRemotingServerReceivingMessage(g, true);

                    // Only wrap the replySink if the call wants a reply
                    if (replySink != null)
                    {
                        // Now wrap the reply sink in our own so that we can notify the profiler of
                        // when the reply is sent.  Upon invocation, it will notify the profiler
                        // then pass control on to the replySink passed in above.
                        IMessageSink profSink = new ServerAsyncReplyTerminatorSink(replySink);

                        // Replace the reply sink with our own
                        replySink = profSink;
                    }
                }

                Context srvCtx = srvID.ServerContext;
                if (srvCtx.IsThreadPoolAware)
                {
                    // this is the case when we do not queue the work item since the
                    // server context claims to be doing its own threading.

                    args[0] = reqMsg;
                    args[1] = replySink;
                    args[2] = Thread.CurrentContext;
                    args[3] = srvCtx;

                    InternalCrossContextDelegate xctxDel = new InternalCrossContextDelegate(AsyncProcessMessageCallback);

                    msgCtrl = (IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(srvCtx, xctxDel, args);
                }
                else
                {
                    AsyncWorkItem workItem = null;

                    // This is the case where we take care of returning the calling
                    // thread asap by using the ThreadPool for completing the call.

                    // we use a more elaborate WorkItem and delegate the work to the thread pool
                    workItem = new AsyncWorkItem(reqMsg,
                                                 replySink,
                                                 Thread.CurrentContext,
                                                 srvID);

                    WaitCallback threadFunc = new WaitCallback(workItem.FinishAsyncWork);
                    // Note: Dynamic sinks are notified in the threadFunc
                    ThreadPool.QueueUserWorkItem(threadFunc);
                }
            }

            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call returning!!\n");
            return(msgCtrl);
        } // AsyncProcessMessage
예제 #9
0
        } // AsyncProcessMessage

        internal static IMessageCtrl DoAsyncDispatch(IMessage reqMsg, IMessageSink replySink)
        {
            ServerIdentity srvID    = GetServerIdentity(reqMsg);
            AsyncWorkItem  workItem = null;

            // If active, notify the profiler that an asynchronous remoting message was received.
            if (RemotingServices.CORProfilerTrackRemotingAsync())
            {
                Guid g = Guid.Empty;

                if (RemotingServices.CORProfilerTrackRemotingCookie())
                {
                    Object obj = reqMsg.Properties["CORProfilerCookie"];
                    if (obj != null)
                    {
                        g = (Guid)obj;
                    }
                }

                RemotingServices.CORProfilerRemotingServerReceivingMessage(g, true);

                // Only wrap the replySink if the call wants a reply
                if (replySink != null)
                {
                    // Now wrap the reply sink in our own so that we can notify the profiler of
                    // when the reply is sent.  Upon invocation, it will notify the profiler
                    // then pass control on to the replySink passed in above.
                    IMessageSink profSink =
                        new ServerAsyncReplyTerminatorSink(replySink);

                    // Replace the reply sink with our own
                    replySink = profSink;
                }
            }

            Context srvCtx = srvID.ServerContext;

            //if (srvCtx.IsThreadPoolAware)
            //{
            // this is the case when we do not queue the work item since the
            // server context claims to be doing its own threading.

            Context oldCtx = Thread.CurrentContext;
            // change to server object context
            ContextTransitionFrame frame = new ContextTransitionFrame();

            Thread.CurrentThread.EnterContext(srvID.ServerContext, ref frame);

            // we use the work item just as our replySink in this case
            if (replySink != null)
            {
                workItem = new AsyncWorkItem(replySink, oldCtx);
            }
            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");
            // call the server context chain
            IMessageCtrl msgCtrl =
                srvID.ServerContext.GetServerContextChain().AsyncProcessMessage(reqMsg, (IMessageSink)workItem);

            Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");
            // chain back to the dispatch thread context
            Thread.CurrentThread.ReturnToContext(ref frame);

            //}

            return(msgCtrl);
        } // DoDispatch
예제 #10
0
        public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink)
        {
            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call starting!!\n");
            // One way Async notifications may potentially pass a null reply sink.
            IMessage     errMsg  = ValidateMessage(reqMsg);
            IMessageCtrl msgCtrl = null;

            if (errMsg != null)
            {
                if (replySink != null)
                {
                    replySink.SyncProcessMessage(errMsg);
                }
            }
            else
            {
                ServerIdentity srvID    = GetServerIdentity(reqMsg);
                AsyncWorkItem  workItem = null;

                // If active, notify the profiler that an asynchronous remoting message was received.
                if (RemotingServices.CORProfilerTrackRemotingAsync())
                {
                    Guid g = Guid.Empty;

                    if (RemotingServices.CORProfilerTrackRemotingCookie())
                    {
                        Object obj = reqMsg.Properties["CORProfilerCookie"];

                        if (obj != null)
                        {
                            g = (Guid)obj;
                        }
                    }

                    RemotingServices.CORProfilerRemotingServerReceivingMessage(g, true);

                    // Only wrap the replySink if the call wants a reply
                    if (replySink != null)
                    {
                        // Now wrap the reply sink in our own so that we can notify the profiler of
                        // when the reply is sent.  Upon invocation, it will notify the profiler
                        // then pass control on to the replySink passed in above.
                        IMessageSink profSink = new ServerAsyncReplyTerminatorSink(replySink);

                        // Replace the reply sink with our own
                        replySink = profSink;
                    }
                }

                Context srvCtx = srvID.ServerContext;
                if (srvCtx.IsThreadPoolAware)
                {
                    // this is the case when we do not queue the work item since the
                    // server context claims to be doing its own threading.

                    Context oldCtx = Thread.CurrentContext;
                    // change to server object context
                    ContextTransitionFrame frame = new ContextTransitionFrame();
                    srvCtx = srvID.ServerContext;
                    Thread.CurrentThread.EnterContext(srvCtx, ref frame);

                    // we use the work item just as our replySink in this case
                    if (replySink != null)
                    {
                        workItem = new AsyncWorkItem(replySink, oldCtx);
                    }

                    Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");

                    srvCtx.NotifyDynamicSinks(
                        reqMsg,
                        false,          // bCliSide
                        true,           // bStart
                        true,           // bAsync
                        true);          // bNotifyGlobals

                    // call the server context chain
                    msgCtrl =
                        srvCtx.GetServerContextChain().AsyncProcessMessage(
                            reqMsg,
                            (IMessageSink)workItem);

                    // Note: for async calls, we will do the return notification
                    // for dynamic properties only when the async call
                    // completes (i.e. when the replySink gets called)

                    Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");

                    // chain back to the dispatch thread context
                    Thread.CurrentThread.ReturnToContext(ref frame);
                }
                else
                {
                    // This is the case where we take care of returning the calling
                    // thread asap by using the ThreadPool for completing the call.

                    // we use a more elaborate WorkItem and delegate the work to the thread pool
                    workItem = new AsyncWorkItem(reqMsg,
                                                 replySink,
                                                 Thread.CurrentContext,
                                                 srvID);

                    WaitCallback threadFunc = new WaitCallback(workItem.FinishAsyncWork);
                    // Note: Dynamic sinks are notified in the threadFunc
                    ThreadPool.QueueUserWorkItem(threadFunc);

                    msgCtrl = null;
                }
            }

            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Async call returning!!\n");
            return(msgCtrl);
        } // AsyncProcessMessage
예제 #11
0
        public virtual IMessage     SyncProcessMessage(IMessage reqMsg)
        {
            IMessage replyMsg = null;

            try
            {
                Message.DebugOut("\n::::::::::::::::::::::::: CrossContext Channel: Sync call starting");
                IMessage errMsg = ValidateMessage(reqMsg);
                if (errMsg != null)
                {
                    return(errMsg);
                }

                ServerIdentity srvID = GetServerIdentity(reqMsg);
                Message.DebugOut("Got Server identity \n");
                BCLDebug.Assert(null != srvID, "null != srvID");


                BCLDebug.Assert(null != srvID.ServerContext, "null != srvID.ServerContext");

                bool fEnteredContext         = false;
                ContextTransitionFrame frame = new ContextTransitionFrame();
                try
                {
                    Context srvCtx = srvID.ServerContext;
                    Thread.CurrentThread.EnterContext(srvCtx, ref frame);
                    fEnteredContext = true;
                    // If profiling of remoting is active, must tell the profiler that we have received
                    // a message.
                    if (RemotingServices.CORProfilerTrackRemoting())
                    {
                        Guid g = Guid.Empty;

                        if (RemotingServices.CORProfilerTrackRemotingCookie())
                        {
                            Object obj = reqMsg.Properties["CORProfilerCookie"];

                            if (obj != null)
                            {
                                g = (Guid)obj;
                            }
                        }

                        RemotingServices.CORProfilerRemotingServerReceivingMessage(g, false);
                    }

                    Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: passing to ServerContextChain");

                    // Server side notifications for dynamic sinks are done
                    // in the x-context channel ... this is to maintain
                    // symmetry of the point of notification between
                    // the client and server context
                    srvCtx.NotifyDynamicSinks(
                        reqMsg,
                        false,          // bCliSide
                        true,           // bStart
                        false,          // bAsync
                        true);          // bNotifyGlobals

                    replyMsg = srvCtx.GetServerContextChain().SyncProcessMessage(reqMsg);
                    srvCtx.NotifyDynamicSinks(
                        replyMsg,
                        false,          // bCliSide
                        false,          // bStart
                        false,          // bAsync
                        true);          // bNotifyGlobals

                    Message.DebugOut("::::::::::::::::::::::::: CrossContext Channel: back from ServerContextChain");

                    // If profiling of remoting is active, must tell the profiler that we are sending a
                    // reply message.
                    if (RemotingServices.CORProfilerTrackRemoting())
                    {
                        Guid g;

                        RemotingServices.CORProfilerRemotingServerSendingReply(out g, false);

                        if (RemotingServices.CORProfilerTrackRemotingCookie())
                        {
                            replyMsg.Properties["CORProfilerCookie"] = g;
                        }
                    }
                }
                finally
                {
                    if (fEnteredContext)
                    {
                        Thread.CurrentThread.ReturnToContext(ref frame);
                    }
                }
            }
            catch (Exception e)
            {
                Message.DebugOut("Arrgh.. XCTXSink::throwing exception " + e + "\n");
                replyMsg = new ReturnMessage(e, (IMethodCallMessage)reqMsg);
                if (reqMsg != null)
                {
                    ((ReturnMessage)replyMsg).SetLogicalCallContext(
                        (LogicalCallContext)
                        reqMsg.Properties[Message.CallContextKey]);
                }
            }

            Message.DebugOut("::::::::::::::::::::::::::: CrossContext Channel: Sync call returning!!\n");
            return(replyMsg);
        }