public void Run() { try { if (_isSafetyNetRunning != true) //checking if safetynet has already been started { this.StartSafetyNet(); //watch instance numbers _isSafetyNetRunning = true; } if (_isTempCleanerRunning != true) //checking if tempcleaner has been started { TempFiles.StartTempFileWatcher(); //watch temp directory on a diff schedule _isTempCleanerRunning = true; } this._timeline = TimelineBuilder.GetLocalTimeline(); // now watch that file for changes if (timelineWatcher == null) //you can change this to a bool if you want but checks if the object has been created { _log.Trace("Timeline watcher starting and is null..."); timelineWatcher = new FileSystemWatcher(TimelineBuilder.TimelineFilePath().DirectoryName) { Filter = Path.GetFileName(TimelineBuilder.TimelineFilePath().Name) }; _log.Trace($"watching {Path.GetFileName(TimelineBuilder.TimelineFilePath().Name)}"); timelineWatcher.NotifyFilter = NotifyFilters.LastWrite; timelineWatcher.EnableRaisingEvents = true; timelineWatcher.Changed += OnChanged; } _threadJobs = new List <ThreadJob>(); //load into an managing object //which passes the timeline commands to handlers //and creates a thread to execute instructions over that timeline if (this._timeline.Status == Timeline.TimelineStatus.Run) { RunEx(this._timeline); } else { if (MonitorThread != null) { MonitorThread.Abort(); MonitorThread = null; } } } catch (Exception e) { _log.Error($"Orchestrator.Run exception: {e}"); } }
///here lies technical debt //TODO clean up // if supposed to be one excel running, and there is more than 2, then kill race condition private static void SafetyNet() { while (true) { try { _log.Trace("SafetyNet loop beginning"); FileListing.FlushList(); //Added 6/10 by AMV to clear clogged while loop. var timeline = TimelineBuilder.GetLocalTimeline(); var handlerCount = timeline.TimeLineHandlers.Count(o => o.HandlerType == HandlerType.Excel); var pids = ProcessManager.GetPids(ProcessManager.ProcessNames.Excel).ToList(); if (pids.Count > handlerCount + 1) { _log.Trace($"SafetyNet excel handlers: {handlerCount} pids: {pids.Count} - killing"); ProcessManager.KillProcessAndChildrenByName(ProcessManager.ProcessNames.Excel); } handlerCount = timeline.TimeLineHandlers.Count(o => o.HandlerType == HandlerType.PowerPoint); pids = ProcessManager.GetPids(ProcessManager.ProcessNames.PowerPoint).ToList(); if (pids.Count > handlerCount + 1) { _log.Trace($"SafetyNet powerpoint handlers: {handlerCount} pids: {pids.Count} - killing"); ProcessManager.KillProcessAndChildrenByName(ProcessManager.ProcessNames.PowerPoint); } handlerCount = timeline.TimeLineHandlers.Count(o => o.HandlerType == HandlerType.Word); pids = ProcessManager.GetPids(ProcessManager.ProcessNames.Word).ToList(); if (pids.Count > handlerCount + 1) { _log.Trace($"SafetyNet word handlers: {handlerCount} pids: {pids.Count} - killing"); ProcessManager.KillProcessAndChildrenByName(ProcessManager.ProcessNames.Word); } _log.Trace("SafetyNet loop ending"); } catch (Exception e) { _log.Trace($"SafetyNet exception: {e}"); } finally { Thread.Sleep(60000); //every 60 seconds clean up } } }
public void Run() { try { this.StartSafetyNet(); //watch instance numbers TempFiles.StartTempFileWatcher(); //watch temp directory on a diff schedule this._timeline = TimelineBuilder.GetLocalTimeline(); // now watch that file for changes FileSystemWatcher timelineWatcher = new FileSystemWatcher(TimelineBuilder.TimelineFilePath().DirectoryName) { Filter = Path.GetFileName(TimelineBuilder.TimelineFilePath().Name) }; _log.Trace($"watching {timelineWatcher.Path}"); timelineWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.CreationTime | NotifyFilters.LastWrite; timelineWatcher.EnableRaisingEvents = true; timelineWatcher.Changed += new FileSystemEventHandler(OnChanged); _threadJobs = new List <ThreadJob>(); //load into an managing object //which passes the timeline commands to handlers //and creates a thread to execute instructions over that timeline if (this._timeline.Status == Timeline.TimelineStatus.Run) { RunEx(this._timeline); } else { if (MonitorThread != null) { MonitorThread.Abort(); MonitorThread = null; } } } catch (Exception e) { _log.Error($"Orchestrator.Run exception: {e}"); } }