Ejemplo n.º 1
0
 /// <summary>
 /// UpdateThreadsSitesDict method updates the data in the dictionary of key (site) - value pairs (separate thread).
 /// </summary>
 /// <param name="threadsSitesDict"> Dictionary of key (site) - value (separate thread). </param>
 private void UpdateThreadsSitesDict(Dictionary <string, Thread> threadsSitesDict)
 {
     if (ListWebSiteSettings.Count > threadsSitesDict.Count)
     {
         foreach (var webSite in ListWebSiteSettings)
         {
             if (!threadsSitesDict.ContainsKey(webSite.UrlSiteForCheck))
             {
                 threadsSitesDict[webSite.UrlSiteForCheck] = null;
             }
         }
     }
     if (ListWebSiteSettings.Count < threadsSitesDict.Count)
     {
         SettingsWebSiteMonitoring.SettingsWebSiteMonitoring result = null;
         List <string> keys = new List <string>(threadsSitesDict.Keys);
         foreach (var webSite in keys)
         {
             result = ListWebSiteSettings.Find((_webSite) => _webSite.UrlSiteForCheck == webSite);
             if (result == null)
             {
                 threadsSitesDict.Remove(webSite);
             }
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// ParseConfig method reads information about the sites that need to be checked from the json file.
 /// </summary>
 /// <param name="path"> Path to json file. </param>
 private void ParseConfig(string path)
 {
     using (StreamReader sr = new StreamReader(path))
     {
         string jsonString = File.ReadAllText(path);
         ReflectionJsonSettingsSiteMonitoring WebSites = JsonConvert.DeserializeObject <ReflectionJsonSettingsSiteMonitoring>(jsonString);
         for (int i = 0; i < WebSites._WebsiteMonitoringSettings.Length; i++)
         {
             ListWebSiteSettings.Add(new SettingsWebSiteMonitoring.SettingsWebSiteMonitoring(WebSites._WebsiteMonitoringSettings[i].IntervalBetweenChecksSeconds, WebSites._WebsiteMonitoringSettings[i].MaxExpectedServerResponseTimeSeconds,
                                                                                             WebSites._WebsiteMonitoringSettings[i].UrlSiteForCheck, WebSites._WebsiteMonitoringSettings[i].DataAdministrator));
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// ParseChangedConfig method reads information about checked sites from json after changing json file.
        /// </summary>
        private void ParseChangedConfig()
        {
            bool configIsAvailable = false;

            while (!configIsAvailable)
            {
                try
                {
                    ListWebSiteSettings.Clear();
                    ParseConfig(JsonPath);
                    configIsAvailable = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }