Beispiel #1
0
        public void AddStepsOfType(Type type, List <DependentInitializationStep> dependentInitors)
        {
            var mgrAttr = type.GetCustomAttributes <GlobalMgrAttribute>().FirstOrDefault();

            if (mgrAttr != null)
            {
                UnresolvedDependencies.Add(type, new GlobalMgrInfo());
            }

            // Get all public static methods in this type.
            var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            // Check each method we found to see if it has an initialization attribute.
            foreach (var method in methods)
            {
                var attribute      = method.GetCustomAttributes <InitializationAttribute>().FirstOrDefault();
                var depInitorAttrs = method.GetCustomAttributes <DependentInitializationAttribute>();

                // Can't have multiple instances of the attribute on a single method, so we check for 1.
                if (attribute != null)
                {
                    var step = new InitializationStep(attribute.Pass, attribute.Name, attribute.IsRequired, method);

                    if (depInitorAttrs.Length > 0)
                    {
                        var dep = new DependentInitializationStep(step,
                                                                  depInitorAttrs.TransformArray(attr => new InitializationDependency(attr)));
                        dependentInitors.Add(dep);
                    }
                    else
                    {
                        AddIndipendentStep(step);
                    }

                    m_newSteps = true;
                }
                else
                {
                    if (depInitorAttrs.Length > 0)
                    {
                        throw new InitializationException("Invalid {0} - Requires missing {1} for: {2}",
                                                          typeof(DependentInitializationAttribute).Name,
                                                          typeof(InitializationAttribute).Name,
                                                          method.GetFullMemberName());
                    }
                }
            }
        }
Beispiel #2
0
 private void TryResolve(DependentInitializationStep depList)
 {
     if (!depList.Dependency.All(
             dep => dep.DependentMgr.IsInitialized))
     {
         return;
     }
     if (depList.Step.Pass != InitializationPass.Any && depList.Step.Pass > m_currentPass)
     {
         AddIndipendentStep(depList.Step);
     }
     else
     {
         DoExecute(depList.Step);
     }
 }
Beispiel #3
0
 private void TryResolve(DependentInitializationStep depList)
 {
     if (!((IEnumerable <InitializationDependency>)depList.Dependency).All <InitializationDependency>(
             (Func <InitializationDependency, bool>)(dep => dep.DependentMgr.IsInitialized)))
     {
         return;
     }
     if (depList.Step.Pass != InitializationPass.Any && depList.Step.Pass > this.m_currentPass)
     {
         this.AddIndipendentStep(depList.Step);
     }
     else
     {
         this.DoExecute(depList.Step);
     }
 }
Beispiel #4
0
        public void AddStepsOfType(Type type, List <DependentInitializationStep> dependentInitors)
        {
            if (((IEnumerable <GlobalMgrAttribute>)type.GetCustomAttributes <GlobalMgrAttribute>())
                .FirstOrDefault <GlobalMgrAttribute>() != null)
            {
                this.UnresolvedDependencies.Add(type, new GlobalMgrInfo());
            }
            foreach (MethodInfo method in type.GetMethods(BindingFlags.Static | BindingFlags.Public |
                                                          BindingFlags.NonPublic))
            {
                InitializationAttribute initializationAttribute =
                    ((IEnumerable <InitializationAttribute>)method.GetCustomAttributes <InitializationAttribute>())
                    .FirstOrDefault <InitializationAttribute>();
                DependentInitializationAttribute[] customAttributes =
                    method.GetCustomAttributes <DependentInitializationAttribute>();
                if (initializationAttribute != null)
                {
                    InitializationStep step = new InitializationStep(initializationAttribute.Pass,
                                                                     initializationAttribute.Name, initializationAttribute.IsRequired, method);
                    if (customAttributes.Length > 0)
                    {
                        DependentInitializationStep initializationStep = new DependentInitializationStep(step,
                                                                                                         ((IEnumerable <DependentInitializationAttribute>)customAttributes)
                                                                                                         .TransformArray <DependentInitializationAttribute, InitializationDependency>(
                                                                                                             (Func <DependentInitializationAttribute, InitializationDependency>)(attr =>
                                                                                                                                                                                 new InitializationDependency(attr))));
                        dependentInitors.Add(initializationStep);
                    }
                    else
                    {
                        this.AddIndipendentStep(step);
                    }

                    this.m_newSteps = true;
                }
                else if (customAttributes.Length > 0)
                {
                    throw new InitializationException("Invalid {0} - Requires missing {1} for: {2}", new object[3]
                    {
                        (object)typeof(DependentInitializationAttribute).Name,
                        (object)typeof(InitializationAttribute).Name,
                        (object)method.GetFullMemberName()
                    });
                }
            }
        }
Beispiel #5
0
 private void TryResolve(DependentInitializationStep depList)
 {
     if (depList.Dependency.All(dep => dep.DependentMgr.IsInitialized))
     {
         // all dependencies resolved
         if (depList.Step.Pass != InitializationPass.Any && depList.Step.Pass > m_currentPass)
         {
             // not ready yet -> Add to list
             AddIndipendentStep(depList.Step);
         }
         else
         {
             // can execute immediately
             DoExecute(depList.Step);
         }
     }
 }
Beispiel #6
0
    	private void TryResolve(DependentInitializationStep depList)
    	{
			if (depList.Dependency.All(dep => dep.DependentMgr.IsInitialized))
			{
				// all dependencies resolved
				if (depList.Step.Pass != InitializationPass.Any && depList.Step.Pass > m_currentPass)
				{
					// not ready yet -> Add to list
					AddIndipendentStep(depList.Step);
				}
				else
				{
					// can execute immediately
					DoExecute(depList.Step);
				}
			}
    	}
Beispiel #7
0
        public void AddStepsOfType(Type type, List<DependentInitializationStep> dependentInitors)
        {
            var mgrAttr = type.GetCustomAttributes<GlobalMgrAttribute>().FirstOrDefault();
            if (mgrAttr != null)
            {
                UnresolvedDependencies.Add(type, new GlobalMgrInfo());
            }

            // Get all public static methods in this type.
            var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            // Check each method we found to see if it has an initialization attribute.
            foreach (var method in methods)
            {
                var attribute = method.GetCustomAttributes<InitializationAttribute>().FirstOrDefault();
                var depInitorAttrs = method.GetCustomAttributes<DependentInitializationAttribute>();

                // Can't have multiple instances of the attribute on a single method, so we check for 1.
                if (attribute != null)
                {
					var step = new InitializationStep(attribute.Pass, attribute.Name, attribute.IsRequired, method);

                    if (depInitorAttrs.Length > 0)
                    {
						var dep = new DependentInitializationStep(step,
                            depInitorAttrs.TransformArray(attr => new InitializationDependency(attr)));
                        dependentInitors.Add(dep);
                    }
                    else
                    {
                    	AddIndipendentStep(step);
                    }

                    m_newSteps = true;
                }
                else
                {
                    if (depInitorAttrs.Length > 0)
                    {
                        throw new InitializationException("Invalid {0} - Requires missing {1} for: {2}",
                            typeof(DependentInitializationAttribute).Name,
                            typeof(InitializationAttribute).Name,
                            method.GetFullMemberName());
                    }
                }

            }
        }