コード例 #1
0
ファイル: FrmTask.cs プロジェクト: github188/smartbooks
        /// <summary>
        /// 获取当前已修改的UI界面任务配置设置
        /// </summary>
        /// <returns>任务配置对象</returns>
        private Task GetUiConfig()
        {
            Task t = new Task();

            #region 保存任务设置
            t.Name         = this.txtName.Text;
            t.Description  = this.txtDescription.Text;
            t.ThreadNumber = Convert.ToInt32(this.nudThreadNumber.Value);
            t.UrlListManager.UrlEncoding        = this.cbxUrlEncoding.Text;
            t.UrlListManager.HistoryUrlCapacity = Convert.ToInt32(this.nudHistoryCount.Value);
            t.OutputDetailedLog              = this.chbOutputDetailedLog.Checked;
            t.SaveLogToFile                  = this.chbSaveLogToFile.Checked;
            t.LoginAutomatically             = this.rdbAutoLogin.Checked;
            t.Cookie                         = this.txtCookie.Text;
            t.ScheduleLimitTimeRange         = this.chbScheduleLimitTimeRange.Checked;
            t.DisableScheduleAfterFinish     = this.chbDisableScheduleAfterFinish.Checked;
            t.ScheduleDays                   = Convert.ToInt32(this.nudScheduleDays.Value);
            t.ScheduleHours                  = Convert.ToInt32(this.nudScheduleHours.Value);
            t.ScheduleMinutes                = Convert.ToInt32(this.nudScheduleHours.Value);
            t.UseProcedure                   = this.chbUseProcedure.Checked;
            t.PublicationTarget              = this.cbxPublicationTarget.Text;
            t.ConnectionString               = this.txtConnectionString.Text;
            t.DeleteResultAfterPublication   = this.chbDeleteResultAfterPublication.Checked;
            t.ElapsedTime                    = this._TaskUnit.TaskConfig.ElapsedTime; /*运行时间等于原任务时间*/
            t.IgnoreDataColumnNotFound       = this.chbIgnoreDataColumnNotFound.Checked;
            t.SaveRepeatedRows               = this.chbSaveRepeatedRows.Checked;
            t.SaveErrorRows                  = this.chbSaveErrorRows.Checked;
            t.PluginPath                     = this.txtPluginPath.Text;
            t.UsePluginOfProcessContentFile  = this.chbUsePluginOfProcessContentFile.Checked;
            t.UsePluginOfProcessSingleFile   = this.chbUsePluginOfProcessSingleFile.Checked;
            t.UsePluginOfDownloadContentFile = this.chbUsePluginOfDownloadContentFile.Checked;
            t.UsePluginOfDownloadSingleFile  = this.chbUsePluginOfDownloadSingleFile.Checked;
            t.UsePluginOfProcessResultRow    = this.chbUsePluginOfProcessResultRow.Checked;
            t.UsePluginOfGetWebProxy         = this.chbUsePluginOfGetWebProxy.Checked;
            #endregion

            #region 获取定时采集调度设置

            t.ScheduleEnabled = this.chbScheduleEnabled.Checked;
            //每隔时间段
            if (rdoScheduleModeTime.Checked)
            {
                t.ScheduleMode    = ScheduleMode.Time;
                t.ScheduleDays    = (int)this.nudScheduleDays.Value;
                t.ScheduleHours   = (int)this.nudScheduleHours.Value;
                t.ScheduleMinutes = (int)this.nudScheduleMinutes.Value;
            }

            //(每当模式/*该功能留在V2.0实现*/)
            if (rdoScheduleModeDay.Checked)
            {
                t.ScheduleMode = ScheduleMode.Day;
                //每当时间
                t.ScheduleFromDayOfWeek = this._TaskUnit.TaskConfig.ScheduleFromDayOfWeek; //每当星期几开始
                t.ScheduleFromDay       = this._TaskUnit.TaskConfig.ScheduleFromDay;       //每当星期几开始
                t.ScheduleFromHour      = this._TaskUnit.TaskConfig.ScheduleFromHour;      //每当X小时调度

                //预定时间
                t.ScheduleFromDayOfWeek = this._TaskUnit.TaskConfig.ScheduleFromDayOfWeek; //预定星期几结束
                t.ScheduleToDay         = this._TaskUnit.TaskConfig.ScheduleToDay;         //预定天
                t.ScheduleToHour        = this._TaskUnit.TaskConfig.ScheduleToHour;        //预定小时
            }

            #endregion

            #region 发布结果选项
            if (this.rdoResultSaveFile.Checked)
            {
                t.PublishResultDircetly = false;
            }
            else
            {
                t.PublishResultDircetly = true;
            }
            #endregion

            #region 数据库类型
            if (this.rdoDataTypeAccess.Checked)
            {
                t.DatabaseType = DatabaseType.Access;
            }
            else if (this.rdoDataTypeMySql.Checked)
            {
                t.DatabaseType = DatabaseType.MySql;
            }
            else if (this.rdoDataTypeOracle.Checked)
            {
                t.DatabaseType = DatabaseType.Oracle;
            }
            else if (this.rdoDataTypeSqlLite.Checked)
            {
                t.DatabaseType = DatabaseType.SqlLite;
            }
            else if (this.rdoDataTypeSqlServer.Checked)
            {
                t.DatabaseType = DatabaseType.SqlServer;
            }
            #endregion

            #region 起始地址 {start, end, step}
            foreach (string url in this.libStartingUrlList.Items)
            {
                MatchCollection regexMatch = Regex.Matches(url, "{[0-9,-]*}");
                if (regexMatch.Count != 0)
                {
                    string[]         v = regexMatch[0].Value.Replace("}", "").Replace("{", "").Split(',');
                    PagedUrlPatterns p = new PagedUrlPatterns();
                    p.Format          = PagedUrlPatternsMode.Increment;
                    p.PagedUrlPattern = url;
                    p.StartPage       = Convert.ToDouble(v[0]);
                    p.EndPage         = Convert.ToDouble(v[1]);
                    if (v.Length >= 3)
                    {
                        p.Step = Convert.ToDouble(v[2]);
                    }
                    if (p.StartPage > p.EndPage)
                    {
                        p.Format = PagedUrlPatternsMode.Decreasing;
                    }
                    /*模板网址*/
                    t.UrlListManager.PagedUrlPattern.Add(p);
                }
                else
                {
                    /*普通网址*/
                    t.UrlListManager.StartingUrlList.Add(url);
                }
            }
            #endregion

            #region 导航地址
            foreach (Utility.NavigationRuleItem item in this.livNavigationRule.Items)
            {
                t.UrlListManager.NavigationRules.Add(item.rule);
            }
            #endregion

            #region 采集规则
            foreach (Utility.ExtractionRulesItem item in this.LivExtractionRule.Items)
            {
                t.ExtractionRules.Add(item.rule);
            }
            #endregion

            return(t);
        }
