Beispiel #1
0
 // 开始扫描列表页中内容
 private void StartSingleScan(BaseRule rule)
 {
     rule.SiteScanBegin += ShowBeginScan;
     rule.PageScanComplete += ShowProcess;
     rule.SiteScanComplete += ShowCompleteInfo;
     rule.PrepareScan();
 }
Beispiel #2
0
 // 显示扫描的进度
 private void ShowProcess(object sender, BaseRule.ScanCompleteEventArgs e)
 {
     if (this.InvokeRequired)
     {
         this.BeginInvoke(new BaseRule.PageScanCompleteEventHandler(ShowProcess), new object[] { null, e });
     }
     else
     {
         int process = int.Parse(beiProcess.EditValue.ToString());
         beiProcess.EditValue = (++process);
         beiStatus.Caption = string.Format(@"[{2}]正在扫描...,一共{0}页, {1}页已扫描.", e.web.MaxPage, process, e.web.Name);
     }
 }
Beispiel #3
0
 // 扫描完成后的显示处理
 private void ShowCompleteInfo(object sender, BaseRule.ScanCompleteEventArgs e)
 {
     if (this.InvokeRequired)
     {
         this.BeginInvoke(new BaseRule.SiteScanCompleteEventHandle(ShowCompleteInfo), new object[] { null, e });
     }
     else
     {
         beiProcess.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;    // 不显示进度条
         beiStatus.Caption = string.Format(@"[{0}]扫描完成!", e.web.Name);
         ShowPageList(true);         // 刷新一下结点
         m_task = null;        // 清空线程
     }
 }
Beispiel #4
0
        // 开始扫描时,界面的显示
        private void ShowBeginScan(object sender, BaseRule.SiteScanBeginEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new BaseRule.SiteScanBeginHandler(ShowBeginScan), new object[] { null, e });
            }
            else
            {
                // 将状态栏的文本提示和进度条显示出来
                beiStatus.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
                beiProcess.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;

                // 设置进度条的最大值
                this.repositoryItemProgressBar1.Maximum = e.web.MaxPage;

                // 初始化显示内容
                beiStatus.Caption = string.Format(@"[{0}]开始准备扫描...", e.web.Name);
                beiProcess.EditValue = 0;
            }
        }
Beispiel #5
0
        // 保存所有扫描出来的页面到数据库里面
        protected void SaveScanResult(object sender, BaseRule.ScanCompleteEventArgs e)
        {
            // 同一时间只能一个线程保存数据
            System.Threading.Mutex m = new System.Threading.Mutex(false, "SaveDB");
            m.WaitOne();
            using (UnitOfWork uow = new UnitOfWork(XpoDefault.DataLayer))       // 开始事务
            {
                uow.BeginTransaction();
                //  对于每个取得的新页面,判断是否已经存在,如果不存在就保存
                foreach (Page page in e.pages)
                {
                    XPCollection<Page> pages = new XPCollection<Page>(uow,
                        CriteriaOperator.Parse("URL = ?", page.URL));
                    if (pages.Count() == 0)
                    {
                        Page newPage = new Page(uow) { Parent_ID = CurrentWeb.Oid, Title = page.Title, URL = page.URL };
                        newPage.Save();
                    }
                }
                uow.CommitChanges();
            }

            m.ReleaseMutex();
        }
Beispiel #6
0
 public static void ShowMessage(object sender, BaseRule.ScanCompleteEventArgs e)
 {
     m_count ++;
     Console.WriteLine(@"已经下载了{0}页,共{1}页", m_count, e.web.MaxPage);
 }