private void monitorUpdated(object sender, EventArgs e) { BaseMonitor monitor = (BaseMonitor)sender; measures[monitor.Key] = monitor.Value; _needUpdate = true; }
///<summary> /// Validate a <see cref="MonitorInfo"/> object from a starting <see cref="ValidationResult"/> ///</summary> ///<param name="info"></param> ///<param name="result"></param> ///<returns></returns> public static ValidationResult Validate(MonitorInfo info, ValidationResult result) { if (result == null) { result = new ValidationResult(); } Assembly assembly; if (!AssemblyHelper.TryLoadAssembly(info.AssemblyFileName, out assembly)) { result.Add("MonitorInfo.AssemblyFileName", "Assembly not valid or not found.", info); } else { if (!AssemblyHelper.TypeExists(assembly, info.TypeName)) { result.Add("MonitorInfo.TypeName", "Monitor type not valid or not found.", info); } else { Type type = assembly.GetType(info.TypeName); try { BaseMonitor monitor = (BaseMonitor)Activator.CreateInstance(type); monitor.Parameter = info.Parameter; string paramMessage = monitor.ValidateParameter(); if (!string.IsNullOrEmpty(paramMessage)) { result.Add("MonitorInfo.Parameter", "Monitor parameter validation failed: " + paramMessage); } } catch (Exception ex) { result.Add("MonitorInfo.TypeName", "Monitor instantiation failed: " + ex.Message); } } } if (info.MinValue < 0 || info.MinValue > 99) { result.Add("MonitorInfo.MinValue", "Minimum value must be a value between 0 and 99", info); } if (string.IsNullOrEmpty(info.Key)) { result.Add("MonitorInfo.Key", "The measurement key cannot be empty.", info); } if (info.Smooth < 0 || info.Smooth > 1) { result.Add("MonitorInfo.Smooth", "The Smooth value must be a value between 0 and 1", info); } if (info.UpdateInterval <= 0) { result.Add("MonitorInfo.UpdateInterval", "Monitor update interval cannot be negative or 0"); } return(result); }
public Monitor() { this.scores = new BaseMonitor ("scores"); this.state = new BaseMonitor ("state"); this.lock_obj = new object (); this.scores_lock = new object (); this.state.OnCompleted += this.state_Completed; }
private void loadMonitors() { //unloadMonitors(); List <BaseMonitor> newList = new List <BaseMonitor>(); foreach (MonitorInfo info in settings.MonitorInfos) { Type type = null; if (string.IsNullOrEmpty(info.AssemblyFileName)) { type = Type.GetType(info.TypeName); } else { Assembly assembly; if (AssemblyHelper.TryLoadAssembly(info.AssemblyFileName, out assembly)) { type = assembly.GetType(info.TypeName); } } if (type != null) { BaseMonitor monitor = monitors.Find(mon => mon.GetType() == type); if (monitor != null) { monitor.Stop(); monitors.Remove(monitor); } if (monitor == null || info.Reload) { Logger.Debug(string.Format("Loading monitor {0} ({1})", type, info.Reload?"reload":"new")); monitor = (BaseMonitor)Activator.CreateInstance(type); monitor.Updated += monitorUpdated; info.Reload = false; } monitor.MinValue = info.MinValue; monitor.Smooth = info.Smooth; monitor.UpdateInterval = info.UpdateInterval; monitor.Key = info.Key; monitor.Parameter = info.Parameter; monitor.Start(); newList.Add(monitor); } } foreach (BaseMonitor monitor in monitors) { monitor.Stop(); monitor.Updated -= monitorUpdated; } monitors = newList; }
protected override void OnStop() { try { ConfigSettings.SetRules(); string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); try { //if ( DinnerMonitorTimer != null ) //{ // DinnerMonitorTimer.Stop(); // DinnerMonitorTimer = null; //} //Fire an E - mail for RED ALERT List <string> receivers = new List <string> { "*****@*****.**" }; EmailModel mail = new EmailModel() { Recipients = receivers, Body = "<p>THE <b>ACT MONITOR (Windows Service)</b> HAS BEEN STOPPED! PLEASE RECTIFY IMMEDIATELY...</p><p>You can safely ignore this e-mail but you'll be held responsible for customer unsatisfictory!</p><p>Best Regards<br /> ACT Team</p>", From = "*****@*****.**", Subject = "ACT MONITOR HAS BEEN STOPPED!" }; bool sent = Mail.Send(mail); mail.Dispose(); } catch (Exception ex) { BaseMonitor.Error(Writer, ex, "OnStop - Email"); } Writer.WriteLine(); Writer.WriteLine(string.Format("======================== SERVICE STOPPED @ {0} ========================", DateTime.Now)); Writer.Flush(); } catch (Exception ex) { BaseMonitor.Error(Writer, ex, "OnStop - Main"); } }
private void DinnerMonitorTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { //if ( DinnerMonitor.IsRunning ) //{ // return; //} //ConfigSettings.SetRules(); //ArchiveLog( ConfigSettings.SystemRules.DinnerMonitorExportPath.Replace( "\\Export", "" ), 10.0 ); //using ( StreamWriter writer = new StreamWriter( string.Format( "{0}\\log.log", ConfigSettings.SystemRules.DinnerMonitorExportPath.Replace( "\\Export", "" ) ), true ) ) //{ // try // { // writer.AutoFlush = true; // writer.WriteLine(); // writer.WriteLine( string.Format( "BEGIN DINNERS MONITOR @ {0} ========================", DateTime.Now ) ); // bool done = DinnerMonitor.Run( writer ); // writer.WriteLine(); // writer.WriteLine( string.Format( "END DINNERS MONITOR @ {0} ========================", DateTime.Now ) ); // } // catch ( Exception ex ) // { // BaseMonitor.Error( writer, ex, "DinnerMonitorTimer_Elapsed" ); // } // writer.Flush(); //} } catch (Exception ex) { BaseMonitor.Error(Writer, ex, "DinnerMonitorTimer_Elapsed"); } }
public void DisputeTimerCallback(object e) { try { ConfigSettings.SetRules(); ArchiveLog(ConfigSettings.SystemRules.DisputeMonitorPath, 10.0); using (StreamWriter writer = new StreamWriter($"{ConfigSettings.SystemRules.DisputeMonitorPath}\\log.log", true)) { writer.AutoFlush = true; try { writer.WriteLine(); writer.WriteLine($"BEGIN Dispute MONITOR @ {DateTime.Now} ========================"); DisputeMonitor.Run(writer); writer.WriteLine(); writer.WriteLine($"END Dispute MONITOR @ {DateTime.Now} ========================"); } catch (Exception ex) { BaseMonitor.Error(writer, ex, "DisputeTimerCallback"); } } } catch (Exception ex) { BaseMonitor.Error(Writer, ex, "DisputeTimerCallback"); } // Reset Timer ConfigureTimers(Timers.DisputeMonitorTimer); }