コード例 #1
0
        internal static MarshalByRefObject CreateInstance(RuntimeType serverType)
        {
            MarshalByRefObject     transparentProxy = null;
            ConstructorCallMessage ctorCallMsg      = null;
            RemotingProxy          realProxy;
            bool flag = IsCurrentContextOK(serverType, null, ref ctorCallMsg);

            if (flag && !serverType.IsContextful)
            {
                return(RemotingServices.AllocateUninitializedObject(serverType));
            }
            transparentProxy = (MarshalByRefObject)ConnectIfNecessary(ctorCallMsg);
            if (transparentProxy == null)
            {
                realProxy        = new RemotingProxy(serverType);
                transparentProxy = (MarshalByRefObject)realProxy.GetTransparentProxy();
            }
            else
            {
                realProxy = (RemotingProxy)RemotingServices.GetRealProxy(transparentProxy);
            }
            realProxy.ConstructorMessage = ctorCallMsg;
            if (!flag)
            {
                ContextLevelActivator activator = new ContextLevelActivator {
                    NextActivator = ctorCallMsg.Activator
                };
                ctorCallMsg.Activator = activator;
                return(transparentProxy);
            }
            ctorCallMsg.ActivateInContext = true;
            return(transparentProxy);
        }
コード例 #2
0
        internal static object ActivateWithMessage(Type serverType, IMessage msg, ServerIdentity srvIdToBind, out Exception e)
        {
            e = (Exception)null;
            object obj = (object)RemotingServices.AllocateUninitializedObject(serverType);
            object server;

            if (serverType.IsContextful)
            {
                object proxy = !(msg is ConstructorCallMessage) ? (object)null : ((ConstructorCallMessage)msg).GetThisPtr();
                server = RemotingServices.Wrap((ContextBoundObject)obj, proxy, false);
            }
            else
            {
                if (Thread.CurrentContext != Context.DefaultContext)
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_Activation_Failed"));
                }
                server = obj;
            }
            IMethodReturnMessage methodReturnMessage = (IMethodReturnMessage) new StackBuilderSink(server).SyncProcessMessage(msg);

            if (methodReturnMessage.Exception == null)
            {
                if (serverType.IsContextful)
                {
                    return(RemotingServices.Wrap((ContextBoundObject)obj));
                }
                return(obj);
            }
            e = methodReturnMessage.Exception;
            return((object)null);
        }
コード例 #3
0
        public IConstructionReturnMessage InitializeServerObject(IConstructionCallMessage ctorMsg)
        {
            IConstructionReturnMessage constructionReturnMessage = (IConstructionReturnMessage)null;

            if (this._serverObject == null)
            {
                Type proxiedType = this.GetProxiedType();
                if (ctorMsg != null && ctorMsg.ActivationType != proxiedType)
                {
                    throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Proxy_BadTypeForActivation"), (object)proxiedType.FullName, (object)ctorMsg.ActivationType));
                }
                this._serverObject = RemotingServices.AllocateUninitializedObject(proxiedType);
                this.SetContextForDefaultStub();
                MarshalByRefObject   marshalByRefObject  = (MarshalByRefObject)this.GetTransparentProxy();
                IMethodReturnMessage methodReturnMessage = (IMethodReturnMessage)null;
                Exception            e = (Exception)null;
                if (ctorMsg != null)
                {
                    methodReturnMessage = RemotingServices.ExecuteMessage(marshalByRefObject, (IMethodCallMessage)ctorMsg);
                    e = methodReturnMessage.Exception;
                }
                else
                {
                    try
                    {
                        RemotingServices.CallDefaultCtor((object)marshalByRefObject);
                    }
                    catch (Exception ex)
                    {
                        e = ex;
                    }
                }
                if (e == null)
                {
                    object[]           outArgs      = methodReturnMessage == null ? (object[])null : methodReturnMessage.OutArgs;
                    int                outArgsCount = outArgs == null ? 0 : outArgs.Length;
                    LogicalCallContext callCtx      = methodReturnMessage == null ? (LogicalCallContext)null : methodReturnMessage.LogicalCallContext;
                    constructionReturnMessage = (IConstructionReturnMessage) new ConstructorReturnMessage(marshalByRefObject, outArgs, outArgsCount, callCtx, ctorMsg);
                    this.SetupIdentity();
                    if (this.IsRemotingProxy())
                    {
                        this.Initialized = true;
                    }
                }
                else
                {
                    constructionReturnMessage = (IConstructionReturnMessage) new ConstructorReturnMessage(e, ctorMsg);
                }
            }
            return(constructionReturnMessage);
        }
