Ejemplo n.º 1
0
        private static RunspaceConfiguration Create(Assembly assembly)
        {
            RunspaceConfiguration configuration;

            if (assembly == null)
            {
                throw PSTraceSource.NewArgumentNullException("assembly");
            }
            object[] customAttributes = assembly.GetCustomAttributes(typeof(RunspaceConfigurationTypeAttribute), false);
            if ((customAttributes == null) || (customAttributes.Length == 0))
            {
                throw new RunspaceConfigurationAttributeException("RunspaceConfigurationAttributeNotExist", assembly.FullName);
            }
            if (customAttributes.Length > 1)
            {
                throw new RunspaceConfigurationAttributeException("RunspaceConfigurationAttributeDuplicate", assembly.FullName);
            }
            RunspaceConfigurationTypeAttribute attribute = (RunspaceConfigurationTypeAttribute)customAttributes[0];

            try
            {
                configuration = Create(assembly.GetType(attribute.RunspaceConfigurationType, true));
            }
            catch (SecurityException)
            {
                throw new RunspaceConfigurationTypeException(assembly.FullName, attribute.RunspaceConfigurationType);
            }
            return(configuration);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create an RunspaceConfiguration-derived instance based an RunspaceConfiguration-derived type
        /// in specified assembly. The type name is defined by assembly attribute:
        /// RunspaceConfigurationTypeAttribute.
        /// </summary>
        /// <param name="assembly"></param>
        /// <returns>Runspace configuration instance created</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Exception thrown when <paramref name="assembly"/> is null or empty.
        /// </exception>
        private static RunspaceConfiguration Create(Assembly assembly)
        {
            if (assembly == null)
            {
                throw PSTraceSource.NewArgumentNullException("assembly");
            }

            object[] attributes = ClrFacade.GetCustomAttributes <RunspaceConfigurationTypeAttribute>(assembly);

            if (attributes == null || attributes.Length == 0)
            {
                throw new RunspaceConfigurationAttributeException("RunspaceConfigurationAttributeNotExist", assembly.FullName);
            }

            if (attributes.Length > 1)
            {
                throw new RunspaceConfigurationAttributeException("RunspaceConfigurationAttributeDuplicate", assembly.FullName);
            }

            RunspaceConfigurationTypeAttribute runspaceConfigTypeAttribute = (RunspaceConfigurationTypeAttribute)attributes[0];

            try
            {
                Type runspaceConfigType = assembly.GetType(runspaceConfigTypeAttribute.RunspaceConfigurationType, true, false);
                return(Create(runspaceConfigType));
            }
            catch (SecurityException)
            {
                throw new RunspaceConfigurationTypeException(assembly.FullName, runspaceConfigTypeAttribute.RunspaceConfigurationType);
            }
        }
Ejemplo n.º 3
0
        private static RunspaceConfiguration Create(Assembly assembly)
        {
            using (RunspaceConfiguration.tracer.TraceMethod())
            {
                object[] objArray = assembly != null?assembly.GetCustomAttributes(typeof(RunspaceConfigurationTypeAttribute), false) : throw RunspaceConfiguration.tracer.NewArgumentNullException(nameof(assembly));

                if (objArray == null || objArray.Length == 0)
                {
                    throw new RunspaceConfigurationAttributeException("RunspaceConfigurationAttributeNotExist", assembly.FullName);
                }
                RunspaceConfigurationTypeAttribute configurationTypeAttribute = objArray.Length <= 1 ? (RunspaceConfigurationTypeAttribute)objArray[0] : throw new RunspaceConfigurationAttributeException("RunspaceConfigurationAttributeDuplicate", assembly.FullName);
                try
                {
                    return(RunspaceConfiguration.Create(assembly.GetType(configurationTypeAttribute.RunspaceConfigurationType, true)));
                }
                catch (SecurityException ex)
                {
                    throw new RunspaceConfigurationTypeException(assembly.FullName, configurationTypeAttribute.RunspaceConfigurationType);
                }
            }
        }