public static ConstructionCall CreateConstructionCall(Type type, string activationUrl, object[] activationAttributes)
        {
            ConstructionCall constructionCall = new ConstructionCall(type);

            if (!type.IsContextful)
            {
                constructionCall.Activator   = new AppDomainLevelActivator(activationUrl, ActivationServices.ConstructionActivator);
                constructionCall.IsContextOk = false;
                return(constructionCall);
            }
            IActivator activator = ActivationServices.ConstructionActivator;

            activator = new ContextLevelActivator(activator);
            ArrayList arrayList = new ArrayList();

            if (activationAttributes != null)
            {
                arrayList.AddRange(activationAttributes);
            }
            bool    flag           = activationUrl == ChannelServices.CrossContextUrl;
            Context currentContext = Thread.CurrentContext;

            if (flag)
            {
                foreach (object obj in arrayList)
                {
                    IContextAttribute contextAttribute = (IContextAttribute)obj;
                    if (!contextAttribute.IsContextOK(currentContext, constructionCall))
                    {
                        flag = false;
                        break;
                    }
                }
            }
            object[] customAttributes = type.GetCustomAttributes(true);
            foreach (object obj2 in customAttributes)
            {
                if (obj2 is IContextAttribute)
                {
                    flag = (flag && ((IContextAttribute)obj2).IsContextOK(currentContext, constructionCall));
                    arrayList.Add(obj2);
                }
            }
            if (!flag)
            {
                constructionCall.SetActivationAttributes(arrayList.ToArray());
                foreach (object obj3 in arrayList)
                {
                    IContextAttribute contextAttribute2 = (IContextAttribute)obj3;
                    contextAttribute2.GetPropertiesForNewContext(constructionCall);
                }
            }
            if (activationUrl != ChannelServices.CrossContextUrl)
            {
                activator = new AppDomainLevelActivator(activationUrl, activator);
            }
            constructionCall.Activator   = activator;
            constructionCall.IsContextOk = flag;
            return(constructionCall);
        }
Esempio n. 2
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);
        }
        internal static MarshalByRefObject CreateInstance(RuntimeType serverType)
        {
            ConstructorCallMessage constructorCallMessage = null;
            bool flag = ActivationServices.IsCurrentContextOK(serverType, null, ref constructorCallMessage);
            MarshalByRefObject marshalByRefObject;

            if (flag && !serverType.IsContextful)
            {
                marshalByRefObject = RemotingServices.AllocateUninitializedObject(serverType);
            }
            else
            {
                marshalByRefObject = (MarshalByRefObject)ActivationServices.ConnectIfNecessary(constructorCallMessage);
                RemotingProxy remotingProxy;
                if (marshalByRefObject == null)
                {
                    remotingProxy      = new RemotingProxy(serverType);
                    marshalByRefObject = (MarshalByRefObject)remotingProxy.GetTransparentProxy();
                }
                else
                {
                    remotingProxy = (RemotingProxy)RemotingServices.GetRealProxy(marshalByRefObject);
                }
                remotingProxy.ConstructorMessage = constructorCallMessage;
                if (!flag)
                {
                    ContextLevelActivator contextLevelActivator = new ContextLevelActivator();
                    contextLevelActivator.NextActivator = constructorCallMessage.Activator;
                    constructorCallMessage.Activator    = contextLevelActivator;
                }
                else
                {
                    constructorCallMessage.ActivateInContext = true;
                }
            }
            return(marshalByRefObject);
        }
Esempio n. 4
0
        public static ConstructionCall CreateConstructionCall(Type type, string activationUrl, object[] activationAttributes)
        {
            ConstructionCall ctorCall = new ConstructionCall(type);

            if (!type.IsContextful)
            {
                // Must be a remote activated object
                ctorCall.Activator   = new AppDomainLevelActivator(activationUrl, ConstructionActivator);
                ctorCall.IsContextOk = false;                   // It'll be activated in a remote context
                return(ctorCall);
            }

            // It is a CBO. Need collect context properties and
            // check if a new context is needed.

            IActivator activatorChain = ConstructionActivator;

            activatorChain = new ContextLevelActivator(activatorChain);

            ArrayList attributes = new ArrayList();

            if (activationAttributes != null)
            {
                attributes.AddRange(activationAttributes);
            }

            bool    isContextOk    = (activationUrl == ChannelServices.CrossContextUrl);        // Remote CBOs are always created in a new context
            Context currentContext = Threading.Thread.CurrentContext;

            if (isContextOk)
            {
                foreach (IContextAttribute attr in attributes)
                {
                    if (!attr.IsContextOK(currentContext, ctorCall))
                    {
                        isContextOk = false;
                        break;
                    }
                }
            }

            object[] typeAttributes = type.GetCustomAttributes(true);
            foreach (object attr in typeAttributes)
            {
                if (attr is IContextAttribute)
                {
                    isContextOk = isContextOk && ((IContextAttribute)attr).IsContextOK(currentContext, ctorCall);
                    attributes.Add(attr);
                }
            }

            if (!isContextOk)
            {
                // A new context is needed. Collect the context properties and chain
                // the context level activator.

                ctorCall.SetActivationAttributes(attributes.ToArray());

                foreach (IContextAttribute attr in attributes)
                {
                    attr.GetPropertiesForNewContext(ctorCall);
                }
            }

            if (activationUrl != ChannelServices.CrossContextUrl)
            {
                activatorChain = new AppDomainLevelActivator(activationUrl, activatorChain);
            }

            ctorCall.Activator   = activatorChain;
            ctorCall.IsContextOk = isContextOk;

            return(ctorCall);
        }
