Beispiel #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);
            }
        }
        public void Execute(IJobExecutionContext context)
        {
            var k = context.JobDetail.Key;
            var j = context.JobDetail.JobDataMap.SingleOrDefault(p => p.Key == k.Name).Value as ModelTask;

            Console.WriteLine(context.JobDetail.Key.Name + "::::" + j.ID + "::::" + j.TaskName);

            var          model  = dal.GetModelSingleTask(j.ID);
            SpiderHelper Spider = new SpiderHelper();

            Spider.modelTask          = model;
            Spider.GatherWorkDelegate = (object sender, GatherEvents.GatherLinkEvents e) => {
                CommonHelper.FormMain.OutPutWindowBox(this, new MainEvents.OutPutWindowEventArgs()
                {
                    Message = e.Message
                });
            };
            Console.WriteLine("采集任务开始!");
            Spider.Start();
        }
        /// <summary>
        /// 任务开始
        /// </summary>
        private void ToolStripMenuItem_TaskStart_Click(object sender, EventArgs e)
        {
            try {
                DALTask   dal   = new DALTask();
                ModelTask model = new ModelTask();
                int       ID    = Get_DataViewID();
                //检查目录是否存在
                //model = dal.GetModelSingleTask(ID);

                if (listGatherTask.ContainsKey(ID.ToString()))
                {
                    SpiderHelper Spider = listGatherTask.FirstOrDefault().Value;
                    if (Spider.Stopped)
                    {
                        Spider.Start();
                    }
                }
                else
                {
                    model = dal.GetModelSingleTask(ID);
                    SpiderHelper 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);
            }
        }