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);
        }
            private static IContextAttribute[] CreateContextAttributesFromConfigEntries(ArrayList contextAttributes)
            {
                int count = contextAttributes.Count;

                if (count == 0)
                {
                    return(null);
                }
                IContextAttribute[] attributeArray = new IContextAttribute[count];
                int num2 = 0;

                foreach (RemotingXmlConfigFileData.ContextAttributeEntry entry in contextAttributes)
                {
                    Assembly          assembly   = Assembly.Load(entry.AssemblyName);
                    IContextAttribute attribute  = null;
                    Hashtable         properties = entry.Properties;
                    if ((properties != null) && (properties.Count > 0))
                    {
                        object[] args = new object[] { properties };
                        attribute = (IContextAttribute)Activator.CreateInstance(assembly.GetType(entry.TypeName, false, false), BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, args, null, null);
                    }
                    else
                    {
                        attribute = (IContextAttribute)Activator.CreateInstance(assembly.GetType(entry.TypeName, false, false), true);
                    }
                    attributeArray[num2++] = attribute;
                }
                return(attributeArray);
            }
Example #3
0
 internal static void GetPropertiesFromAttributes(IConstructionCallMessage ctorMsg, object[] attributes)
 {
     if (attributes != null)
     {
         for (int i = 0; i < attributes.Length; i++)
         {
             IContextAttribute attribute = attributes[i] as IContextAttribute;
             if (attribute == null)
             {
                 throw new RemotingException(Environment.GetResourceString("Remoting_Activation_BadAttribute"));
             }
             RuntimeAssembly asm = (RuntimeAssembly)attribute.GetType().Assembly;
             CheckForInfrastructurePermission(asm);
             attribute.GetPropertiesForNewContext(ctorMsg);
         }
     }
 }
 internal static void GetPropertiesFromAttributes(IConstructionCallMessage ctorMsg, object[] attributes)
 {
     if (attributes == null)
     {
         return;
     }
     for (int index = 0; index < attributes.Length; ++index)
     {
         IContextAttribute contextAttribute = attributes[index] as IContextAttribute;
         if (contextAttribute == null)
         {
             throw new RemotingException(Environment.GetResourceString("Remoting_Activation_BadAttribute"));
         }
         ActivationServices.CheckForInfrastructurePermission((RuntimeAssembly)contextAttribute.GetType().Assembly);
         contextAttribute.GetPropertiesForNewContext(ctorMsg);
     }
 }
        internal static IContextAttribute[] GetContextAttributesForType(Type serverType)
        {
            if (!typeof(ContextBoundObject).IsAssignableFrom(serverType) || serverType.IsCOMObject)
            {
                return((IContextAttribute[])new ContextAttribute[0]);
            }
            Type type1   = serverType;
            int  length1 = 8;

            IContextAttribute[] contextAttributeArray1 = new IContextAttribute[length1];
            int  length2       = 0;
            Type attributeType = typeof(IContextAttribute);
            int  num           = 1;

            foreach (IContextAttribute customAttribute in type1.GetCustomAttributes(attributeType, num != 0))
            {
                Type type2 = customAttribute.GetType();
                bool flag  = false;
                for (int index = 0; index < length2; ++index)
                {
                    if (type2.Equals(contextAttributeArray1[index].GetType()))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    ++length2;
                    if (length2 > length1 - 1)
                    {
                        IContextAttribute[] contextAttributeArray2 = new IContextAttribute[2 * length1];
                        Array.Copy((Array)contextAttributeArray1, 0, (Array)contextAttributeArray2, 0, length1);
                        contextAttributeArray1 = contextAttributeArray2;
                        length1 *= 2;
                    }
                    contextAttributeArray1[length2 - 1] = customAttribute;
                }
            }
            IContextAttribute[] contextAttributeArray3 = new IContextAttribute[length2];
            Array.Copy((Array)contextAttributeArray1, (Array)contextAttributeArray3, length2);
            return(contextAttributeArray3);
        }
