private List <string> RunErrorCorrectiveScripts(bool stateChanged = false)
        {
            List <string> scriptsRan = new List <string>();

            if (!stateChanged && CorrectiveScriptOnErrorMinimumRepeatTimeMin == 0)
            {
                CorrectiveScriptMinRepeatTimeBlockedEvent?.Invoke(this, "Error corrective script(s) blocked from running. It will only run if the state has changed!");
            }
            else if (CorrectiveScriptOnErrorMinimumRepeatTimeMin > 0 && DateTime.Now < LastErrorCorrectiveScriptRun.AddMinutes(CorrectiveScriptOnErrorMinimumRepeatTimeMin))
            {
                CorrectiveScriptMinRepeatTimeBlockedEvent?.Invoke(this, "Error corrective script(s) blocked from running. The specified minimum number of seconds have not passed since the last time the script ran!");
            }
            else
            {
                foreach (var errorScript in (from s in ActionScripts
                                             where s.IsErrorCorrectiveScript
                                             select s))
                {
                    try
                    {
                        //if (errorScript.RunTimeLinkedActionScript != null)
                        //{
                        errorScript.Run(false);
                        ErrorCorrectiveScriptExecuted?.Invoke(this, errorScript.Name);
                        LastErrorCorrectiveScriptRun = DateTime.Now;
                        scriptsRan.Add(errorScript.Name);
                        //}
                        //else
                        //    ErrorCorrectiveScriptFailed?.Invoke(this, "No linked action script found!", errorScript.MPId);
                    }
                    catch (Exception ex)
                    {
                        ErrorCorrectiveScriptFailed?.Invoke(this, errorScript.Name, ex.Message);
                    }
                }
                if (scriptsRan.Count > 0)
                {
                    TimesErrorCorrectiveScriptRan++;
                }
            }
            return(scriptsRan);
        }
示例#2
0
 private void collectorHost_CorrectiveScriptMinRepeatTimeBlockedEvent(CollectorHost collectorHost, string message)
 {
     LogCorrectiveScriptMinRepeatTimeBlockedEvent(collectorHost, message);
     CorrectiveScriptMinRepeatTimeBlockedEvent?.Invoke(collectorHost, message);
 }