コード例 #4
0
        public IConstructionReturnMessage InitializeServerObject(IConstructionCallMessage ctorMsg)
        {
            IConstructionReturnMessage message = null;

            if (this._serverObject != null)
            {
                return(message);
            }
            Type proxiedType = this.GetProxiedType();

            if ((ctorMsg != null) && (ctorMsg.ActivationType != proxiedType))
            {
                throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Proxy_BadTypeForActivation"), new object[] { proxiedType.FullName, ctorMsg.ActivationType }));
            }
            this._serverObject = RemotingServices.AllocateUninitializedObject(proxiedType);
            this.SetContextForDefaultStub();
            MarshalByRefObject   transparentProxy = (MarshalByRefObject)this.GetTransparentProxy();
            IMethodReturnMessage message2         = null;
            Exception            e = null;

            if (ctorMsg != null)
            {
                message2 = RemotingServices.ExecuteMessage(transparentProxy, ctorMsg);
                e        = message2.Exception;
            }
            else
            {
                try
                {
                    RemotingServices.CallDefaultCtor(transparentProxy);
                }
                catch (Exception exception2)
                {
                    e = exception2;
                }
            }
            if (e == null)
            {
                object[]           outArgs      = (message2 == null) ? null : message2.OutArgs;
                int                outArgsCount = (outArgs == null) ? 0 : outArgs.Length;
                LogicalCallContext callCtx      = (message2 == null) ? null : message2.LogicalCallContext;
                message = new ConstructorReturnMessage(transparentProxy, outArgs, outArgsCount, callCtx, ctorMsg);
                this.SetupIdentity();
                if (this.IsRemotingProxy())
                {
                    ((RemotingProxy)this).Initialized = true;
                }
                return(message);
            }
            return(new ConstructorReturnMessage(e, ctorMsg));
        }
コード例 #5
0
        public IConstructionReturnMessage InitializeServerObject(IConstructionCallMessage ctorMsg)
        {
            IConstructionReturnMessage result = null;

            if (this._serverObject == null)
            {
                Type proxiedType = this.GetProxiedType();
                if (ctorMsg != null && ctorMsg.ActivationType != proxiedType)
                {
                    throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Proxy_BadTypeForActivation"), proxiedType.FullName, ctorMsg.ActivationType));
                }
                this._serverObject = RemotingServices.AllocateUninitializedObject(proxiedType);
                this.SetContextForDefaultStub();
                MarshalByRefObject   marshalByRefObject  = (MarshalByRefObject)this.GetTransparentProxy();
                IMethodReturnMessage methodReturnMessage = null;
                Exception            ex = null;
                if (ctorMsg != null)
                {
                    methodReturnMessage = RemotingServices.ExecuteMessage(marshalByRefObject, ctorMsg);
                    ex = methodReturnMessage.Exception;
                }
                else
                {
                    try
                    {
                        RemotingServices.CallDefaultCtor(marshalByRefObject);
                    }
                    catch (Exception ex2)
                    {
                        ex = ex2;
                    }
                }
                if (ex == null)
                {
                    object[]           array        = (methodReturnMessage == null) ? null : methodReturnMessage.OutArgs;
                    int                outArgsCount = (array == null) ? 0 : array.Length;
                    LogicalCallContext callCtx      = (methodReturnMessage == null) ? null : methodReturnMessage.LogicalCallContext;
                    result = new ConstructorReturnMessage(marshalByRefObject, array, outArgsCount, callCtx, ctorMsg);
                    this.SetupIdentity();
                    if (this.IsRemotingProxy())
                    {
                        ((RemotingProxy)this).Initialized = true;
                    }
                }
                else
                {
                    result = new ConstructorReturnMessage(ex, ctorMsg);
                }
            }
            return(result);
        }
