private InstallDestination CreateDestination(XmlNode sdest)
        {
            string asm = defaultAssembly;

            if ((sdest as XmlElement).HasAttribute(assemblyAttribute))
            {
                asm = sdest.Attributes[assemblyAttribute].Value;
            }

            string nsp = defaultDestinationNamespace;

            if ((sdest as XmlElement).HasAttribute(namespaceAttribute))
            {
                asm = sdest.Attributes[namespaceAttribute].Value;
            }

            string fullName = String.Format("{0}.{1}, {2}", nsp, sdest.Name, asm);
            Type   t        = Type.GetType(fullName);

            if (t != null)
            {
                InstallDestination inspected = t.GetConstructor(Type.EmptyTypes).Invoke(null) as InstallDestination;

                IComponentConfiguration config = new StandardConfiguration();
                foreach (XmlAttribute attribute in sdest.Attributes)
                {
                    config.Values[attribute.Name] = new Simple(attribute.Value);
                }

                return(ConfiguredComponent.ReconfigureInstance(inspected, inspected.GetType(), componentEnvironment, config));
            }

            throw new Exception(String.Format("The Install Destination {0} is not supported.", sdest.Name));
        }
        string[] RegisterAutoParametrization(IComponentDirectory destination, string[] args)
        {
            // We must add auto parametrization.
            ConfiguredComponent typeProvider = destination.FindByName(
                applicationDescriptor.ApplicationComponent)[0] as ConfiguredComponent;

            Type type = typeProvider.ComponentType;

            if (type.GetCustomAttributes(typeof(AutoParametrizeAttribute), true).Length > 0)
            {
                return(AutoParametrization.PerformAutoParametrization(type, localDirectory, args));
            }
            return(args.Clone() as string[]);
        }
Beispiel #3
0
        public void PostComponentInit(IComponentDirectory directory)
        {
            concurrencyCount = (uint)(System.Environment.ProcessorCount * workerThreadsPerCore);

            for (int i = 0; i < System.Environment.ProcessorCount; ++i)
            {
                CPUWorkUnit masterWorkUnit = null;

                for (int j = 0; j < workerThreadsPerCore; ++j)
                {
                    IComponentConfiguration config = new StandardConfiguration();
                    config.Values["CoreNumber"]  = new Simple(i);
                    config.Values["SliceNumber"] = new Simple(j);
                    if (masterWorkUnit != null)
                    {
                        config.Values["Previous"] = new Simple(masterWorkUnit);
                    }
                    config.Values["SlicesPerCore"] = new Simple((int)workerThreadsPerCore);

                    ConfiguredComponent component = new ConfiguredComponent(
                        typeof(CPUWorkUnit).FullName,
                        config);

                    CPUWorkUnit wu =
                        Components.ConfigureInlineComponent(component) as CPUWorkUnit;

                    this.registry.Register(wu);

                    if (j == 0)
                    {
                        masterWorkUnit = wu;
                    }
                }
            }

            controlThread = new Thread(Controller);

            controlThreadTimer =
                new Timer(Schedule, null, TimeSpan.Zero, DefaultTimeSlice);
        }
        private InstallSource CreateSource(XmlNode src)
        {
            string asm = defaultAssembly;

            if ((src as XmlElement).HasAttribute(assemblyAttribute))
            {
                asm = src.Attributes[assemblyAttribute].Value;
            }

            string nsp = defaultSourceNamespace;

            if ((src as XmlElement).HasAttribute(namespaceAttribute))
            {
                asm = src.Attributes[namespaceAttribute].Value;
            }

            string fullName = String.Format("{0}.{1}, {2}", nsp, src.Name, asm);

            Type t = Type.GetType(fullName);

            if (t != null)
            {
                InstallSource inspected = t.GetConstructor(Type.EmptyTypes).Invoke(null) as InstallSource;

                IComponentConfiguration config = new StandardConfiguration();
                foreach (XmlAttribute attribute in src.Attributes)
                {
                    config.Values[attribute.Name] = new Simple(attribute.Value);
                }

                inspected = ConfiguredComponent.ReconfigureInstance(
                    inspected, inspected.GetType(), componentEnvironment, config);


                if (src.ChildNodes.Count == 1)
                {
                    PropertyInfo pinfo = t.GetProperty(childPropertyName);
                    if (pinfo == null)
                    {
                        throw new Exception(String.Format("Source {0} does not allow child sources", src.Name));
                    }
                    InstallSource child = CreateSource(src.ChildNodes[0]);
                    pinfo.SetValue(inspected, child, null);
                }

                else if (src.ChildNodes.Count > 1)
                {
                    PropertyInfo pinfo = t.GetProperty(childPropertyName);
                    if (pinfo == null)
                    {
                        throw new Exception(String.Format("Source {0} does not allow child sources", src.Name));
                    }

                    if (pinfo.GetIndexParameters().Length == 0)
                    {
                        throw new Exception(String.Format("Source {0} does not allow multiple child sources", src.Name));
                    }
                    int i = 0;
                    foreach (XmlNode node in src.ChildNodes)
                    {
                        InstallSource child = CreateSource(src.ChildNodes[0]);
                        pinfo.SetValue(inspected, child, new object[] { i });
                    }
                }

                return(inspected);
            }

            throw new Exception(String.Format("The Install Source {0} is not supported.", src.Name));
        }