Esempio n. 5
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static MarshalByRefObject CreateInstance(RuntimeType serverType)
        {
            // Use our activation implementation               
            MarshalByRefObject retObj = null;
            ConstructorCallMessage ctorCallMsg = null;
            bool bCtxOK = IsCurrentContextOK(serverType, null, ref ctorCallMsg);
            if (bCtxOK && !serverType.IsContextful)
            {
                // Marshal by ref case
                Message.DebugOut("Allocating blank marshal-by-ref object"); 
                // We create an uninitialized instance of the actual type and
                // let the regular jit-activation execute the constructor on it.
                retObj = RemotingServices.AllocateUninitializedObject(serverType);
            }
            else 
            {
                //  (context not OK) || (serverType is Contextful)
                // We always return a proxy and the jit-activation's attempt
                // to execute the constructor gets intercepted by the TP stub
                // and routed to RemotingServices.Activate() below.

                // if context *is* OK 
                // this is a contextBound type being activated for which 
                // we always create a proxy (proxies-everywhere!)

                // if context *is not* OK 
                // this could be a MarshalByRef or ContextBound type 
                // being activated outside this appDomain 
                // OR
                // this could be a ContextBound type being activated cross-ctx 

                RemotingProxy rp;
                // See if the object-type is configured for Connect (with a URL)
                retObj = (MarshalByRefObject)ConnectIfNecessary(ctorCallMsg);
                if (retObj == null)
                {
                    // not configured for connect, take the usual route of 
                    // creating a proxy
                    Message.DebugOut("Creating remoting proxy for " + 
                                 serverType.FullName + " in context " + 
                                 Thread.CurrentContext);  

                    rp = new RemotingProxy(serverType);

                    Message.DebugOut("Created remoting proxy\n");
                    retObj = (MarshalByRefObject)rp.GetTransparentProxy();
                }
                else
                {
                    Message.DebugOut("NewObj did a Connect!");
                    rp = (RemotingProxy)RemotingServices.GetRealProxy(retObj);                    
                }                    

                // Store the constructor call message in the proxy
                rp.ConstructorMessage = ctorCallMsg;

                if (!bCtxOK)
                {

                    // Chain in the context level activator now
                    ContextLevelActivator activator = new ContextLevelActivator();
                    activator.NextActivator = ctorCallMsg.Activator; 
                    ctorCallMsg.Activator = activator;
                }
                else
                {
                    // Set the flag to indicate that the activation
                    // will not be leaving the client context .. in this case
                    // the default construction level activator is enough
                    // to complete the activation process.
                    ctorCallMsg.ActivateInContext = true;
                }
            }

            return retObj;
        }
		public static ConstructionCall CreateConstructionCall (Type type, string activationUrl, object[] activationAttributes)
		{
			ConstructionCall ctorCall = new ConstructionCall (type);

			if (!type.IsContextful) 
			{
				// Must be a remote activated object
				ctorCall.Activator = new AppDomainLevelActivator (activationUrl, ConstructionActivator);
				ctorCall.IsContextOk = false;	// It'll be activated in a remote context
				return ctorCall;
			}

			// It is a CBO. Need collect context properties and
			// check if a new context is needed.

			IActivator activatorChain = ConstructionActivator;
			activatorChain = new ContextLevelActivator (activatorChain);

			ArrayList attributes = new ArrayList ();
			if (activationAttributes != null) attributes.AddRange (activationAttributes);

			bool isContextOk = (activationUrl == ChannelServices.CrossContextUrl);	// Remote CBOs are always created in a new context
			Context currentContext = Threading.Thread.CurrentContext;

			if (isContextOk) 
			{
				foreach (IContextAttribute attr in attributes) 
				{
					if (!attr.IsContextOK (currentContext, ctorCall)) 
					{
						isContextOk = false;
						break;
					}
				}
			}

			object[] typeAttributes = type.GetCustomAttributes (true);
			foreach (object attr in typeAttributes) 
			{
				if (attr is IContextAttribute) 
				{
					isContextOk = isContextOk && ((IContextAttribute)attr).IsContextOK (currentContext, ctorCall);
					attributes.Add (attr);
				}
			}

			if (!isContextOk)
			{
				// A new context is needed. Collect the context properties and chain
				// the context level activator.

				ctorCall.SetActivationAttributes (attributes.ToArray());

				foreach (IContextAttribute attr in attributes)
					attr.GetPropertiesForNewContext (ctorCall);
			}

			if (activationUrl != ChannelServices.CrossContextUrl)
				activatorChain = new AppDomainLevelActivator (activationUrl, activatorChain);
			
			ctorCall.Activator = activatorChain;
			ctorCall.IsContextOk = isContextOk;

			return ctorCall;
		}
 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;
 }