private static void OnConfigFileChanged(object obj) { if (ServerConnectionSettings.s_Monitor != null && ServerConnectionSettings.s_Monitor.HasChanged) { if (ServerConnectionSettings.LoadConfigSettings(ServerConnectionSettings.s_DefaultConfigurationFile)) { try { EventHandler configFileChanged = ServerConnectionSettings.ConfigFileChanged; if (configFileChanged != null) { configFileChanged((object)null, EventArgs.Empty); } } catch (Exception ex) { string message = string.Format("Error notifying for file changes\r\n{0}", (object)ex.ToString()); Trace.TraceWarning(message); if (ServerConnectionSettings.s_EventLog != null) { ServerConnectionSettings.s_EventLog.WriteEntry(message, EventLogEntryType.Warning); } } } } ServerConnectionSettings.s_Monitor = (HostFileChangeMonitor)null; try { ServerConnectionSettings.s_Monitor = new HostFileChangeMonitor((IList <string>) new List <string>() { ServerConnectionSettings.s_DefaultConfigurationFile }); ServerConnectionSettings.s_Monitor.NotifyOnChanged(new OnChangedCallback(ServerConnectionSettings.OnConfigFileChanged)); } catch (Exception ex) { string message = string.Format("Error establishing change notifications\r\n{0}", (object)ex.ToString()); Trace.TraceWarning(message); if (ServerConnectionSettings.s_EventLog == null) { return; } ServerConnectionSettings.s_EventLog.WriteEntry(message, EventLogEntryType.Warning); } }
static ServerConnectionSettings() { try { if (!EventLog.SourceExists("InSite Server Connection Library")) { EventLog.CreateEventSource("InSite Server Connection Library", "Camstar"); } ServerConnectionSettings.s_EventLog = new EventLog("Camstar"); ServerConnectionSettings.s_EventLog.Source = "InSite Server Connection Library"; } catch (Exception ex) { Trace.TraceError(string.Format("Error creating/modifying the event log.\r\n{0}", (object)ex.ToString())); EventLog eventLog = ServerConnectionSettings.s_EventLog; } try { RegistryKey localMachine = Registry.LocalMachine; RegistryKey registryKey1 = localMachine.OpenSubKey("SOFTWARE\\Camstar\\Camstar InSite Server Connection", false); if (registryKey1 != null) { ServerConnectionSettings.s_DefaultConfigurationFile = (string)registryKey1.GetValue("ConfigPath"); } if (string.IsNullOrEmpty(ServerConnectionSettings.s_DefaultConfigurationFile)) { RegistryKey registryKey2 = localMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Camstar\\Camstar InSite Server Connection", false); if (registryKey2 != null) { ServerConnectionSettings.s_DefaultConfigurationFile = (string)registryKey2.GetValue("ConfigPath"); } } } catch (Exception ex1) { try { string message = string.Format("Getting config file name from the registry\r\n{0}", (object)ex1.ToString()); Trace.TraceWarning(message); if (ServerConnectionSettings.s_EventLog != null) { ServerConnectionSettings.s_EventLog.WriteEntry(message, EventLogEntryType.Warning); } } catch (Exception ex2) { Trace.TraceError(string.Format("Error writing to the event log. \r\n{0}", (object)ex2.ToString())); } } ServerConnectionSettings.LoadConfigSettings(ServerConnectionSettings.s_DefaultConfigurationFile); try { ServerConnectionSettings.s_Monitor = new HostFileChangeMonitor((IList <string>) new List <string>() { ServerConnectionSettings.s_DefaultConfigurationFile }); ServerConnectionSettings.s_Monitor.NotifyOnChanged(new OnChangedCallback(ServerConnectionSettings.OnConfigFileChanged)); } catch (Exception ex) { string message = string.Format("Error establishing change notifications\r\n{0}", (object)ex.ToString()); Trace.TraceWarning(message); if (ServerConnectionSettings.s_EventLog == null) { return; } ServerConnectionSettings.s_EventLog.WriteEntry(message, EventLogEntryType.Warning); } }