//加载指定任务的信息 private void LoadTaskInfo(string FileName) { //根据一个任务名称装载一个任务 try { xmlConfig = new cXmlIO(FileName); //获取TaskClass节点 //TaskClass = xmlConfig.GetData("descendant::TaskClasses"); } catch (System.Exception ex) { if (!File.Exists(FileName)) { throw new System.IO.IOException("您指定的任务文件不存在!"); } else { throw ex; } } //加载任务信息 this.TaskID = Int64.Parse(xmlConfig.GetNodeValue("Task/BaseInfo/ID")); this.TaskName = xmlConfig.GetNodeValue("Task/BaseInfo/Name"); ///加载任务版本信息,注意:1.0中是不存在版本信息描述的,所以如果加载1.0的任务 ///会出错 try { this.TaskVersion = Single.Parse(xmlConfig.GetNodeValue("Task/BaseInfo/Version")); } catch (System.Exception) { this.TaskVersion = Single.Parse("1.0"); } if (TaskVersion != SupportTaskVersion) { throw new cSoukeyException("您加载任务的版本低于系统要求的版本,请对任务进行升级后重试!"); } this.TaskDemo = xmlConfig.GetNodeValue("Task/BaseInfo/TaskDemo"); this.TaskClass = xmlConfig.GetNodeValue("Task/BaseInfo/Class"); this.TaskType = xmlConfig.GetNodeValue("Task/BaseInfo/Type"); this.RunType = xmlConfig.GetNodeValue("Task/BaseInfo/RunType"); //因存的是相对路径,所以要加上系统路径 this.SavePath = Program.getPrjPath() + xmlConfig.GetNodeValue("Task/BaseInfo/SavePath"); this.UrlCount = int.Parse(xmlConfig.GetNodeValue("Task/BaseInfo/UrlCount").ToString()); this.ThreadCount = int.Parse(xmlConfig.GetNodeValue("Task/BaseInfo/ThreadCount")); this.Cookie = xmlConfig.GetNodeValue("Task/BaseInfo/Cookie"); this.DemoUrl = xmlConfig.GetNodeValue("Task/BaseInfo/DemoUrl"); this.StartPos = xmlConfig.GetNodeValue("Task/BaseInfo/StartPos"); this.EndPos = xmlConfig.GetNodeValue("Task/BaseInfo/EndPos"); this.WebCode = xmlConfig.GetNodeValue("Task/BaseInfo/WebCode"); this.IsLogin = (xmlConfig.GetNodeValue("Task/BaseInfo/IsLogin") == "True"? true :false); this.LoginUrl = xmlConfig.GetNodeValue("Task/BaseInfo/LoginUrl"); this.IsUrlEncode = (xmlConfig.GetNodeValue("Task/BaseInfo/IsUrlEncode") == "True" ? true : false); this.UrlEncode = xmlConfig.GetNodeValue("Task/BaseInfo/UrlEncode"); this.ExportType = xmlConfig.GetNodeValue("Task/Result/ExportType"); this.ExportFile = xmlConfig.GetNodeValue("Task/Result/ExportFileName"); this.DataSource = xmlConfig.GetNodeValue("Task/Result/DataSource"); this.DataTableName = xmlConfig.GetNodeValue("Task/Result/DataTableName"); this.InsertSql = xmlConfig.GetNodeValue("Task/Result/InsertSql"); this.ExportUrl = xmlConfig.GetNodeValue("Task/Result/ExportUrl"); this.ExportUrlCode = xmlConfig.GetNodeValue("Task/Result/ExportUrlCode"); this.ExportCookie = xmlConfig.GetNodeValue("Task/Result/ExportCookie"); //加载高级配置信息 this.GatherAgainNumber = int.Parse(xmlConfig.GetNodeValue("Task/Advance/GatherAgainNumber")); this.IsIgnore404 = (xmlConfig.GetNodeValue("Task/Advance/IsIgnore404") == "True" ? true : false); this.IsErrorLog = (xmlConfig.GetNodeValue("Task/Advance/IsErrorLog") == "True" ? true : false); this.IsDelRepRow = (xmlConfig.GetNodeValue("Task/Advance/IsDelRepeatRow") == "True" ? true : false); this.IsExportHeader = (xmlConfig.GetNodeValue("Task/Advance/IsExportHeader") == "True" ? true : false); this.IsTrigger = (xmlConfig.GetNodeValue("Task/Advance/IsTrigger") == "True" ? true : false); this.TriggerType = xmlConfig.GetNodeValue("Task/Advance/TriggerType"); DataView dw = new DataView(); int i; //加载Trigger信息 dw = xmlConfig.GetData("descendant::Trigger"); cTriggerTask tt; if (dw != null) { for (i = 0; i < dw.Count; i++) { tt = new cTriggerTask(); tt.RunTaskType = int.Parse(dw[i].Row["RunTaskType"].ToString()); tt.RunTaskName = dw[i].Row["RunTaskName"].ToString(); tt.RunTaskPara = dw[i].Row["RunTaskPara"].ToString(); this.TriggerTask.Add(tt); } } dw = null; dw = new DataView(); dw = xmlConfig.GetData("descendant::WebLinks"); cWebLink w; DataView dn; if (dw != null) { for (i = 0; i < dw.Count; i++) { w = new cWebLink(); w.id = i; w.Weblink = dw[i].Row["Url"].ToString(); if (dw[i].Row["IsNag"].ToString() == "True") { w.IsNavigation = true; } else { w.IsNavigation = false; } if (dw[i].Row["IsNextPage"].ToString() == "True") { w.IsNextpage = true; } else { w.IsNextpage = false; } w.NextPageRule = dw[i].Row["NextPageRule"].ToString(); w.IsGathered = int.Parse((dw[i].Row["IsGathered"].ToString() == null || dw[i].Row["IsGathered"].ToString() == "") ? "2031" : dw[i].Row["IsGathered"].ToString()); //加载导航规则 if (w.IsNavigation == true) { dn = dw[i].CreateChildView("WebLink_NavigationRules")[0].CreateChildView("NavigationRules_Rule"); cNavigRule nRule; for (int m = 0; m < dn.Count; m++) { nRule = new cNavigRule(); nRule.Url = dn[m].Row["Url"].ToString(); nRule.Level = int.Parse(dn[m].Row["Level"].ToString()); nRule.NavigRule = dn[m].Row["NagRule"].ToString(); w.NavigRules.Add(nRule); } } this.WebpageLink.Add(w); w = null; } } dw = null; dw = new DataView(); dw = xmlConfig.GetData("descendant::GatherRule"); Task.cWebpageCutFlag c; if (dw != null) { for (i = 0; i < dw.Count; i++) { c = new Task.cWebpageCutFlag(); c.Title = dw[i].Row["Title"].ToString(); c.DataType = int.Parse((dw[i].Row["DataType"].ToString() == null || dw[i].Row["DataType"].ToString() == "") ? "0" : dw[i].Row["DataType"].ToString()); c.StartPos = dw[i].Row["StartFlag"].ToString(); c.EndPos = dw[i].Row["EndFlag"].ToString(); c.LimitSign = int.Parse((dw[i].Row["LimitSign"].ToString() == null || dw[i].Row["LimitSign"].ToString() == "") ? "0" : dw[i].Row["LimitSign"].ToString()); //处理版本不同时造成的错误,捕获不处理 try { c.RegionExpression = dw[i].Row["RegionExpression"].ToString(); c.ExportLimit = int.Parse((dw[i].Row["ExportLimit"].ToString() == null || dw[i].Row["ExportLimit"].ToString() == "") ? "0" : dw[i].Row["ExportLimit"].ToString()); c.ExportExpression = dw[i].Row["ExportExpression"].ToString(); } catch (System.Exception) { } this.WebpageCutFlag.Add(c); c = null; } } dw = null; }
private bool SaveTask(string TaskPath) { Task.cTask t = new Task.cTask(); //����DZ༭״̬������Ҫɾ��ԭ���ļ� if (this.FormState == cGlobalParas.FormState.Edit) { t.TaskName = this.tTask.Text; if (this.comTaskClass.SelectedIndex == 0) { try { //ɾ��ԭ���������ҪĿ����Ϊ�˱��ݣ������������������� t.DeleTask("", this.tTask.Text); } catch (System.Exception) { } } else { //��ȡ����������·�� Task.cTaskClass tClass = new Task.cTaskClass(); string tPath = tClass.GetTaskClassPathByName(this.comTaskClass.SelectedItem.ToString()); try { //ɾ��ԭ���������ҪĿ����Ϊ�˱��ݣ������������������� t.DeleTask(tPath, this.tTask.Text); } catch (System.Exception) { } } } int i = 0; int UrlCount = 0; //�������� //�½�һ������ t.New(); t.TaskName = this.tTask.Text; t.TaskDemo = this.txtTaskDemo.Text; if (this.comTaskClass.SelectedIndex == 0) { t.TaskClass = ""; } else { t.TaskClass = this.comTaskClass.SelectedItem.ToString(); } t.TaskType = cGlobalParas.ConvertID(this.TaskType.SelectedItem.ToString()).ToString(); t.RunType = cGlobalParas.ConvertID(this.comRunType.SelectedItem.ToString()).ToString(); if (this.txtSavePath.Text.Trim().ToString() == "") t.SavePath = Program.getPrjPath() + "data"; else t.SavePath = this.txtSavePath.Text; t.ThreadCount = int.Parse(this.udThread.Value.ToString()); t.StartPos = this.txtStartPos.Text; t.EndPos = this.txtEndPos.Text; t.DemoUrl = this.txtWeblinkDemo.Text; t.Cookie = this.txtCookie.Text; t.WebCode = cGlobalParas.ConvertID(this.comWebCode.SelectedItem.ToString()).ToString(); t.IsLogin = this.IsLogin.Checked; t.LoginUrl = this.txtLoginUrl.Text; t.IsUrlEncode = this.IsUrlEncode.Checked; if (this.IsUrlEncode.Checked == false) { t.UrlEncode = ""; } else { t.UrlEncode = cGlobalParas.ConvertID(this.comUrlEncode.SelectedItem.ToString()).ToString(); } //�ж��Ƿ��ļ����洢������������Ϣ if (this.comRunType.SelectedIndex == 0) { if (this.raExportTxt.Checked == true) { t.ExportType = ((int)cGlobalParas.PublishType.PublishTxt).ToString(); } else if (this.raExportExcel.Checked == true) { t.ExportType = ((int)cGlobalParas.PublishType.PublishExcel).ToString(); } else if (this.raExportAccess.Checked == true) { t.ExportType = ((int)cGlobalParas.PublishType.PublishAccess).ToString(); } else if (this.raExportMSSQL.Checked == true) { t.ExportType = ((int)cGlobalParas.PublishType.PublishMSSql).ToString(); } else if (this.raExportMySql.Checked == true) { t.ExportType = ((int)cGlobalParas.PublishType.PublishMySql).ToString(); } else if (this.raExportWeb.Checked == true) { t.ExportType = ((int)cGlobalParas.PublishType.PublishWeb).ToString(); } t.ExportFile = this.txtFileName.Text.ToString(); t.DataSource = this.txtDataSource.Text.ToString(); t.DataTableName = this.comTableName.Text.ToString(); t.InsertSql = this.txtInsertSql.Text; t.ExportUrl = this.txtExportUrl.Text; t.ExportUrlCode = cGlobalParas.ConvertID(this.comExportUrlCode.SelectedItem.ToString()).ToString(); t.ExportCookie = this.txtExportCookie.Text; } else { t.ExportFile = ""; t.DataSource = ""; t.ExportType = ((int)cGlobalParas.PublishType.NoPublish).ToString(); t.DataSource = ""; t.DataTableName = ""; } //��ʼ�洢��������Ϣ t.GatherAgainNumber = int.Parse(this.udAgainNumber.Value.ToString()); t.IsIgnore404 = this.IsIgnore404.Checked; t.IsExportHeader = this.IsIncludeHeader.Checked; t.IsDelRepRow = this.IsDelRepRow.Checked; t.IsErrorLog = this.IsSaveErrorLog.Checked; t.IsTrigger = this.IsStartTrigger.Checked; if (this.raGatheredRun.Checked == true) t.TriggerType = ((int)cGlobalParas.TriggerType.GatheredRun).ToString(); else if (this.raPublishedRun.Checked == true) t.TriggerType = ((int)cGlobalParas.TriggerType.PublishedRun).ToString(); cTriggerTask tt; //��ʼ��Ӵ�����ִ�е����� for (i = 0; i < this.listTask.Items.Count; i++) { tt = new cTriggerTask(); tt.RunTaskType = cGlobalParas.ConvertID(this.listTask.Items[i].Text); if (cGlobalParas.ConvertID(this.listTask.Items[i].Text) == (int)cGlobalParas.RunTaskType.DataTask) tt.RunTaskName = cGlobalParas.ConvertID(this.listTask.Items[i].SubItems[1].Text.ToString()).ToString(); else tt.RunTaskName = this.listTask.Items[i].SubItems[1].Text.ToString(); tt.RunTaskPara = this.listTask.Items[i].SubItems[2].Text.ToString(); t.TriggerTask.Add(tt); } for (i = 0; i < this.listWeblink.Items.Count; i++) { UrlCount += int.Parse(this.listWeblink.Items[i].SubItems[4].Text); } t.UrlCount = UrlCount; Task.cWebLink w; for (i = 0; i < this.listWeblink.Items.Count; i++) { w = new Task.cWebLink(); w.id = i; w.Weblink = this.listWeblink.Items[i].Text; if (this.listWeblink.Items[i].SubItems[1].Text == "N") { w.IsNavigation = false; } else { w.IsNavigation = true; //��ӵ������� for (int m = 0; m < m_listNaviRules.Count; m++) { if (m_listNaviRules[m].Url == this.listWeblink.Items[i].Text) { w.NavigRules = m_listNaviRules[m].NavigRule; break; } } } if (this.listWeblink.Items[i].SubItems[3].Text == "" || this.listWeblink.Items[i].SubItems[3].Text == null) { w.IsNextpage = false; } else { w.IsNextpage = true; w.NextPageRule = this.listWeblink.Items[i].SubItems[3].Text; } t.WebpageLink.Add(w); w = null; } Task.cWebpageCutFlag c; for (i = 0; i < this.listWebGetFlag.Items.Count; i++) { c = new Task.cWebpageCutFlag(); c.id = i; c.Title = this.listWebGetFlag.Items[i].Text; c.DataType = cGlobalParas.ConvertID(this.listWebGetFlag.Items[i].SubItems[1].Text); c.StartPos = this.listWebGetFlag.Items[i].SubItems[2].Text; c.EndPos = this.listWebGetFlag.Items[i].SubItems[3].Text; c.LimitSign = cGlobalParas.ConvertID(this.listWebGetFlag.Items[i].SubItems[4].Text); try { c.RegionExpression = this.listWebGetFlag.Items[i].SubItems[5].Text; c.ExportLimit = cGlobalParas.ConvertID(this.listWebGetFlag.Items[i].SubItems[6].Text); c.ExportExpression = this.listWebGetFlag.Items[i].SubItems[7].Text; } catch (System.Exception) { //��������������1.0�汾 } t.WebpageCutFlag.Add(c); c = null; } t.Save(TaskPath); t = null; return true; }
//����ָ���������Ϣ private void LoadTaskInfo(string FileName) { //����һ����������װ��һ������ try { xmlConfig = new cXmlIO(FileName); //��ȡTaskClass�ڵ� //TaskClass = xmlConfig.GetData("descendant::TaskClasses"); } catch (System.Exception ex) { if (!File.Exists(FileName)) { throw new System.IO.IOException("��ָ���������ļ������ڣ�"); } else { throw ex; } } //����������Ϣ this.TaskID =Int64.Parse ( xmlConfig.GetNodeValue("Task/BaseInfo/ID")); this.TaskName = xmlConfig.GetNodeValue("Task/BaseInfo/Name"); ///��������汾��Ϣ��ע�⣺1.0���Dz����ڰ汾��Ϣ�����ģ������������1.0������ ///����� try { this.TaskVersion = Single.Parse(xmlConfig.GetNodeValue("Task/BaseInfo/Version")); } catch (System.Exception ) { this.TaskVersion =Single.Parse ("1.0"); } if (TaskVersion != SupportTaskVersion) { throw new cSoukeyException("����������İ汾����ϵͳҪ��İ汾���������������������ԣ�"); } this.TaskDemo = xmlConfig.GetNodeValue("Task/BaseInfo/TaskDemo"); this.TaskClass = xmlConfig.GetNodeValue("Task/BaseInfo/Class"); this.TaskType=xmlConfig.GetNodeValue("Task/BaseInfo/Type"); this.RunType = xmlConfig.GetNodeValue("Task/BaseInfo/RunType"); //���������·��������Ҫ����ϵͳ·�� this.SavePath = Program.getPrjPath () + xmlConfig.GetNodeValue("Task/BaseInfo/SavePath"); this.UrlCount =int.Parse (xmlConfig.GetNodeValue("Task/BaseInfo/UrlCount").ToString ()); this.ThreadCount = int.Parse (xmlConfig.GetNodeValue("Task/BaseInfo/ThreadCount")); this.Cookie = xmlConfig.GetNodeValue("Task/BaseInfo/Cookie"); this.DemoUrl = xmlConfig.GetNodeValue("Task/BaseInfo/DemoUrl"); this.StartPos = xmlConfig.GetNodeValue("Task/BaseInfo/StartPos"); this.EndPos = xmlConfig.GetNodeValue("Task/BaseInfo/EndPos"); this.WebCode = xmlConfig.GetNodeValue("Task/BaseInfo/WebCode"); this.IsLogin =( xmlConfig.GetNodeValue("Task/BaseInfo/IsLogin")=="True"? true :false ); this.LoginUrl = xmlConfig.GetNodeValue("Task/BaseInfo/LoginUrl"); this.IsUrlEncode = (xmlConfig.GetNodeValue("Task/BaseInfo/IsUrlEncode") == "True" ? true : false); this.UrlEncode = xmlConfig.GetNodeValue("Task/BaseInfo/UrlEncode"); this.ExportType =xmlConfig.GetNodeValue("Task/Result/ExportType") ; this.ExportFile = xmlConfig.GetNodeValue("Task/Result/ExportFileName"); this.DataSource = xmlConfig.GetNodeValue("Task/Result/DataSource"); this.DataTableName = xmlConfig.GetNodeValue("Task/Result/DataTableName"); this.InsertSql = xmlConfig.GetNodeValue("Task/Result/InsertSql"); this.ExportUrl = xmlConfig.GetNodeValue("Task/Result/ExportUrl"); this.ExportUrlCode = xmlConfig.GetNodeValue("Task/Result/ExportUrlCode"); this.ExportCookie = xmlConfig.GetNodeValue("Task/Result/ExportCookie"); //���ظ�������Ϣ this.GatherAgainNumber= int.Parse (xmlConfig.GetNodeValue("Task/Advance/GatherAgainNumber")); this.IsIgnore404 = (xmlConfig.GetNodeValue("Task/Advance/IsIgnore404") == "True" ? true : false); this.IsErrorLog = (xmlConfig.GetNodeValue("Task/Advance/IsErrorLog") == "True" ? true : false); this.IsDelRepRow = (xmlConfig.GetNodeValue("Task/Advance/IsDelRepeatRow") == "True" ? true : false); this.IsExportHeader =( xmlConfig.GetNodeValue("Task/Advance/IsExportHeader") == "True" ? true : false); this.IsTrigger =( xmlConfig.GetNodeValue("Task/Advance/IsTrigger") == "True" ? true : false); this.TriggerType = xmlConfig.GetNodeValue("Task/Advance/TriggerType"); DataView dw = new DataView(); int i; //����Trigger��Ϣ dw = xmlConfig.GetData("descendant::Trigger"); cTriggerTask tt; if (dw != null) { for (i = 0; i < dw.Count; i++) { tt = new cTriggerTask(); tt.RunTaskType = int.Parse ( dw[i].Row["RunTaskType"].ToString()); tt.RunTaskName = dw[i].Row["RunTaskName"].ToString(); tt.RunTaskPara = dw[i].Row["RunTaskPara"].ToString(); this.TriggerTask.Add(tt); } } dw = null; dw = new DataView(); dw = xmlConfig.GetData("descendant::WebLinks"); cWebLink w; DataView dn; if (dw!=null) { for (i = 0; i < dw.Count; i++) { w = new cWebLink(); w.id = i; w.Weblink = dw[i].Row["Url"].ToString(); if (dw[i].Row["IsNag"].ToString() == "True") w.IsNavigation = true; else w.IsNavigation = false; if (dw[i].Row["IsNextPage"].ToString() == "True") w.IsNextpage = true; else w.IsNextpage = false; w.NextPageRule = dw[i].Row["NextPageRule"].ToString(); w.IsGathered = int.Parse((dw[i].Row["IsGathered"].ToString() == null || dw[i].Row["IsGathered"].ToString() == "") ? "2031" : dw[i].Row["IsGathered"].ToString()); //���ص������� if (w.IsNavigation == true) { dn = dw[i].CreateChildView("WebLink_NavigationRules")[0].CreateChildView("NavigationRules_Rule"); cNavigRule nRule; for (int m = 0; m < dn.Count; m++) { nRule = new cNavigRule(); nRule.Url = dn[m].Row["Url"].ToString(); nRule.Level = int.Parse(dn[m].Row["Level"].ToString()); nRule.NavigRule = dn[m].Row["NagRule"].ToString(); w.NavigRules.Add(nRule); } } this.WebpageLink.Add(w); w = null; } } dw = null; dw = new DataView(); dw = xmlConfig.GetData("descendant::GatherRule"); Task.cWebpageCutFlag c; if (dw != null) { for (i = 0; i < dw.Count; i++) { c = new Task.cWebpageCutFlag(); c.Title = dw[i].Row["Title"].ToString(); c.DataType = int.Parse((dw[i].Row["DataType"].ToString() == null || dw[i].Row["DataType"].ToString() == "") ? "0" : dw[i].Row["DataType"].ToString()); c.StartPos = dw[i].Row["StartFlag"].ToString(); c.EndPos = dw[i].Row["EndFlag"].ToString(); c.LimitSign = int.Parse((dw[i].Row["LimitSign"].ToString() == null || dw[i].Row["LimitSign"].ToString() == "") ? "0" : dw[i].Row["LimitSign"].ToString()); //����汾��ͬʱ��ɵĴ������� try { c.RegionExpression = dw[i].Row["RegionExpression"].ToString(); c.ExportLimit = int.Parse((dw[i].Row["ExportLimit"].ToString() == null || dw[i].Row["ExportLimit"].ToString() == "") ? "0" : dw[i].Row["ExportLimit"].ToString()); c.ExportExpression = dw[i].Row["ExportExpression"].ToString(); } catch (System.Exception) { } this.WebpageCutFlag.Add(c); c = null; } } dw=null; }