Example #6
0
        internal static IContextAttribute[] GetContextAttributesForType(Type serverType)
        {
            if (!typeof(ContextBoundObject).IsAssignableFrom(serverType) || serverType.IsCOMObject)
            {
                return(new ContextAttribute[0]);
            }
            Type type   = serverType;
            int  length = 8;

            IContextAttribute[] sourceArray = new IContextAttribute[length];
            int num2 = 0;

            foreach (IContextAttribute attribute in type.GetCustomAttributes(typeof(IContextAttribute), true))
            {
                Type type2 = attribute.GetType();
                bool flag  = false;
                for (int i = 0; i < num2; i++)
                {
                    if (type2.Equals(sourceArray[i].GetType()))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    num2++;
                    if (num2 > (length - 1))
                    {
                        IContextAttribute[] attributeArray2 = new IContextAttribute[2 * length];
                        Array.Copy(sourceArray, 0, attributeArray2, 0, length);
                        sourceArray = attributeArray2;
                        length     *= 2;
                    }
                    sourceArray[num2 - 1] = attribute;
                }
            }
            IContextAttribute[] destinationArray = new IContextAttribute[num2];
            Array.Copy(sourceArray, destinationArray, num2);
            return(destinationArray);
        }
        internal static IContextAttribute[] GetContextAttributesForType(Type serverType)
        {
            if (!typeof(ContextBoundObject).IsAssignableFrom(serverType) || serverType.IsCOMObject)
            {
                return(new ContextAttribute[0]);
            }
            int num = 8;

            IContextAttribute[] array = new IContextAttribute[num];
            int num2 = 0;

            object[] customAttributes = serverType.GetCustomAttributes(typeof(IContextAttribute), true);
            foreach (IContextAttribute contextAttribute in customAttributes)
            {
                Type type = contextAttribute.GetType();
                bool flag = false;
                for (int j = 0; j < num2; j++)
                {
                    if (type.Equals(array[j].GetType()))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    num2++;
                    if (num2 > num - 1)
                    {
                        IContextAttribute[] array3 = new IContextAttribute[2 * num];
                        Array.Copy(array, 0, array3, 0, num);
                        array = array3;
                        num  *= 2;
                    }
                    array[num2 - 1] = contextAttribute;
                }
            }
            IContextAttribute[] array4 = new IContextAttribute[num2];
            Array.Copy(array, array4, num2);
            return(array4);
        }
        private static bool QueryAttributesIfContextOK(Context ctx, IConstructionCallMessage ctorMsg, object[] attributes)
        {
            bool flag = true;

            if (attributes != null)
            {
                for (int index = 0; index < attributes.Length; ++index)
                {
                    IContextAttribute contextAttribute = attributes[index] as IContextAttribute;
                    if (contextAttribute == null)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_Activation_BadAttribute"));
                    }
                    ActivationServices.CheckForInfrastructurePermission((RuntimeAssembly)contextAttribute.GetType().Assembly);
                    flag = contextAttribute.IsContextOK(ctx, ctorMsg);
                    if (!flag)
                    {
                        break;
                    }
                }
            }
            return(flag);
        }
Example #9
0
        private static bool QueryAttributesIfContextOK(Context ctx, IConstructionCallMessage ctorMsg, object[] attributes)
        {
            bool flag = true;

            if (attributes != null)
            {
                for (int i = 0; i < attributes.Length; i++)
                {
                    IContextAttribute attribute = attributes[i] as IContextAttribute;
                    if (attribute == null)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_Activation_BadAttribute"));
                    }
                    RuntimeAssembly asm = (RuntimeAssembly)attribute.GetType().Assembly;
                    CheckForInfrastructurePermission(asm);
                    flag = attribute.IsContextOK(ctx, ctorMsg);
                    if (!flag)
                    {
                        return(flag);
                    }
                }
            }
            return(flag);
        }
Example #10
0
            } // GetRegisteredWellKnownClientTypes


            //
            // end of helper functions to retrieve registered types
            //

            internal void AddActivatedType(String typeName, String assemblyName,
                                           IContextAttribute[] contextAttributes)
            {
                if (typeName == null)
                    throw new ArgumentNullException("typeName");
                if (assemblyName == null)
                    throw new ArgumentNullException("assemblyName");
                Contract.EndContractBlock();

                if (CheckForRedirectedClientType(typeName, assemblyName))
                {
                    throw new RemotingException(
                        String.Format(
                            CultureInfo.CurrentCulture, Environment.GetResourceString(
                                "Remoting_Config_CantUseRedirectedTypeForWellKnownService"),
                            typeName, assemblyName));
                }                                

                ActivatedServiceTypeEntry aste =  
                    new ActivatedServiceTypeEntry(typeName, assemblyName);
                aste.ContextAttributes = contextAttributes;
            
                //   The assembly name is stored in lowercase to let it be case-insensitive.
                String key = EncodeTypeAndAssemblyNames(typeName, assemblyName);
                _exportableClasses.Add(key, aste);
            } // AddActivatedType
Example #11
0
            } // StoreWellKnownExports
            

            // helper functions for above configuration helpers

            static IContextAttribute[] CreateContextAttributesFromConfigEntries(ArrayList contextAttributes)
            {
                // create context attribute entry list
                int numAttrs = contextAttributes.Count;
                if (numAttrs == 0)
                    return null;
                
                IContextAttribute[] attrs = new IContextAttribute[numAttrs];

                int co = 0;
                foreach (RemotingXmlConfigFileData.ContextAttributeEntry cae in contextAttributes)
                {
                    Assembly asm = Assembly.Load(cae.AssemblyName);  

                    IContextAttribute attr = null;
                    Hashtable properties = cae.Properties;                    
                    if ((properties != null) && (properties.Count > 0))
                    {
                        Object[] args = new Object[1];
                        args[0] = properties;

                        // We explicitly allow the ability to create internal
                        // only attributes
                        attr = (IContextAttribute)
                            Activator.CreateInstance(
                                asm.GetType(cae.TypeName, false, false), 
                                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, 
                                null, 
                                args, 
                                null, 
                                null);
                    }
                    else
                    {
                        attr = (IContextAttribute)
                            Activator.CreateInstance(
                                asm.GetType(cae.TypeName, false, false), 
                                true);
                    }
                    
                    attrs[co++] = attr; 
                }

                return attrs;
            } // CreateContextAttributesFromConfigEntries
