Esempio n. 1
0
        private async Task <string> parsePage(Site site, Page page)
        {
            try
            {
                var pageMonitor = new Metis.Guard.PageMonitor();
                var content     = await pageMonitor.ParsePage(site, page);

                return(content);
            }
            catch (System.Net.Http.HttpRequestException exception)
            {
                site.Status = Status.Alarm;
                page.Status = Status.NotFound;
                await siteException(site, page, exception);

                return(string.Empty);
            }
            catch (Exception exception)
            {
                site.Status = Status.Alarm;
                page.Status = Status.Alarm;
                await siteException(site, page, exception);

                return(string.Empty);
            }
        }
Esempio n. 2
0
        private async Task monitor(Site site, Page page)
        {
            var encoding    = Encoding.GetEncoding(site.EncodingCode);
            var pageMonitor = new Metis.Guard.PageMonitor();
            var content     = await pageMonitor.ParsePage(site, page);

            if (string.IsNullOrEmpty(content))
            {
                return;
            }

            var md5 = Metis.Guard.Utilities.CreateMD5(content, encoding);

            //if it is a new page
            if (string.IsNullOrEmpty(page.MD5Hash))
            {
                //initialize the md5 hash of the content to the current one
                page.MD5Hash = md5;
                page.Status  = Status.Ok;
                await updateSitePage(_siteId, page);
            }
            else if (string.Equals(page.MD5Hash, md5))
            {
                if (page.Status != Status.Ok)
                {
                    page.Status = Status.Ok;
                    await updateSitePage(_siteId, page);
                }
            }
            else
            {
                if (page.Status != Status.Alarm)
                {
                    page.Status = Status.Alarm;
                    await updateSitePage(_siteId, page);
                }
            }

            await updateSitePageContent(site, page, content);

            Console.WriteLine($"Page {page.Uri} status is {page.Status}");
        }