Beispiel #1
0
        public BadLinksReport(string datakey)
        {
            InitializeComponent();


            lvReport.View          = View.Details; //只有设置为这个HeaderStyle才有用
            lvReport.HeaderStyle   = ColumnHeaderStyle.Nonclickable;
            lvReport.GridLines     = true;         //显示网格线
            lvReport.FullRowSelect = true;         //选择时选择是行,而不是某列
            lvReport.Columns.Add("页面地址", 350, HorizontalAlignment.Center);
            lvReport.Columns.Add("是否死链接", 100, HorizontalAlignment.Center);
            lvReport.Columns.Add("报告结果", 300, HorizontalAlignment.Left);

            model        = BLL.BadLink.Instance.GetEntity(new Guid(datakey));//BLL.BadLink.Instance.GetOne(datakey);
            txtInfo.Text = string.Format("检测地址:{0},找到死链接{1}个,最后检测时间{2}", model.PUrl, model.BadLinkCount, model.LastTestDate);
            BindData();
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="badnum"></param>
        /// <param name="currentnum">当前任务错误数,</param>
        /// <param name="countnum">当前任务要检查的链接数</param>
        /// <param name="key"></param>
        /// <param name="iscomp">是否完成</param>
        private void MtUpdateCheckState(int badnum, int currentnum, int countnum, string key, bool iscomp, int status, string info)
        {
            if (!iscomp)
            {
                foreach (ListViewItem lvi in lv404links.Items)
                {
                    if (lvi.SubItems[0].Text.Equals(string.Concat("--", key)))
                    {
                        lvi.SubItems[2].Text = badnum.ToString();
                        lvi.SubItems[3].Text = "完成";
                        lvi.SubItems[4].Text = DateTime.Now.ToString();
                        lvi.SubItems[5].Text = string.Format("Http返回状态:{0} {1}", status, info);//返回状态
                        break;
                    }
                }
            }
            else
            {
                List <BadLinkReport> lstBadLinkReport = new List <BadLinkReport>();
                lstBadLinkReport.Clear();//清空之前的报表记录

                string datakey = string.Empty;
                //int reportcountnum = 0;
                string        reportinfo      = string.Empty;
                int           reportbadnum    = 0;
                StringBuilder sbBadReportInfo = new StringBuilder();
                foreach (ListViewItem lvi in lv404links.Items)
                {
                    if (lvi.SubItems[0].Text.StartsWith("--"))  //更新报表明细
                    {
                        lvi.Remove();
                        BadLinkReport md          = new BadLinkReport();
                        string        sHttpStatus = lvi.SubItems[5].Text;
                        md.PUrl = string.Format("{0} {1}", lvi.SubItems[0].Text, sHttpStatus);
                        md.IsOK = (lvi.SubItems[2].Text == "0");

                        md.Info = sHttpStatus;

                        lstBadLinkReport.Add(md);
                        if (!md.IsOK)
                        {
                            sbBadReportInfo.AppendFormat("失败网址:{0},请求{1};", md.PUrl, sHttpStatus);
                        }
                    }
                    else if (lvi.SubItems[0].Text.Equals(key)) //更新任务报表
                    {
                        //reportcountnum = countnum;
                        reportbadnum         = badnum;
                        reportinfo           = string.Format("完成,总共处理地址{0}条,找到死链接{1}条", countnum, badnum);
                        lvi.SubItems[5].Text = reportinfo;
                        lvi.SubItems[3].Text = "空闲";
                        lvi.BackColor        = Color.White;
                        datakey = lvi.SubItems[6].Text;
                    }
                }
                //更新到报告列表
                if (!string.IsNullOrEmpty(datakey) && lstBadLinkReport.Count > 0)
                {
                    Entity.BadLink md = BLL.BadLink.Instance.GetEntity(new Guid(datakey));//BLL.BadLink.Instance.GetOne(datakey);
                    md.Reports      = lstBadLinkReport;
                    md.LastTestDate = DateTime.Now;
                    md.BadLinkCount = reportbadnum;
                    BLL.BadLink.Instance.UpdateOne(md);
                }
                //添加到邮件列表
                if (reportbadnum > 0)
                {
                    BLL.EmailQueue.Instance.AddEmailToDB(reportinfo, string.Format("{0},检测时间:{1},检测页面:{2},详细情况:{3}", reportinfo, DateTime.Now, key, sbBadReportInfo));
                }

                if (BadLinkQue.ContainsKey(CurrentBadLink))
                {
                    BadLinkQue.Remove(CurrentBadLink);
                }
                CurrentBadLink = string.Empty;

                if (BadLinkQue.Count > 0)
                {
                    UpdateBadLinkLvItem(null, BadLinkQue.Values.ElementAt(0));
                }
            }
        }