private void LoadConfig() { string path = System.Reflection.Assembly.GetExecutingAssembly().Location.ToLowerInvariant(); Configuration cfg = ConfigurationManager.OpenExeConfiguration(path); if (cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.NagiosServiceStartPause)) { if (int.TryParse(cfg.AppSettings.Settings[ConfigConstants.NagiosServiceStartPause].Value, out _startPause) == false) { _startPause = 60; } } try { if (cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.Services)) { WinServices s = WinServices.Load(cfg.AppSettings.Settings[ConfigConstants.Services].Value); _services.Clear(); s.Services.ForEach(x => { _services.Add(new CheckingService { LastChecked = DateTime.Now.AddSeconds(_startPause), Service = x }); }); } } catch (Exception ex) { Log.WriteLog(string.Format("{0}\n{1}", ex.Message, ex.StackTrace), true); } }
protected static WinServices Deserialize(string data) { WinServices o = null; MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(data)); try { DataContractJsonSerializer ser = GetSerializer(); o = ser.ReadObject(ms) as WinServices; } catch (Exception e) { throw new PerfCountersLoadException(string.Format("Error thrown then read WinServices settings: {0}", e.Message)); } finally { ms.Close(); } return(o); }