Exemplo n.º 1
0
        private void MtUpdateSiteState(WatchTimerEventArgs arg)
        {
            string url    = arg.Url;
            Thread thread = new Thread(() =>
            {
                string reportinfo = "";
                int rel           = ValidateUrl(url, out reportinfo);
                if (rel != 1)
                {
                    DateTime dt = DateTime.Now;

                    bool isAddToMobileMsg = (rel != 4 || rel != 5);//4的时候会误报,只email报告


                    foreach (ListViewItem lvi in lvErrSiteList.Items)
                    {
                        if (lvi.SubItems[2].Text.Equals(url))
                        {
                            int errorNum         = Convert.ToInt32(lvi.SubItems[4].Text);
                            int reportNum        = Convert.ToInt32(lvi.SubItems[4].Text);
                            lvi.SubItems[4].Text = (errorNum + 1).ToString();
                            lvi.SubItems[5].Text = (reportNum + 1).ToString();
                            lvi.SubItems[6].Text = dt.ToString();
                        }
                    }

                    BLL.EmailQueue.Instance.AddEmailToDB(string.Concat(reportinfo, dt), string.Format("{0},检测时间:{1},检测页面:{2}", reportinfo, dt, url), isAddToMobileMsg);
                }
            });

            thread.Start();
        }
Exemplo n.º 2
0
        private void UpdateFriendLinkLvItem(object sender, WatchTimerEventArgs arg)
        {
            string sUrl = arg.Url;

            Entity.FriendLink model = BLL.FriendLink.Instance.GetEntity(new Guid(arg.Id));

            try
            {
                string[] sNoCheckUrls       = model.GetNoCheckUrls();
                List <FriendLinkModel> urls = BLL.FriendLink.Instance.GetFriendLinks(sUrl);

                List <string> urltemp = new List <string>();

                foreach (var url2 in model.Reports)
                {
                    urltemp.Add(url2.PUrl);
                }

                foreach (var s in urls)
                {
                    if (!urltemp.Contains(s.LinkUrl))
                    {
                        FriendLinkReport rp = new FriendLinkReport();
                        rp.PUrl       = s.LinkUrl;
                        rp.IsOK       = true;
                        rp.IsNewAdd   = true;
                        rp.Info       = "等待检测";
                        rp.LinkToText = s.LinkText;

                        if (!Equals(sNoCheckUrls, null) && sNoCheckUrls.Contains(rp.PUrl))
                        {
                            rp.Info           = "忽略站点不做检测";
                            rp.IsNoToCheckUrl = true;
                        }

                        model.Reports.Add(rp);
                    }
                }
                BLL.FriendLink.Instance.UpdateOne(model);
                CheckFriedLink(model);
            }
            catch (Exception e)
            {
                if (!Equals(model, null))
                {
                    model.IsHaveBad = true;
                    BLL.FriendLink.Instance.UpdateOne(model);
                }
                else
                {
                    XS.Core.Log.ErrorLog.InfoFormat("更新{0}出错,model为null,具体原因:{1}", sUrl, e.Message);
                }
            }
            //重新绑定数据
            BindWebLink();
        }
Exemplo n.º 3
0
        private void UpdateLinkLvItem(object sender, WatchTimerEventArgs arg)
        {
            foreach (ListViewItem lvi in lvPageUpdate.Items)
            {
                if (lvi.SubItems[0].Text.Equals(arg.Url))
                {
                    string lastmd5    = lvi.SubItems[5].Text;
                    string currentmd5 = "";
                    string content    = "";
                    try
                    {
                        content = XS.Core.WebUtils.GetHtml(arg.Url);
                    }
                    catch (Exception e)
                    {
                        XS.Core.Log.ErrorLog.ErrorFormat("检查页面是否更新时,获取页面内容发生错误,页面:{0},错误:{1}", arg.Url, e.Message);

                        BLL.EmailQueue.Instance.AddEmailToDB("检查页面是否更新时,获取页面内容发生错误", string.Format("检查页面是否更新时,获取页面内容发生错误,页面:{0},错误:{1}", arg.Url, e.Message));
                    }


                    if (!string.IsNullOrEmpty(content))
                    {
                        currentmd5 = Utils.MD5(content);
                    }
                    else
                    {
                        lvi.SubItems[4].Text = "获取页面发生异常,请查看日志";
                        return;
                    }
                    lvi.SubItems[3].Text = DateTime.Now.ToString();
                    if (!string.IsNullOrEmpty(lastmd5))
                    {
                        if (lastmd5.Equals(currentmd5))
                        {
                            lvi.SubItems[4].Text = "未更新";
                            BLL.EmailQueue.Instance.AddEmailToDB(string.Concat("发现有一个页面未能按时更新", DateTime.Now), string.Format("发现有一个页面未能按时更新,时间:{0},发现页面:{1}", DateTime.Now, arg.Url));
                        }
                        else
                        {
                            lvi.SubItems[4].Text = "正常更新";
                        }
                    }
                    else
                    {
                        lvi.SubItems[4].Text = "第一次检查";
                    }

                    lvi.SubItems[5].Text = currentmd5;
                }
            }
        }
