Ejemplo n.º 1
0
        private async Task SendAlert(MonitoredHistoryItem item)
        {
            MonitoredItem monitoredItem = await _context.MonitoredItems.Include(a => a.User).FirstOrDefaultAsync(a => a.MonitItemId == item.MonitoredItemId);

            User user = await _context.Users.FindAsync(monitoredItem.User.Id);

            MailSender sender = new MailSender(_mailSettings);
            await sender.sendAllert(user.EMail, monitoredItem.Url);
        }
Ejemplo n.º 2
0
        private MonitoredHistoryItem CompareWebPages()
        {
            if (_item.ElementName == "")
            {
                MonitoredHistoryItem historyItem   = new MonitoredHistoryItem(_item.MonitItemId, _oldWebPage, _newWebPage);
                HTMLCompareResult    compareResult = HTMLMenager.HTMLDocumentCompare(_oldWebPage, _newWebPage);

                if (compareResult.Type == 1)
                {
                    historyItem.SetTypeError(compareResult.Message);
                }
                ;
                if (compareResult.Type == 2)
                {
                    historyItem.SetTypeError(compareResult.Message);
                    _oldWebPage = _newWebPage;
                }
                ;
                if (compareResult.Type == 3)
                {
                    historyItem.SetTypeNothingChanges(compareResult.Message);
                }
                ;
                return(historyItem);
            }
            else
            {
                _newNode = _newWebPage.GetElementbyId(_item.ElementName);
                MonitoredHistoryItem historyItem   = new MonitoredHistoryItem(_item.MonitItemId, _oldNode, _newNode);
                HTMLCompareResult    compareResult = HTMLMenager.HTMLNodeCompare(_oldNode, _newNode);

                if (compareResult.Type == 1)
                {
                    historyItem.SetTypeError(compareResult.Message);
                }
                ;
                if (compareResult.Type == 2)
                {
                    historyItem.SetTypeError(compareResult.Message);
                    _oldNode = _newNode;
                }
                ;
                if (compareResult.Type == 3)
                {
                    historyItem.SetTypeNothingChanges(compareResult.Message);
                }
                ;
                return(historyItem);
            }
        }
Ejemplo n.º 3
0
        private async void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            _timer.Stop();
            _newWebPage = new HtmlDocument();
            _newWebPage.LoadHtml(HTMLMenager.GetHtmlPage(_item.Url));
            MonitoredHistoryItem historyItem = CompareWebPages();

            await SaveToDatabase(historyItem);

            if (historyItem.Type == 2)
            {
                await SendAlert(historyItem);
            }
            _timer.Start();
        }
Ejemplo n.º 4
0
 private bool PrepareDetection()
 {
     _oldWebPage = new HtmlDocument();
     _oldWebPage.LoadHtml(HTMLMenager.GetHtmlPage(_item.Url));
     if (_item.ElementName != "")
     {
         _oldNode = _oldWebPage.GetElementbyId(_item.ElementName);
         if (_oldNode == null)
         {
             MonitoredHistoryItem historyitem = new MonitoredHistoryItem(_item.MonitItemId);
             historyitem.SetTypeError("Cant find element on website ");
             SaveToDatabase(historyitem);
             // HistoryChange(this, myArg);
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 5
0
        private async Task SaveToDatabase(MonitoredHistoryItem item)
        {
            await _context.MonitoredHistory.AddAsync(item);

            await _context.SaveChangesAsync();
        }