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
        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);
        }