Ejemplo n.º 1
0
            private void InitCreationChain(ComponentRequirementMap map)
            {
                this.CreationChain = new List <CreationChainItem>();

                IEnumerable <RequiredComponentAttribute> attributes = this.Component.GetTypeInfo().GetAttributesCached <RequiredComponentAttribute>();

                foreach (RequiredComponentAttribute attrib in attributes)
                {
                    // Ignore invalid constraints
                    if (!this.IsValidRequirement(attrib))
                    {
                        continue;
                    }

                    // If this is a conditional creation, add the sub-chain of the Component to create
                    if (attrib.CreateDefaultType != attrib.RequiredComponentType)
                    {
                        this.AddCreationChainElements(map, attrib, attrib.CreateDefaultType);
                    }

                    // In any case, add the sub-chain of direct requirements
                    this.AddCreationChainElements(map, attrib, attrib.RequiredComponentType);
                }

                // Remove any duplicates that we might have generated in the creation chain
                this.RemoveCreationChainDuplicates();
            }
Ejemplo n.º 2
0
            private void InitRequirements(ComponentRequirementMap map)
            {
                this.Requirements = new List <Type>();

                IEnumerable <RequiredComponentAttribute> attribs = this.Component.GetTypeInfo().GetAttributesCached <RequiredComponentAttribute>();

                foreach (RequiredComponentAttribute a in attribs)
                {
                    Type reqType = a.RequiredComponentType;

                    // Don't require itself
                    if (reqType == this.Component)
                    {
                        continue;
                    }

                    // Ignore invalid constraints
                    if (!this.IsValidRequirement(a))
                    {
                        continue;
                    }

                    this.Requirements.AddRange(map.GetRequirements(reqType).Where(t => !this.Requirements.Contains(t)));
                    if (!this.Requirements.Contains(reqType))
                    {
                        this.Requirements.Add(reqType);
                    }
                }
            }
Ejemplo n.º 3
0
            public void EnsureCreationChain(ComponentRequirementMap map)
            {
                if (this.initCreationChain == RecursiveInit.Initialized)
                {
                    return;
                }
                if (this.initCreationChain == RecursiveInit.InProgress)
                {
                    Log.Write(LogType.Error,
                              "Detected a cyclic Component requirement in {0}. Requirements can not be ensured for cyclic dependencies.",
                              this.Component);
                    return;
                }

                this.initCreationChain = RecursiveInit.InProgress;
                this.InitCreationChain(map);
                this.initCreationChain = RecursiveInit.Initialized;
            }
Ejemplo n.º 4
0
            public void EnsureRequirements(ComponentRequirementMap map)
            {
                if (this.initRequirements == RecursiveInit.Initialized)
                {
                    return;
                }
                if (this.initRequirements == RecursiveInit.InProgress)
                {
                    Console.WriteLine(
                        "Detected a cyclic Component requirement in {0}. Requirements can not be ensured for cyclic dependencies.",
                        this.Component);
                    return;
                }

                this.initRequirements = RecursiveInit.InProgress;
                this.InitRequirements(map);
                this.initRequirements = RecursiveInit.Initialized;
            }
Ejemplo n.º 5
0
            public void EnsureRequirements(ComponentRequirementMap map)
            {
                if (this.initRequirements == RecursiveInit.Initialized)
                {
                    return;
                }
                if (this.initRequirements == RecursiveInit.InProgress)
                {
                    Logs.Core.WriteWarning(
                        "Detected a cyclic Component requirement in {0}. Requirements can not be ensured for cyclic dependencies.",
                        LogFormat.Type(this.Component));
                    return;
                }

                this.initRequirements = RecursiveInit.InProgress;
                this.InitRequirements(map);
                this.initRequirements = RecursiveInit.Initialized;
            }
Ejemplo n.º 6
0
            private void AddCreationChainElements(ComponentRequirementMap map, RequiredComponentAttribute attrib, Type subChainType)
            {
                if (subChainType == this.Component)
                {
                    return;
                }

                int baseIndex      = this.CreationChain.Count;
                int subChainLength = 0;

                // Retrieve the creation sub-chain to satisfy this item's requirements
                List <CreationChainItem> createTypeSubChain = map.GetCreationChain(subChainType);

                foreach (CreationChainItem subItem in createTypeSubChain)
                {
                    this.CreationChain.Add(subItem);
                    subChainLength++;
                }

                // Add the main item after its requirement items so we're always creating bottom-up
                this.CreationChain.Add(new CreationChainItem
                {
                    RequiredType = attrib.RequiredComponentType,
                    CreateType   = attrib.CreateDefaultType
                });

                // If this is a conditional requirement, add a control item that checks the
                // requirement and skips this item and its sub-chains if it's already met.
                if (subChainLength > 0 && attrib.CreateDefaultType != attrib.RequiredComponentType)
                {
                    this.CreationChain.Insert(baseIndex, new CreationChainItem
                    {
                        RequiredType = attrib.RequiredComponentType,
                        SkipIfExists = 1 + subChainLength
                    });
                }
            }