コード例 #6
0
        internal static MarshalByRefObject CreateInstance(RuntimeType serverType)
        {
            ConstructorCallMessage ctorCallMsg = (ConstructorCallMessage)null;
            bool flag = ActivationServices.IsCurrentContextOK(serverType, (object[])null, ref ctorCallMsg);
            MarshalByRefObject marshalByRefObject;

            if (flag && !serverType.IsContextful)
            {
                marshalByRefObject = RemotingServices.AllocateUninitializedObject(serverType);
            }
            else
            {
                marshalByRefObject = (MarshalByRefObject)ActivationServices.ConnectIfNecessary((IConstructionCallMessage)ctorCallMsg);
                RemotingProxy remotingProxy;
                if (marshalByRefObject == null)
                {
                    remotingProxy      = new RemotingProxy((Type)serverType);
                    marshalByRefObject = (MarshalByRefObject)remotingProxy.GetTransparentProxy();
                }
                else
                {
                    remotingProxy = (RemotingProxy)RemotingServices.GetRealProxy((object)marshalByRefObject);
                }
                remotingProxy.ConstructorMessage = ctorCallMsg;
                if (!flag)
                {
                    ctorCallMsg.Activator = (IActivator) new ContextLevelActivator()
                    {
                        NextActivator = ctorCallMsg.Activator
                    }
                }
                ;
                else
                {
                    ctorCallMsg.ActivateInContext = true;
                }
            }
            return(marshalByRefObject);
        }
コード例 #7
0
        public IConstructionReturnMessage InitializeServerObject(IConstructionCallMessage ctorMsg)
        {
            IConstructionReturnMessage retMsg = null;

            if (_serverObject == null)
            {
                Type svrType = GetProxiedType();
                if ((ctorMsg != null) && (ctorMsg.ActivationType != svrType))
                {
                    throw new RemotingException(
                              String.Format(
                                  CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Proxy_BadTypeForActivation"),
                                  svrType.FullName,
                                  ctorMsg.ActivationType));
                }

                // Create a blank object
                _serverObject = RemotingServices.AllocateUninitializedObject(svrType);

                // If the stub is the default stub, then set the server context
                // to be the current context.
                SetContextForDefaultStub();

                // OK... we are all set to run the constructor call on the uninitialized object
                MarshalByRefObject   proxy = (MarshalByRefObject)GetTransparentProxy();
                IMethodReturnMessage msg   = null;
                Exception            e     = null;
                if (null != ctorMsg)
                {
                    msg = RemotingServices.ExecuteMessage(proxy, ctorMsg);
                    e   = msg.Exception;
                }
                else
                {
                    try
                    {
                        RemotingServices.CallDefaultCtor(proxy);
                    }
                    catch (Exception excep)
                    {
                        e = excep;
                    }
                }

                // Construct a return message
                if (null == e)
                {
                    Object[]           outArgs   = (msg == null ? null : msg.OutArgs);
                    int                outLength = (null == outArgs ? 0 : outArgs.Length);
                    LogicalCallContext callCtx   = (msg == null ? null : msg.LogicalCallContext);
                    retMsg = new ConstructorReturnMessage(proxy,
                                                          outArgs, outLength,
                                                          callCtx, ctorMsg);

                    // setup identity
                    SetupIdentity();
                    if (IsRemotingProxy())
                    {
                        ((RemotingProxy)this).Initialized = true;
                    }
                }
                else
                {
                    // Exception occurred
                    retMsg = new ConstructorReturnMessage(e, ctorMsg);
                }
            }


            return(retMsg);
        }