Example #12
0
        internal static IContextAttribute[] GetContextAttributesForType(Type serverType)
        {
            if (!(typeof(ContextBoundObject).IsAssignableFrom(serverType)) ||
                serverType.IsCOMObject)
            {
                return new ContextAttribute[0];
            }

            Type currType = serverType;
            Object[] currAttr = null;
            int retSize = 8;
            IContextAttribute[] retAttr = new IContextAttribute[retSize];
            int numAttr = 0;
    
    
            // Obtain the custom attributes that implement 
            // IContextAttribute for this type
            currAttr = currType.GetCustomAttributes(
                                    typeof(IContextAttribute),
                                    true);  // recursively on the typeHierarchy
            Boolean bDupe;                             
            foreach (IContextAttribute attr in currAttr)
            {
                Type attrType = attr.GetType();
                bDupe = false;
                for (int i=0; i<numAttr; i++)
                {
                    if (attrType.Equals(retAttr[i].GetType()))
                    {
                        bDupe = true;
                        break;
                    }
                }

                if (!bDupe)
                { 
                    // We must add this attribute to our list
                    numAttr++;
                     
                    // Check if we have enough space to store it
                    // Leaving one spot for a NULL value!
                    if (numAttr > retSize-1)
                    {
                        IContextAttribute[] newAttr = new IContextAttribute[2*retSize];
                        Array.Copy(
                            retAttr,     // srcArray
                            0,          // srcIndex
                            newAttr,    // destArray
                            0,          // destIndex
                            retSize);   // lengthToCopy
                        retAttr = newAttr;
                        retSize = retSize*2;
                    }
                    retAttr[numAttr-1] = attr;
                }
            }
           
            IContextAttribute[] ctxAttr = new IContextAttribute[numAttr];
            Array.Copy(retAttr, ctxAttr, numAttr);
            return ctxAttr;
        }  
 private static IContextAttribute[] CreateContextAttributesFromConfigEntries(ArrayList contextAttributes)
 {
     int count = contextAttributes.Count;
     if (count == 0)
     {
         return null;
     }
     IContextAttribute[] attributeArray = new IContextAttribute[count];
     int num2 = 0;
     foreach (RemotingXmlConfigFileData.ContextAttributeEntry entry in contextAttributes)
     {
         Assembly assembly = Assembly.Load(entry.AssemblyName);
         IContextAttribute attribute = null;
         Hashtable properties = entry.Properties;
         if ((properties != null) && (properties.Count > 0))
         {
             object[] args = new object[] { properties };
             attribute = (IContextAttribute) Activator.CreateInstance(assembly.GetType(entry.TypeName, false, false), BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, args, null, null);
         }
         else
         {
             attribute = (IContextAttribute) Activator.CreateInstance(assembly.GetType(entry.TypeName, false, false), true);
         }
         attributeArray[num2++] = attribute;
     }
     return attributeArray;
 }
 internal void AddActivatedType(string typeName, string assemblyName, IContextAttribute[] contextAttributes)
 {
     if (typeName == null)
     {
         throw new ArgumentNullException("typeName");
     }
     if (assemblyName == null)
     {
         throw new ArgumentNullException("assemblyName");
     }
     if (this.CheckForRedirectedClientType(typeName, assemblyName))
     {
         throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_CantUseRedirectedTypeForWellKnownService"), new object[] { typeName, assemblyName }));
     }
     ActivatedServiceTypeEntry entry = new ActivatedServiceTypeEntry(typeName, assemblyName) {
         ContextAttributes = contextAttributes
     };
     string key = this.EncodeTypeAndAssemblyNames(typeName, assemblyName);
     this._exportableClasses.Add(key, entry);
 }
 internal static IContextAttribute[] GetContextAttributesForType(Type serverType)
 {
     if (!typeof(ContextBoundObject).IsAssignableFrom(serverType) || serverType.IsCOMObject)
     {
         return new ContextAttribute[0];
     }
     Type type = serverType;
     int length = 8;
     IContextAttribute[] sourceArray = new IContextAttribute[length];
     int num2 = 0;
     foreach (IContextAttribute attribute in type.GetCustomAttributes(typeof(IContextAttribute), true))
     {
         Type type2 = attribute.GetType();
         bool flag = false;
         for (int i = 0; i < num2; i++)
         {
             if (type2.Equals(sourceArray[i].GetType()))
             {
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             num2++;
             if (num2 > (length - 1))
             {
                 IContextAttribute[] attributeArray2 = new IContextAttribute[2 * length];
                 Array.Copy(sourceArray, 0, attributeArray2, 0, length);
                 sourceArray = attributeArray2;
                 length *= 2;
             }
             sourceArray[num2 - 1] = attribute;
         }
     }
     IContextAttribute[] destinationArray = new IContextAttribute[num2];
     Array.Copy(sourceArray, destinationArray, num2);
     return destinationArray;
 }