コード例 #1
0
 private void DoExecute(InitializationStep step)
 {
     if (!Execute(step))
     {
         throw new InitializationException("Failed to Execute dependent step: " + step);
     }
 }
コード例 #2
0
ファイル: InitMgr.cs プロジェクト: NecroSharper/WCell
        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());
                    }
                }
            }
        }
コード例 #3
0
ファイル: InitMgr.cs プロジェクト: uvbs/Asda2-Server
        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()
                    });
                }
            }
        }
コード例 #4
0
        public bool Execute(InitializationStep step)
        {
            step.Executed = true;
            bool flag = false;

            object[] args = step.GetArgs(this);
            DateTime now  = DateTime.Now;

            try
            {
                object obj = step.InitMethod.Invoke(null, args);
                if (obj is bool && !(bool)obj)
                {
                    s_log.Error(WCell_Core.InitStepFailed, step.InitStepName,
                                step.InitMethod.Name, ".");
                }
                else
                {
                    flag = true;
                }
            }
            catch (Exception ex)
            {
                LogUtil.ErrorException(ex, WCell_Core.InitStepFailed, (object)step.InitStepName,
                                       (object)step.InitMethod.Name, (object)"");
            }

            if (flag)
            {
                ++totalSuccess;
                if (!string.IsNullOrEmpty(step.InitStepName))
                {
                    TimeSpan timeSpan = DateTime.Now - now;
                    if (!m_MeasureSteps)
                    {
                        ;
                    }
                    string[] strArray1 = new string[5]
                    {
                        timeSpan.Minutes.ToString().PadLeft(2, '0'),
                        ":",
                        null,
                        null,
                        null
                    };
                    string[] strArray2 = strArray1;
                    int      index1    = 2;
                    int      num       = timeSpan.Seconds;
                    string   str1      = num.ToString().PadLeft(2, '0');
                    strArray2[index1] = str1;
                    strArray1[3]      = ".";
                    string[] strArray3 = strArray1;
                    int      index2    = 4;
                    num = timeSpan.Milliseconds;
                    string str2 = num.ToString().PadLeft(2, '0');
                    strArray3[index2] = str2;
                    string str3 = string.Concat(strArray1);
                    s_log.Info(string.Format(WCell_Core.InitStepSucceeded, step.InitStepName,
                                             str3));
                }
            }
            else if (!failHandler(this, step))
            {
                if (step.IsRequired)
                {
                    s_log.Fatal(string.Format(WCell_Core.InitStepWasRequired, step.InitStepName,
                                              step.InitMethod.Name));
                    return(false);
                }

                ++totalFails;
            }

            return(true);
        }
コード例 #5
0
 private void AddIndipendentStep(InitializationStep step)
 {
     ++totalStepCount;
     InitSteps[step.Pass].Add(step);
 }
コード例 #6
0
ファイル: InitMgr.cs プロジェクト: pallmall/WCell
 private void DoExecute(InitializationStep step)
 {
     if (!Execute(step))
     {
         throw new InitializationException("Failed to Execute dependent step: " + step);
     }
 }
コード例 #7
0
ファイル: InitMgr.cs プロジェクト: pallmall/WCell
        public bool Execute(InitializationStep step)
        {
            step.Executed = true;
            var success = false;

            // check whether the Mgr is expected as first argument
            var args = step.GetArgs(this);
            var start = DateTime.Now;

            // If the invoke method returns a bool, we assume it is referring to whether or not
            // it actually completed.
            try
            {
                // Invoke the method and capture its return value
                var result = step.InitMethod.Invoke(null, args);

                if ((result is bool) && !(bool)result)
                {
                    // Step failed.  Check if it was required and and log the initial failure.
                    s_log.Error(Resources.InitStepFailed, step.InitStepName, step.InitMethod.Name, ".");
                }
                else
                {
                    success = true;
                }
            }
            catch (Exception ex)
            {
                // Step failed.  Check if it was required and and log the initial failure.
                LogUtil.ErrorException(ex, Resources.InitStepFailed, step.InitStepName, step.InitMethod.Name, "");
            }

            if (success)
            {
                // Step succeeded

                totalSuccess++;
                if (!string.IsNullOrEmpty(step.InitStepName))
                {
                    var span = DateTime.Now - start;
                    if (m_MeasureSteps)
                    {
                        // save stats for later use
                    }
                    var timeStr = span.Minutes.ToString().PadLeft(2, '0') + ":" + span.Seconds.ToString().PadLeft(2, '0')
                                  + "." + span.Milliseconds.ToString().PadLeft(2, '0');
                    s_log.Info(string.Format(Resources.InitStepSucceeded, step.InitStepName, timeStr));
                }
            }
            else
            {
                if (!failHandler(this, step))
                {
                    // Step failed
                    if (step.IsRequired)
                    {
                        // It was required.  Log this, and cease any further initialization.
                        s_log.Fatal(string.Format(Resources.InitStepWasRequired, step.InitStepName, step.InitMethod.Name));

                        return false;
                    }
                    else
                    {
                        totalFails++;
                    }
                }
            }
            return true;
        }
