Beispiel #1
0
 private void RaiseRunCollectorHostRestorationScript()
 {
     if (RestorationScriptMinimumRepeatTimeMin > 0 && DateTime.Now < LastRestorationScriptRun.AddMinutes(RestorationScriptMinimumRepeatTimeMin))
     {
         RaiseCorrectiveScriptMinRepeatTimeBlockedEvent("Restoration script blocked from running. The specified minimum number of seconds have not passed since the last time the script ran!");
     }
     else if (RunCollectorHostRestorationScript != null)
     {
         RunCollectorHostRestorationScript(this);
         LastRestorationScriptRun = DateTime.Now;
         TimesRestorationScriptRan++;
     }
 }
        private List <string> RunRestorationScripts(bool stateChanged = false)
        {
            List <string> scriptsRan = new List <string>();

            if (!stateChanged && RestorationScriptMinimumRepeatTimeMin == 0)
            {
                CorrectiveScriptMinRepeatTimeBlockedEvent?.Invoke(this, "Restoration script(s) blocked from running. It will only run if the state has changed!");
            }
            else if (RestorationScriptMinimumRepeatTimeMin > 0 && DateTime.Now < LastRestorationScriptRun.AddMinutes(RestorationScriptMinimumRepeatTimeMin))
            {
                CorrectiveScriptMinRepeatTimeBlockedEvent?.Invoke(this, "Restoration script(s) blocked from running. The specified minimum number of seconds have not passed since the last time the script ran!");
            }
            else
            {
                foreach (var restorationScript in (from s in ActionScripts
                                                   where s.IsRestorationScript
                                                   select s))
                {
                    try
                    {
                        //if (restorationScript.RunTimeLinkedActionScript != null)
                        //{
                        restorationScript.Run(false);
                        RestorationScriptExecuted?.Invoke(this, restorationScript.Name);
                        LastRestorationScriptRun = DateTime.Now;
                        scriptsRan.Add(restorationScript.Name);
                        //}
                        //else
                        //    ErrorCorrectiveScriptFailed?.Invoke(this, "No linked action script found!", restorationScript.MPId);
                    }
                    catch (Exception ex)
                    {
                        RestorationScriptFailed?.Invoke(this, restorationScript.Name, ex.Message);
                    }
                }
                if (scriptsRan.Count > 0)
                {
                    TimesRestorationScriptRan++;
                }
            }
            return(scriptsRan);
        }