/// <summary> /// Reloads all the MonitorConfig items for each monitor running on the current service host. /// </summary> public void RefreshConfig() { TraceFactory.Logger.Debug("Request received to refresh config."); List <MonitorConfig> currentConfiguration = null; using (AssetInventoryContext context = DbConnect.AssetInventoryContext()) { currentConfiguration = context.MonitorConfigs.Where(n => n.ServerHostName == Environment.MachineName).ToList(); } lock (_monitors) { RemoveStaleMonitors(new HashSet <Guid>(currentConfiguration.Select(c => c.MonitorConfigId))); } foreach (MonitorConfig config in currentConfiguration) { StfMonitor monitor = _monitors.Where(m => m.MonitorId == config.MonitorConfigId).FirstOrDefault(); if (monitor != null) { // Found existing monitor monitor.RefreshConfig(config); } else { //Monitor exists in the database config, but is not running on the current service host. CreateMonitor(config); } } TraceFactory.Logger.Debug("Config refreshed."); }
private void CreateMonitor(MonitorConfig monitorConfig) { STFMonitorType monitorType = EnumUtil.Parse <STFMonitorType>(monitorConfig.MonitorType); StfMonitor monitor = null; switch (monitorType) { case STFMonitorType.OutputEmail: monitor = new OutputEmailMonitor(monitorConfig); break; case STFMonitorType.OutputDirectory: monitor = new OutputDirectoryMonitor(monitorConfig); break; case STFMonitorType.SharePoint: monitor = new SharePointMonitor(monitorConfig); break; case STFMonitorType.LANFax: monitor = new LANFaxMonitor(monitorConfig); break; case STFMonitorType.DigitalSendNotification: monitor = new DigitalSendNotificationMonitor(monitorConfig); break; case STFMonitorType.Directory: monitor = new DirectoryMonitor(monitorConfig); break; case STFMonitorType.AutoStore: monitor = new AutoStoreMonitor(monitorConfig); break; case STFMonitorType.DSSServer: monitor = new DigitalSendDatabaseMonitor(monitorConfig); break; case STFMonitorType.Hpcr: monitor = new HpcrDatabaseMonitor(monitorConfig); break; case STFMonitorType.EPrint: monitor = new EPrintJobMonitorService(monitorConfig); break; default: TraceFactory.Logger.Debug($"Unknown monitor type: {monitorConfig.MonitorType}"); return; } monitor.RegisteredSessions = _registeredSessions; _monitors.Add(monitor); TraceFactory.Logger.Debug($"Added monitor for '{monitor.MonitorLocation}'."); }
private static void StartMonitor(object state) { StfMonitor monitor = (StfMonitor)state; try { monitor.StartMonitoring(); } catch (Exception ex) { // If something goes wrong, log the error info, but allow other monitors continue to start. TraceFactory.Logger.Debug($"{monitor.ToString()} failed to start."); TraceFactory.Logger.Debug(ex.ToString()); } }