コード例 #8
0
ファイル: InitMgr.cs プロジェクト: pallmall/WCell
        public void AddStepsOfType(Type type, List<InitializationDependency> 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 part = new InitializationStep(attribute.Name, attribute.IsRequired, method);

                    if (depInitorAttrs.Length > 0)
                    {
                        var dep = new InitializationDependency(new InitializationStep(attribute.Name, attribute.IsRequired, method),
                            depInitorAttrs.TransformArray(attr => new DependentInitializationInfo(attr)));
                        dependentInitors.Add(dep);
                    }
                    else
                    {
                        InitSteps[attribute.Pass].Add(part);
                    }

                    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.GetMemberName());
                    }
                }

            }
        }
コード例 #9
0
ファイル: InitMgr.cs プロジェクト: Jeroz/WCell
    	private void AddIndipendentStep(InitializationStep step)
    	{
    		totalStepCount++;
			InitSteps[step.Pass].Add(step);
    	}
コード例 #10
0
		public InitializationDependency(InitializationStep step, DependentInitializationInfo[] info)
		{
			Step = step;
			Info = info;
		}
コード例 #11
0
ファイル: InitMgr.cs プロジェクト: NecroSharper/WCell
        public bool Execute(InitializationStep step)
        {
            step.Executed = true;
            var success = false;

            // check whether the Mgr is expected as first argument
            var args  = step.GetArgs(this);
            var start = DateTime.Now;

            // If the invoke method returns a bool, we assume it is referring to whether or not
            // it actually completed.
            try
            {
                // Invoke the method and capture its return value
                var result = step.InitMethod.Invoke(null, args);

                if ((result is bool) && !(bool)result)
                {
                    // Step failed.  Check if it was required and and log the initial failure.
                    s_log.Error(Resources.InitStepFailed, step.InitStepName, step.InitMethod.Name, ".");
                }
                else
                {
                    success = true;
                }
            }
            catch (Exception ex)
            {
                // Step failed.  Check if it was required and and log the initial failure.
                LogUtil.ErrorException(ex, Resources.InitStepFailed, step.InitStepName, step.InitMethod.Name, "");
            }

            if (success)
            {
                // Step succeeded

                totalSuccess++;
                if (!string.IsNullOrEmpty(step.InitStepName))
                {
                    var span = DateTime.Now - start;
                    if (m_MeasureSteps)
                    {
                        // save stats for later use
                    }
                    var timeStr = span.Minutes.ToString().PadLeft(2, '0') + ":" + span.Seconds.ToString().PadLeft(2, '0')
                                  + "." + span.Milliseconds.ToString().PadLeft(2, '0');
                    s_log.Info(string.Format(Resources.InitStepSucceeded, step.InitStepName, timeStr));
                }
            }
            else
            {
                if (!failHandler(this, step))
                {
                    // Step failed
                    if (step.IsRequired)
                    {
                        // It was required.  Log this, and cease any further initialization.
                        s_log.Fatal(string.Format(Resources.InitStepWasRequired, step.InitStepName, step.InitMethod.Name));

                        return(false);
                    }
                    else
                    {
                        totalFails++;
                    }
                }
            }
            return(true);
        }
コード例 #12
0
ファイル: InitMgr.cs プロジェクト: MeaNone/WCell
    	private void AddIndipendentStep(InitializationStep step)
    	{
			InitSteps[step.Pass].Add(step);
    	}