Exemplo n.º 4
0
        //private void btnAddBadTime_Click(object sender, EventArgs e)
        //{

        //}

        //private void lv404links_ItemChecked(object sender, ItemCheckedEventArgs e)
        //{
        //    ListViewItem lvi = lv404links.SelectedItems[0];

        //    string sUrl = lvi.SubItems[0].Text;

        //    MessageBox.Show(sUrl);
        //}

        private void 立即检查ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListViewItem lvi = lv404links.SelectedItems[0];

            string sUrl = lvi.SubItems[0].Text;

            WatchTimerEventArgs Args = new WatchTimerEventArgs();

            Args.Url        = sUrl;
            Args.UpdateTime = DateTime.Now;
            //Args.ReportMsg = "汇报情况";
            if (!Equals(thThreadCheckLink, null))
            {
                thThreadCheckLink.Abort();
            }

            CurrentBadLink = "";

            foreach (ListViewItem lviSub in lv404links.Items)
            {
                if (lviSub.SubItems[0].Text.StartsWith("--"))
                {
                    lviSub.Remove();
                }
            }

            foreach (ListViewItem lviItem in lv404links.Items)
            {
                if (!lviItem.SubItems[0].Text.Equals(sUrl))
                {
                    lviItem.SubItems[3].Text = "排队中";
                    lviItem.BackColor        = Color.Yellow;
                }
            }

            UpdateBadLinkLvItem(null, Args);
        }
Exemplo n.º 5
0
        private void UpdateErrorSiteLvItem(object sender, WatchTimerEventArgs arg)
        {
            UpdateSiteState updateSiteState = new UpdateSiteState(MtUpdateSiteState);

            lvErrSiteList.Invoke(updateSiteState, arg);
        }
Exemplo n.º 6
0
        private void UpdateBadLinkLvItem(object sender, WatchTimerEventArgs arg)
        {
            if (!string.IsNullOrEmpty(CurrentBadLink)) //如果当前有执行任务,请记录到队列
            {
                if (!CurrentBadLink.Equals(arg.Url))
                {
                    if (!BadLinkQue.ContainsKey(arg.Url))
                    {
                        BadLinkQue.Add(arg.Url, arg);
                        foreach (ListViewItem lvi in lv404links.Items)
                        {
                            if (lvi.SubItems[0].Text.Equals(arg.Url))
                            {
                                lvi.SubItems[3].Text = "排队中";
                                lvi.BackColor        = Color.Yellow;
                                break;
                            }
                        }
                    }
                }

                return;
            }
            else
            {
                //BadLinkQue.Clear();
                //BadLinkQue.Add(arg.Url, arg);
            }

            foreach (ListViewItem lvi in lv404links.Items)
            {
                if (lvi.SubItems[0].Text.Equals(arg.Url))//&& lvi.SubItems[3].Text.Equals("空闲")
                {
                    lvi.SubItems[4].Text = arg.UpdateTime.ToString();
                    string Content = "";
                    try
                    {
                        Content = LoadPageContent(arg.Url);
                    }
                    catch (Exception e)
                    {
                        BLL.EmailQueue.Instance.AddEmailToDB("发生严重的问题,页面不能访问", string.Format("检查死链模板页面不能访问:{0},检测时间:{1},详细情况:{2}", arg.Url, DateTime.Now, e.Message));
                        continue;
                    }

                    Regex           reg     = new Regex(@"(?is)<a[^>]*?href=(['""]?)(?<url>[^'""\s>]+)\1[^>]*>(?<text>(?:(?!</?a\b).)*)</a>");
                    MatchCollection mc      = reg.Matches(Content);
                    Uri             baseUri = new Uri(arg.Url);
                    List <string>   urls    = new List <string>();

                    foreach (Match m in mc)
                    {
                        Uri uriPage = new Uri(baseUri, m.Groups["url"].Value);

                        string sUrl = uriPage.ToString();
                        //sUrl = XS.Core.WebUtils.UrlEncode(sUrl);
                        urls.Add(sUrl);
                    }

                    List <string> NUrls = (from i in urls select i).Distinct().ToList();

                    if (NUrls.Count > 0)
                    {
                        lvi.SubItems[5].Text = string.Format("找到{0}个网址,正在检查...", NUrls.Count);
                        lvi.SubItems[3].Text = "忙碌中";
                        lvi.BackColor        = Color.Red;
                        CurrentBadLink       = arg.Url;

                        foreach (string url in NUrls)  //载入所有要检查的地址
                        {
                            ListViewItem lvisub = new ListViewItem();
                            lvisub.BackColor        = Color.PowderBlue;
                            lvisub.SubItems[0].Text = string.Concat("--", url);
                            lvisub.SubItems.Add("");
                            lvisub.SubItems.Add("");
                            lvisub.SubItems.Add("等待中");
                            lvisub.SubItems.Add("");
                            lvisub.SubItems.Add("");
                            lv404links.Items.Add(lvisub);
                        }



                        thThreadCheckLink = new Thread(() =>
                        {
                            UpdateCheckState dlgUpdateCheckState = new UpdateCheckState(MtUpdateCheckState);
                            int badnum     = 0;
                            int currentnum = 0;
                            int countnum   = NUrls.Count;
                            foreach (string surl in NUrls)
                            {
                                //Thread.Sleep(1000);
                                currentnum++;
                                bool IsBadLink = false;
                                string url     = surl.Trim();
                                int istate     = 0;
                                string errinfo = string.Empty;
                                if (IsToCheck(url))
                                {
                                    istate = WebUtils.ValidateUrl(url, out errinfo);
                                    if (istate != 200)
                                    {
                                        badnum++;
                                        IsBadLink = true;
                                    }
                                }


                                lv404links.Invoke(dlgUpdateCheckState, IsBadLink ? 1 : 0, currentnum, countnum, url, false, istate, errinfo);
                            }

                            lv404links.Invoke(dlgUpdateCheckState, badnum, currentnum, countnum, arg.Url, true, 0, "");
                        });
                        thThreadCheckLink.ApartmentState = ApartmentState.STA;
                        thThreadCheckLink.Start();
                    }
                }
            }
        }