예제 #1
0
        /// <summary>
        /// 任务开始
        /// </summary>
        private void ToolStripMenuItem_TaskStart_Click(object sender, EventArgs e)
        {
            try {
                DALTask   dal   = new DALTask();
                ModelTask model = new ModelTask();
                int       ID    = Get_DataViewID();

                if (listGatherTask.ContainsKey(ID.ToString()))
                {
                    var Spider = listGatherTask.FirstOrDefault().Value;
                    if (Spider.Stopped)
                    {
                        Spider.Start();
                    }
                }
                else
                {
                    model = dal.GetModelSingleTask(ID);
                    if (model.Status != 1)
                    {
                        MainEvents.OutPutWindowEventArgs ev = new MainEvents.OutPutWindowEventArgs();
                        ev.Message = "任务关闭中.不可采集...";
                        OutPutWindowDelegate?.Invoke(this, ev);
                        return;
                    }
                    string baseDir    = AppDomain.CurrentDomain.BaseDirectory + "Data\\Collection\\";
                    string SQLiteName = baseDir + model.TaskName + "\\SpiderResult.db";
                    if (!File.Exists(SQLiteName))
                    {
                        CreateDataFile(model.TaskName, ID);
                    }
                    var Spider = new SpiderHelper();
                    Spider.modelTask                     = model;
                    Spider.GatherWorkDelegate            = OutUrl;
                    Spider.GatherComplateDelegate        = GatherOverDelegate;
                    Spider.OutPutTaskProgressBarDelegate = OutPutTaskProgressBarDelegate;
                    Spider.TaskIndex                     = this.dataGridView_TaskList.SelectedRows[0].Index;
                    Spider.Start();
                    lock (listGatherTask) {
                        if (!listGatherTask.ContainsKey(ID.ToString()))
                        {
                            listGatherTask.Add(ID.ToString(), Spider);
                        }
                    }
                }
            }
            catch (Exception ex) {
                Log4Helper.Write(LogLevel.Error, ex.StackTrace, ex);
            }
        }
예제 #2
0
 private void FrmTaskMain_Load(object sender, EventArgs e)
 {
     Bind_DataList();
     Bind_Plugin();
     tsmExportData.DropDownItems.Clear();
     foreach (IOutPutFormat t in PluginUtility.ListIOutputFormatPlugin)
     {
         var item = new ToolStripMenuItem(t.Format);
         item.MouseEnter += (object s, EventArgs e1) => {
             var id    = Get_DataViewID();
             var Model = new DALTask().GetModel(id);
             if (Model.IsSaveLocal2 != null && Model.IsSaveLocal2.Value == 1)
             {
                 item.Enabled = true;
             }
             else
             {
                 item.Enabled = false;
             }
         };
         item.Click += (object s, EventArgs e1) =>
         {
             var       id              = Get_DataViewID();
             var       Model           = new DALTask().GetModel(id);
             string    LocalSQLiteName = "Data\\Collection\\" + Model.TaskName + "\\SpiderResult.db";
             DataTable dtData          = DbHelper.Query(LocalSQLiteName, "Select * From Content").Tables[0];
             if (!Directory.Exists(Model.SaveDirectory2))
             {
                 Directory.CreateDirectory(Model.SaveDirectory2);
             }
             if (File.Exists(LocalSQLiteName))
             {
                 var r = t.RunSave(dtData, Model);
                 MainEvents.OutPutWindowEventArgs ev = new MainEvents.OutPutWindowEventArgs();
                 if (r.IsOk)
                 {
                     ev.Message = r.Message;
                     OutPutWindowDelegate?.Invoke(this, ev);
                 }
                 else
                 {
                     ev.Message = "保存过程出现错误" + r.Message;
                     OutPutWindowDelegate?.Invoke(this, ev);
                 }
             }
         };
         tsmExportData.DropDownItems.Add(item);
     }
 }
예제 #3
0
 /// <summary>
 /// 日志输出
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void OutPutWindow(object sender, MainEvents.OutPutWindowEventArgs e)
 {
     if (this.txtOutWindowString.InvokeRequired)
     {
         this.txtOutWindowString.BeginInvoke(new MethodInvoker(delegate() {
             this.txtOutWindowString.AppendText("【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】 " + e.Message);
             this.txtOutWindowString.AppendText("\r\n");
         }));
     }
     else
     {
         this.txtOutWindowString.AppendText("【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】 " + e.Message);
         this.txtOutWindowString.AppendText("\r\n");
     }
 }
예제 #4
0
 /// <summary>
 /// 任务结果输出
 /// </summary>
 public void OutUrl(object sender, GatherEvents.GatherLinkEvents e)
 {
     //if (!string.IsNullOrEmpty(e.ID)) {
     //    ModelGatherTask model = listGatherTask.Where(p => p.TaskID == int.Parse("0" + e.ID)).FirstOrDefault();
     //    if (model != null) {
     //        listGatherTask.Remove(model);
     //    }
     //}
     MainEvents.OutPutWindowEventArgs ev = new MainEvents.OutPutWindowEventArgs();
     ev.Message = e.Message;
     OutPutWindowDelegate?.Invoke(this, ev);
     //if (OutPutWindowDelegate != null) {
     //    OutPutWindowDelegate(this, ev);
     //}
 }
예제 #5
0
 /// <summary>
 /// 任务结果输出
 /// </summary>
 public void OutUrl(object sender, GatherEvents.GatherLinkEvents e)
 {
     MainEvents.OutPutWindowEventArgs ev = new MainEvents.OutPutWindowEventArgs();
     ev.Message = e.Message;
     OutPutWindowDelegate?.Invoke(this, ev);
 }
예제 #6
0
 /// <summary>
 /// 发布站点信息委托
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="MeOutPut"></param>
 private void PublishOP(object sender, MainEvents.OutPutWindowEventArgs MeOutPut)
 {
     MessageBox.Show(MeOutPut.Message);
 }