Example #1
0
        static void MainBody()
        {
            int delay = 0;

            while (true)
            {
                Task.Delay(delay).GetAwaiter().GetResult();
                delay = ConfigClass.Interval;
                LogClass.CreateInfoLog("Start cycle");

                List <PechStatus> pechStats = HtmlClass.ParseHtml();
                if (pechStats.Count <= 0)
                {
                    continue;
                }

                pechStats = DatabaseClass.FormatStatus(pechStats);
                if (pechStats.Count <= 0)
                {
                    continue;
                }

                List <PechStatus> lastStats = new List <PechStatus>();
                if (!DatabaseClass.GetLastStatus(out lastStats))
                {
                    continue;
                }

                List <PechStatus> writeNew = new List <PechStatus>();
                List <PechStatus> update   = new List <PechStatus>();
                foreach (var s in pechStats)
                {
                    PechStatus a = lastStats.Find(x => x.Pech == s.Pech);
                    if (a == null || a.Plavka != s.Plavka || a.OperationId != s.OperationId ||
                        a.Start != s.Start)
                    {
                        writeNew.Add(s);
                    }
                    else
                    {
                        s.ProcessId = a.ProcessId;
                        update.Add(s);
                    }
                }
                DatabaseClass.UdateStatus(update);
                DatabaseClass.AddStatus(writeNew);
                if (ConfigClass.SendData)
                {
                    lastStats = new List <PechStatus>();
                    DatabaseClass.GetLastStatus(out lastStats);
                    HtmlClass.SendPechStats(lastStats);
                }
            }
        }
Example #2
0
 static public bool TestConfig()
 {
     LogClass.CreateDebugLog("Test Connect to DB.");
     if (!DatabaseClass.TestDataBase())
     {
         return(false);
     }
     LogClass.CreateDebugLog("Test Connect to parse page.");
     if (!HtmlClass.TestHtml())
     {
         return(false);
     }
     LogClass.CreateInfoLog("Test config: OK");
     return(true);
 }