public static void ShowNextRunDetails(EventSchedule.nextRun nxtRun) { string schMsg = String.Format("Next run in {0} sec. at {1} (schedule: {2})", (Int32)nxtRun.RelTime.TotalSeconds, nxtRun.AbsTime.ToString(), nxtRun.Schedule); fcu.evtLog.WriteEntry(schMsg); total.Logger.Info(schMsg); }
private static void fswEventHandler(Object fswObject, FileSystemEventArgs fswEventArgs) { // ---------------------------------------------------------------------------------------------------------------- // Something happend with a config file (new file, modified, deleted,... you name it) // Disable the FileSystemWatchers and Timer and report the event // ---------------------------------------------------------------------------------------------------------------- SetFileSystemWatchers(false); fcu.fcuTimer.Enabled = false; string fswMessage = String.Format("FSW - File {0} event: {1}", fswEventArgs.ChangeType, fswEventArgs.FullPath); total.Logger.Info(fswMessage); fcu.evtLog.WriteEntry(fswMessage); // ---------------------------------------------------------------------------------------------------------------- // Reload the configuration files. When done re-enable the timer and FileSystemWatchers // ---------------------------------------------------------------------------------------------------------------- fcu.LoadConfiguration(total.APP.Config); SetFileSystemWatchers(true); fcu.fcuTimer.Interval = nxtRun.RelTime.TotalMilliseconds; fcu.fcuTimer.Enabled = true; // ---------------------------------------------------------------------------------------------------------------- // When done show the details for the next scheduled run // ---------------------------------------------------------------------------------------------------------------- nxtRun = fcu.evtSch.GetNextRun(); ShowNextRunDetails(nxtRun); }
private static void tmrEventHandler(Object tmrObject, ElapsedEventArgs tmrEventArgs) { // ---------------------------------------------------------------------------------------------------------------- // A timer elapse event occurred, disable the Timer and all FileSystemWatcher before running the cleanup // Each cleanup schedule can run as a separate task, so more than one cleanup can run simultaneously // ---------------------------------------------------------------------------------------------------------------- Timer fcuTimer = (Timer)tmrObject; fcu.fcuTimer.Enabled = false; SetFileSystemWatchers(false); fcu.ZeroTotalCounters(); foreach (string scheduleName in nxtRun.Schedule.Split(',')) { if (fcu.parallelSchedules) { var t = Task.Run(() => fcu.CleanFileSystem(scheduleName)); } else { fcu.CleanFileSystem(scheduleName); } } // ---------------------------------------------------------------------------------------------------------------- // Get the details for the next scheduled run // ---------------------------------------------------------------------------------------------------------------- nxtRun = fcu.evtSch.GetNextRun(); ShowNextRunDetails(nxtRun); // ---------------------------------------------------------------------------------------------------------------- // When done re-enable the timer and FileSystemWatchers // ---------------------------------------------------------------------------------------------------------------- SetFileSystemWatchers(true); fcu.fcuTimer.Interval = nxtRun.RelTime.TotalMilliseconds; fcu.fcuTimer.Enabled = true; }
// -------------------------------------------------------------------------------------------------------------------- private void resumeWinFCUSercvice() { EventSchedule.nextRun nxtRun = fcu.evtSch.GetNextRun(); fcu.fcuTimer.Interval = nxtRun.RelTime.TotalMilliseconds; fcu.fcuTimer.Enabled = true; WinFCU.SetFileSystemWatchers(true); WinFCU.ShowNextRunDetails(nxtRun); }
public static void runService() { // ================================================================================================================ // Initialize log4net and write a start message to both the eventlog and log4net // ---------------------------------------------------------------------------------------------------------------- total.InitializeLog4Net(); string startMessage = "The WinFCU (" + fcu.fcuVersion + ") service is starting... - Config: " + total.APP.Config; fcu.evtLog.WriteEntry(startMessage); total.Logger.Info(startMessage); // ---------------------------------------------------------------------------------------------------------------- // Load the config file // ---------------------------------------------------------------------------------------------------------------- fcu.LoadConfiguration(total.APP.Config); fcu.evtLog.WriteEntry("The WinFCU service is started...\n" + fcu.GetStatus()); // ---------------------------------------------------------------------------------------------------------------- // Enable FileSystemWatchers for all files in the config folder(s) and core config file(s) // ---------------------------------------------------------------------------------------------------------------- SetFileSystemWatchers(true); // ---------------------------------------------------------------------------------------------------------------- // Now that the configs have been loaded etc we can fetch the next scheduled run time // ---------------------------------------------------------------------------------------------------------------- nxtRun = fcu.evtSch.GetNextRun(); ShowNextRunDetails(nxtRun); // ---------------------------------------------------------------------------------------------------------------- // Set a timer for the requested interval and enable it. Disable repeated events, the timer needs to be set // every time it has elapsed // ---------------------------------------------------------------------------------------------------------------- fcu.fcuTimer = new Timer(nxtRun.RelTime.TotalMilliseconds); fcu.fcuTimer.Elapsed += tmrEventHandler; fcu.fcuTimer.AutoReset = false; fcu.fcuTimer.Enabled = true; // ---------------------------------------------------------------------------------------------------------------- // Run the cleanup for every requested schedule (do not forget the log4net schedule global property!) // ---------------------------------------------------------------------------------------------------------------- }