コード例 #2
0
ファイル: FrmTask.cs プロジェクト: qcjxberin/SmartSpider
        /// <summary>
        /// 获取当前已修改的UI界面任务配置设置
        /// </summary>
        /// <returns>任务配置对象</returns>
        private Task GetUiConfig() {
            Task t = new Task();
            #region 保存任务设置
            t.Name = this.txtName.Text;
            t.Description = this.txtDescription.Text;
            t.ThreadNumber = Convert.ToInt32(this.nudThreadNumber.Value);
            t.UrlListManager.UrlEncoding = this.cbxUrlEncoding.Text;
            t.UrlListManager.HistoryUrlCapacity = Convert.ToInt32(this.nudHistoryCount.Value);
            t.OutputDetailedLog = this.chbOutputDetailedLog.Checked;
            t.SaveLogToFile = this.chbSaveLogToFile.Checked;
            t.LoginAutomatically = this.rdbAutoLogin.Checked;
            t.Cookie = this.txtCookie.Text;            
            t.ScheduleLimitTimeRange = this.chbScheduleLimitTimeRange.Checked;
            t.DisableScheduleAfterFinish = this.chbDisableScheduleAfterFinish.Checked;
            t.ScheduleDays = Convert.ToInt32(this.nudScheduleDays.Value);
            t.ScheduleHours = Convert.ToInt32(this.nudScheduleHours.Value);
            t.ScheduleMinutes = Convert.ToInt32(this.nudScheduleHours.Value);
            t.UseProcedure = this.chbUseProcedure.Checked;
            t.PublicationTarget = this.cbxPublicationTarget.Text;
            t.ConnectionString = this.txtConnectionString.Text;
            t.DeleteResultAfterPublication = this.chbDeleteResultAfterPublication.Checked;
            t.ElapsedTime = this._TaskUnit.TaskConfig.ElapsedTime;    /*运行时间等于原任务时间*/
            t.IgnoreDataColumnNotFound = this.chbIgnoreDataColumnNotFound.Checked;
            t.SaveRepeatedRows = this.chbSaveRepeatedRows.Checked;
            t.SaveErrorRows = this.chbSaveErrorRows.Checked;
            t.PluginPath = this.txtPluginPath.Text;
            t.UsePluginOfProcessContentFile = this.chbUsePluginOfProcessContentFile.Checked;
            t.UsePluginOfProcessSingleFile = this.chbUsePluginOfProcessSingleFile.Checked;
            t.UsePluginOfDownloadContentFile = this.chbUsePluginOfDownloadContentFile.Checked;
            t.UsePluginOfDownloadSingleFile = this.chbUsePluginOfDownloadSingleFile.Checked;
            t.UsePluginOfProcessResultRow = this.chbUsePluginOfProcessResultRow.Checked;
            t.UsePluginOfGetWebProxy = this.chbUsePluginOfGetWebProxy.Checked;
            #endregion

            #region 获取定时采集调度设置

            t.ScheduleEnabled = this.chbScheduleEnabled.Checked;
            //每隔时间段
            if (rdoScheduleModeTime.Checked) {
                t.ScheduleMode = ScheduleMode.Time;
                t.ScheduleDays = (int)this.nudScheduleDays.Value;
                t.ScheduleHours = (int)this.nudScheduleHours.Value;
                t.ScheduleMinutes = (int)this.nudScheduleMinutes.Value;
            }

            //(每当模式/*该功能留在V2.0实现*/)
            if (rdoScheduleModeDay.Checked) {
                t.ScheduleMode = ScheduleMode.Day;
                //每当时间
                t.ScheduleFromDayOfWeek = this._TaskUnit.TaskConfig.ScheduleFromDayOfWeek; //每当星期几开始
                t.ScheduleFromDay = this._TaskUnit.TaskConfig.ScheduleFromDay; //每当星期几开始
                t.ScheduleFromHour = this._TaskUnit.TaskConfig.ScheduleFromHour; //每当X小时调度

                //预定时间
                t.ScheduleFromDayOfWeek = this._TaskUnit.TaskConfig.ScheduleFromDayOfWeek; //预定星期几结束
                t.ScheduleToDay = this._TaskUnit.TaskConfig.ScheduleToDay; //预定天
                t.ScheduleToHour = this._TaskUnit.TaskConfig.ScheduleToHour; //预定小时
            }

            #endregion

            #region 发布结果选项
            if (this.rdoResultSaveFile.Checked) {
                t.PublishResultDircetly = false;
            } else {
                t.PublishResultDircetly = true;
            }
            #endregion

            #region 数据库类型
            if (this.rdoDataTypeAccess.Checked) {
                t.DatabaseType = DatabaseType.Access;
            } else if (this.rdoDataTypeMySql.Checked) {
                t.DatabaseType = DatabaseType.MySql;
            } else if (this.rdoDataTypeOracle.Checked) {
                t.DatabaseType = DatabaseType.Oracle;
            } else if (this.rdoDataTypeSqlLite.Checked) {
                t.DatabaseType = DatabaseType.SqlLite;
            } else if (this.rdoDataTypeSqlServer.Checked) {
                t.DatabaseType = DatabaseType.SqlServer;
            }
            #endregion

            #region 起始地址 {start, end, step}
            foreach (string url in this.libStartingUrlList.Items) {
                MatchCollection regexMatch = Regex.Matches(url, "{[0-9,-]*}");
                if (regexMatch.Count != 0) {
                    string[] v = regexMatch[0].Value.Replace("}", "").Replace("{", "").Split(',');
                    PagedUrlPatterns p = new PagedUrlPatterns();
                    p.Format = PagedUrlPatternsMode.Increment;
                    p.PagedUrlPattern = url;
                    p.StartPage = Convert.ToDouble(v[0]);
                    p.EndPage = Convert.ToDouble(v[1]);
                    if (v.Length >= 3) {
                        p.Step = Convert.ToDouble(v[2]);
                    }
                    if (p.StartPage > p.EndPage) {
                        p.Format = PagedUrlPatternsMode.Decreasing;
                    }
                    /*模板网址*/
                    t.UrlListManager.PagedUrlPattern.Add(p);
                } else {
                    /*普通网址*/
                    t.UrlListManager.StartingUrlList.Add(url);
                }
            }
            #endregion

            #region 导航地址
            foreach (Utility.NavigationRuleItem item in this.livNavigationRule.Items) {
                t.UrlListManager.NavigationRules.Add(item.rule);
            }
            #endregion

            #region 采集规则
            foreach (Utility.ExtractionRulesItem item in this.LivExtractionRule.Items) {
                t.ExtractionRules.Add(item.rule);
            }
            #endregion

            return t;
        }