//修改制定计划的名称 public bool RenamePlanName(string OldPlanName, string NewPlanName) { //判断计划文件是否存在,如果不存在则新建 if (!IsExist()) { NewIndexFile(); } //判断计划是否重名,如果重名则需要进行名称修改 cXmlIO xmlPlan = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); DataView d = xmlPlan.GetData("descendant::Plans"); if (d != null) { for (int i = 0; i < d.Count; i++) { if (NewPlanName == d[i].Row["PlanName"].ToString()) { xmlPlan = null; throw new cSoukeyException("已经存在此计划,重命名失败"); return(false); } } } xmlPlan.EditNodeValue("Plans", "PlanName", OldPlanName, "PlanName", NewPlanName); xmlPlan.Save(); xmlPlan = null; return(true); }
//public int GetPlanCount() //{ // return 0; //} //插入一个计划,计划不能重名 public void InsertPlan(cPlan NewPlan) { //判断计划文件是否存在,如果不存在则新建 if (!IsExist()) { NewIndexFile(); } //判断计划是否重名,如果重名则需要进行名称修改 cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); DataView d = xmlConfig.GetData("descendant::Plans"); if (d != null) { for (int i = 0; i < d.Count; i++) { if (NewPlan.PlanName == d[i].Row["PlanName"].ToString()) { xmlConfig = null; throw new cSoukeyException("已经存在此计划,请修改计划名称,计划名称不能重复!"); } } } string pXml = CreatePlanXml(NewPlan); xmlConfig.InsertElement("Plans", "Plan", pXml); xmlConfig.Save(); xmlConfig = null; }
private void ModifyPlanState(Int64 PlanID, cGlobalParas.PlanState pState) { cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); xmlConfig.EditNodeValue("Plans", "ID", PlanID.ToString(), "PlanState", ((int)pState).ToString()); xmlConfig.Save(); xmlConfig = null; }
private void ModifyPlanRunTime(Int64 PlanID, int RunTime) { cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); xmlConfig.EditNodeValue("Plans", "ID", PlanID.ToString(), "RunTimeCount", RunTime.ToString()); xmlConfig.Save(); xmlConfig = null; }
public void NewTaskRunFile() { xmlConfig = new cXmlIO(); string strXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<Tasks>" + "</Tasks>"; xmlConfig.NewXmlFile(Program.getPrjPath() + "tasks\\taskrun.xml", strXml); }
public void NewTaskCompleteFile() { xmlConfig = new cXmlIO(); string strXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<Tasks>" + "</Tasks>"; xmlConfig.NewXmlFile(Program.getPrjPath() + "data\\index.xml", strXml); }
//当新建一个任务时,调用此方法 public void New() { //this.TaskState =(int) cGlobalParas.TaskState.TaskUnStart; if (xmlConfig != null) { xmlConfig = null; } }
public void OpenLogFile() { if (!IsExist()) { NewLogFile(); } m_PlanFile = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\RunLog.xml"); }
//根据计划的状态获取计划 public void GetPlanByState(cGlobalParas.PlanState pState) { string PlanPath = Program.getPrjPath() + "tasks\\plan"; xmlConfig = new cXmlIO(PlanPath + "\\index.xml"); //获取TaskClass节点 Plans = xmlConfig.GetData("TaskIndex"); }
public void DelPlan(string PlanID) { //�жϼƻ��Ƿ������������������Ҫ���������� cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); //ɾ���ƻ��ڵ� xmlConfig.DeleteChildNodes("Plans", "ID", PlanID); xmlConfig.Save(); xmlConfig = null; }
public void DelPlan(string PlanID) { //判断计划是否重名,如果重名则需要进行名称修改 cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); //删除计划节点 xmlConfig.DeleteChildNodes("Plans", "ID", PlanID); xmlConfig.Save(); xmlConfig = null; }
//获取任务分类根目录下的任务索引,此目录为应用程序路径\\tasks, //此分类为固定内容,不提供用户可操作的任何处理。 public void GetTaskDataByClass() { string ClassPath = Program.getPrjPath() + "tasks"; m_TaskPath = ClassPath; xmlConfig = new cXmlIO(ClassPath + "\\index.xml"); //获取TaskClass节点 Tasks = xmlConfig.GetData("TaskIndex"); }
private void NewLogFile() { cXmlIO xmlConfig = new cXmlIO(); string strXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<Logs>" + "</Logs>"; xmlConfig.NewXmlFile(Program.getPrjPath() + "tasks\\plan\\RunLog.xml", strXml); xmlConfig = null; }
public void NewIndexFile() { cXmlIO xmlConfig = new cXmlIO(); string strXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<Plans>" + "</Plans>"; xmlConfig.NewXmlFile(Program.getPrjPath() + "tasks\\plan\\plan.xml", strXml); xmlConfig = null; }
public void LoadLog() { if (!IsExist()) { return; } cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\RunLog.xml"); m_dataLog = xmlConfig.GetData("descendant::Logs"); xmlConfig = null; }
///保存运行的任务,主要是保存当前运行的状态 ///任务保存需要同时保存taskrun.xml,主要是保存采集数量 ///注意,如果进行暂存后,任务的链接地址会发生变化,因为在任务新建时,任务链接地址有可能带有一定得参数 ///但任务一旦开始执行,带有参数的网址就会进行解析,同时是按照解析后的网址进行是否采集的标识,所以,再次 ///保存后,链接地址会很多 public void Save() { string FileName = Program.getPrjPath() + "tasks\\run\\task" + this.TaskID + ".xml"; string runFileindex = Program.getPrjPath() + "tasks\\taskrun.xml"; //开始保存文件 string tXml = ""; for (int i = 0; i < m_TaskData.Weblink.Count; i++) { tXml += "<WebLink>"; tXml += "<Url>" + cTool.ReplaceTrans(m_TaskData.Weblink[i].Weblink.ToString()) + "</Url>"; tXml += "<IsNag>" + m_TaskData.Weblink[i].IsNavigation + "</IsNag>"; //tXml += "<IsOppPath>" + m_TaskData.Weblink[i].IsOppPath + "</IsOppPath>"; //tXml += "<NagRule>" + cTool.ReplaceTrans(m_TaskData.Weblink[i].NagRule) + "</NagRule>"; tXml += "<IsNextPage>" + m_TaskData.Weblink[i].IsNextpage + "</IsNextPage>"; tXml += "<NextPageRule>" + cTool.ReplaceTrans(m_TaskData.Weblink[i].NextPageRule) + "</NextPageRule>"; tXml += "<IsGathered>" + (int)m_TaskData.Weblink[i].IsGathered + "</IsGathered>"; //保存采集地地址是否需要导航 //插入此网址的导航规则 if (m_TaskData.Weblink[i].IsNavigation == true) { tXml += "<NavigationRules>"; for (int j = 0; j < m_TaskData.Weblink[i].NavigRules.Count; j++) { tXml += "<Rule>"; tXml += "<Url>" + cTool.ReplaceTrans(m_TaskData.Weblink[i].NavigRules[j].Url) + "</Url>"; tXml += "<Level>" + m_TaskData.Weblink[i].NavigRules[j].Level + "</Level>"; tXml += "<NagRule>" + cTool.ReplaceTrans(m_TaskData.Weblink[i].NavigRules[j].NavigRule) + "</NagRule>"; tXml += "</Rule>"; } tXml += "</NavigationRules>"; } tXml += "</WebLink>"; } cXmlIO cxml = new cXmlIO(FileName); cxml.DeleteNode("WebLinks"); cxml.InsertElement("Task", "WebLinks", tXml); cxml.Save(); cxml = null; cxml = new cXmlIO(runFileindex); cxml.EditTaskrunValue(this.TaskID.ToString(), cGlobalParas.TaskState.Stopped, this.GatheredUrlCount.ToString(), this.GatheredTrueUrlCount.ToString(), this.GatherErrUrlCount.ToString(), this.GatheredTrueErrUrlCount.ToString(), this.TrueUrlCount.ToString()); cxml.Save(); cxml = null; }
public cTaskClass() { try { xmlConfig = new cXmlIO(Program.getPrjPath () + "TaskClass.xml"); //��ȡTaskClass�ڵ� TaskClass = xmlConfig.GetData("descendant::TaskClasses"); } catch (System.Exception ex) { throw ex; } }
public void EditPlan(cPlan ePlan) { //�жϼƻ��Ƿ������������������Ҫ���������� cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); //ɾ���ƻ��ڵ� xmlConfig.DeleteChildNodes("Plans", "ID", ePlan.PlanID.ToString ()); string pXml = CreatePlanXml(ePlan); xmlConfig.InsertElement("Plans", "Plan", pXml); xmlConfig.Save(); xmlConfig = null; }
//返回的是已经完成的任务的集合信息 public void LoadTaskData() { try { xmlConfig = new cXmlIO(Program.getPrjPath() + "Data\\index.xml"); } catch (System.Exception ex) { throw ex; } //获取TaskClass节点 Tasks = xmlConfig.GetData("Tasks"); }
public cTaskClass() { try { xmlConfig = new cXmlIO(Program.getPrjPath() + "TaskClass.xml"); //获取TaskClass节点 TaskClass = xmlConfig.GetData("descendant::TaskClasses"); } catch (System.Exception ex) { throw ex; } }
public void EditPlan(cPlan ePlan) { //判断计划是否重名,如果重名则需要进行名称修改 cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); //删除计划节点 xmlConfig.DeleteChildNodes("Plans", "ID", ePlan.PlanID.ToString()); string pXml = CreatePlanXml(ePlan); xmlConfig.InsertElement("Plans", "Plan", pXml); xmlConfig.Save(); xmlConfig = null; }
//获取一个执行的计划 public cPlan GetSinglePlan(Int64 PlanID) { //判断计划文件是否存在,如果不存在则新建 if (!IsExist()) { NewIndexFile(); } //判断计划是否重名,如果重名则需要进行名称修改 cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); DataView d = xmlConfig.GetData("Plans", "ID", PlanID.ToString()); DataView t = d[0].CreateChildView("Plan_Tasks")[0].CreateChildView("Tasks_Task"); cPlan p = new cPlan(); p.PlanID = Int64.Parse(d[0].Row["ID"].ToString()); p.PlanName = d[0].Row["PlanName"].ToString(); p.PlanRemark = d[0].Row["PlanRemark"].ToString(); p.PlanState = int.Parse(d[0].Row["PlanState"].ToString()); p.IsOverRun = d[0].Row["IsOverRun"].ToString() == "True" ? true : false; p.IsDisabled = d[0].Row["IsDisabled"].ToString() == "True" ? true : false; p.DisabledType = int.Parse(d[0].Row["DisabledType"].ToString()); p.DisabledTime = int.Parse(d[0].Row["DisabledTime"].ToString()); p.DisabledDateTime = DateTime.Parse(d[0].Row["DisabledDateTime"].ToString()); p.RunTaskPlanType = int.Parse(d[0].Row["RunTaskPlanType"].ToString()); p.EnabledDateTime = d[0].Row["EnabledDateTime"].ToString(); p.RunOnesTime = d[0].Row["RunOnesTime"].ToString(); p.RunDayTime = d[0].Row["RunDayTime"].ToString(); p.RunAMTime = d[0].Row["RunAMTime"].ToString(); p.RunPMTime = d[0].Row["RunPMTime"].ToString(); p.RunWeeklyTime = d[0].Row["RunWeeklyTime"].ToString(); p.RunWeekly = d[0].Row["RunWeekly"].ToString(); p.RunTimeCount = d[0].Row["RunTimeCount"].ToString(); p.FirstRunTime = d[0].Row["FirstRunTime"].ToString(); p.RunInterval = d[0].Row["RunInterval"].ToString(); cTaskPlan tp; for (int i = 0; i < t.Count; i++) { tp = new cTaskPlan(); tp.RunTaskType = int.Parse(t[i].Row["RunTaskType"].ToString()); tp.RunTaskName = t[i].Row["RunTaskName"].ToString(); tp.RunTaskPara = t[i].Row["RunTaskPara"].ToString(); p.RunTasks.Add(tp); } xmlConfig = null; return(p); }
public void GetTaskDataByClass(int ClassID) { Task.cTaskClass tClass = new Task.cTaskClass(); string ClassPath = tClass.GetTaskClassPathByID(ClassID); m_TaskPath = ClassPath; tClass = null; xmlConfig = new cXmlIO(ClassPath + "\\index.xml"); //获取TaskClass节点 Tasks = xmlConfig.GetData("TaskIndex"); }
//根据完成任务ID加载任务信息 public void LoadSingleTask(Int64 TaskID) { try { xmlConfig = new cXmlIO(Program.getPrjPath() + "Data\\index.xml"); } catch (System.Exception ex) { throw ex; } //获取TaskClass节点,尽管返回的也是DataView,但其中只包含一条记录 //这样做是为了更好的兼容访问操作 Tasks = xmlConfig.GetData("Tasks", "TaskID", TaskID.ToString()); }
//加载计划 //只加载计划的摘要信息,即只会从文件中加载需要列表显示的 //计划内容,不会完整的加载计划信息 public void LoadPlans() { cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); DataView d = xmlConfig.GetData("descendant::Plans"); if (d == null) { return; } cPlan p; for (int i = 0; i < d.Count; i++) { p = new cPlan(); p.PlanID = Int64.Parse(d[i].Row["ID"].ToString()); p.PlanName = d[i].Row["PlanName"].ToString(); p.PlanState = int.Parse(d[i].Row["PlanState"].ToString()); p.IsOverRun = d[i].Row["IsOverRun"].ToString() == "True" ? true : false; p.IsDisabled = d[i].Row["IsDisabled"].ToString() == "True" ? true : false; p.DisabledType = int.Parse(d[i].Row["DisabledType"].ToString()); p.DisabledTime = int.Parse(d[i].Row["DisabledTime"].ToString()); p.DisabledDateTime = DateTime.Parse(d[i].Row["DisabledDateTime"].ToString()); p.RunTaskPlanType = int.Parse(d[i].Row["RunTaskPlanType"].ToString()); p.EnabledDateTime = d[i].Row["EnabledDateTime"].ToString(); p.RunOnesTime = d[i].Row["RunOnesTime"].ToString(); p.RunDayTime = d[i].Row["RunDayTime"].ToString(); p.RunAMTime = d[i].Row["RunAMTime"].ToString(); p.RunPMTime = d[i].Row["RunPMTime"].ToString(); p.RunWeeklyTime = d[i].Row["RunWeeklyTime"].ToString(); p.RunWeekly = d[i].Row["RunWeekly"].ToString(); p.RunTimeCount = d[i].Row["RunTimeCount"].ToString(); p.FirstRunTime = d[i].Row["FirstRunTime"].ToString(); p.RunInterval = d[i].Row["RunInterval"].ToString(); m_Plans.Add(p); } p = null; }
public void InsertOnceLog(cGlobalParas.LogType lType, string PlanID, string PlanName, cGlobalParas.RunTaskType rType, string FileName, string Para) { if (!IsExist()) { NewLogFile(); } cXmlIO xmlconfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\RunLog.xml"); string strXml = "<LogType>" + lType + "</LogType>" + "<PlanID>" + PlanID + "</PlanID>" + "<PlanName>" + PlanName + "</PlanName>" + "<FileName>" + FileName + "</FileName>" + "<FilePara>" + Para + "</FilePara>" + "<TaskType>" + rType + "</TaskType>" + "<RunTime>" + DateTime.Now.ToString() + "</RunTime>"; xmlconfig.InsertElement("Logs", "Log", strXml); xmlconfig.Save(); xmlconfig = null; }
public void GetTaskDataByClass(string ClassName) { string ClassPath; if (ClassName == "") { ClassPath = Program.getPrjPath() + "Tasks"; } else { Task.cTaskClass tClass = new Task.cTaskClass(); ClassPath = tClass.GetTaskClassPathByName(ClassName); tClass = null; } m_TaskPath = ClassPath; xmlConfig = new cXmlIO(ClassPath + "\\index.xml"); //获取TaskClass节点 Tasks = xmlConfig.GetData("TaskIndex"); }
//����ָ���������Ϣ 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; }
public cTaskIndex() { xmlConfig = new cXmlIO(); }
private void ModifyPlanState(Int64 PlanID, cGlobalParas.PlanState pState) { cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); xmlConfig.EditNodeValue("Plans", "ID", PlanID.ToString () ,"PlanState",((int)pState).ToString ()); xmlConfig.Save (); xmlConfig =null; }
//���ƶ��ƻ������� public bool RenamePlanName(string OldPlanName, string NewPlanName) { //�жϼƻ��ļ��Ƿ���ڣ�������������½� if (!IsExist()) NewIndexFile(); //�жϼƻ��Ƿ������������������Ҫ���������� cXmlIO xmlPlan = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); DataView d = xmlPlan.GetData("descendant::Plans"); if (d != null) { for (int i = 0; i < d.Count; i++) { if (NewPlanName == d[i].Row["PlanName"].ToString()) { xmlPlan = null; throw new cSoukeyException("�Ѿ����ڴ˼ƻ���������ʧ��"); return false; } } } xmlPlan.EditNodeValue("Plans", "PlanName", OldPlanName, "PlanName", NewPlanName); xmlPlan.Save(); xmlPlan = null; return true; }
//���ؼƻ� //ֻ���ؼƻ���ժҪ��Ϣ����ֻ����ļ��м�����Ҫ�б���ʾ�� //�ƻ����ݣ����������ļ��ؼƻ���Ϣ public void LoadPlans() { cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); DataView d = xmlConfig.GetData("descendant::Plans"); if (d == null) { return; } cPlan p; for (int i = 0; i < d.Count; i++) { p = new cPlan(); p.PlanID =Int64.Parse ( d[i].Row["ID"].ToString()); p.PlanName = d[i].Row["PlanName"].ToString(); p.PlanState =int.Parse (d[i].Row["PlanState"].ToString()); p.IsOverRun = d[i].Row["IsOverRun"].ToString() == "True" ? true : false; p.IsDisabled = d[i].Row["IsDisabled"].ToString() == "True" ? true : false; p.DisabledType =int.Parse ( d[i].Row["DisabledType"].ToString()); p.DisabledTime = int.Parse ( d[i].Row["DisabledTime"].ToString()); p.DisabledDateTime = DateTime.Parse ( d[i].Row["DisabledDateTime"].ToString()); p.RunTaskPlanType = int.Parse ( d[i].Row["RunTaskPlanType"].ToString()); p.EnabledDateTime = d[i].Row["EnabledDateTime"].ToString(); p.RunOnesTime = d[i].Row["RunOnesTime"].ToString(); p.RunDayTime =d[i].Row["RunDayTime"].ToString(); p.RunAMTime = d[i].Row["RunAMTime"].ToString(); p.RunPMTime =d[i].Row["RunPMTime"].ToString(); p.RunWeeklyTime = d[i].Row["RunWeeklyTime"].ToString(); p.RunWeekly = d[i].Row["RunWeekly"].ToString(); p.RunTimeCount = d[i].Row["RunTimeCount"].ToString(); p.FirstRunTime = d[i].Row["FirstRunTime"].ToString(); p.RunInterval = d[i].Row["RunInterval"].ToString(); m_Plans.Add(p); } p = null; }
//加载指定任务的信息 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; }
//仅根据任务信息保存任务文件,不做其他数据的问题,此方法 //主要用于支持任务升级使用 public void SaveTaskFile(string TaskPath) { //获取需要保存任务的路径 string tPath = ""; if (TaskPath == "" || TaskPath == null) { tPath = GetTaskClassPath() + "\\"; } else { tPath = TaskPath; } int i = 0; //判断此路径下是否已经存在了此任务,如果存在则返回错误信息 if (IsExistTaskFile(tPath + this.TaskName)) { throw new cSoukeyException("任务已经存在,不能建立"); } //开始增加Task任务 //构造Task任务的XML文档格式 //当前构造xml文件全部采用的拼写字符串的形式,并没有采用xml构造函数 string tXml; tXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<Task>" + "<State></State>" + ///此状态值当前无效,用于将来扩充使用 "<BaseInfo>" + "<Version>1.3</Version>" + //默认当前的任务版本号为:1.2 "<ID>" + TaskID + "</ID>" + "<Name>" + this.TaskName + "</Name>" + "<TaskDemo>" + this.TaskDemo + "</TaskDemo>" + "<Class>" + this.TaskClass + "</Class>" + "<Type>" + this.TaskType + "</Type>" + "<RunType>" + this.RunType + "</RunType>" + //选哟转换成相对路径 "<SavePath>" + cTool.GetRelativePath(this.SavePath) + "</SavePath>" + "<ThreadCount>" + this.ThreadCount + "</ThreadCount>" + "<UrlCount>" + this.UrlCount + "</UrlCount>" + "<StartPos>" + cTool.ReplaceTrans(this.StartPos) + "</StartPos>" + "<EndPos>" + cTool.ReplaceTrans(this.EndPos) + "</EndPos>" + "<DemoUrl>" + cTool.ReplaceTrans(this.DemoUrl) + "</DemoUrl>" + "<Cookie>" + cTool.ReplaceTrans(this.Cookie) + "</Cookie>" + "<WebCode>" + this.WebCode + "</WebCode>" + "<IsLogin>" + this.IsLogin + "</IsLogin>" + "<LoginUrl>" + this.LoginUrl + "</LoginUrl>" + "<IsUrlEncode>" + this.IsUrlEncode + "</IsUrlEncode>" + "<UrlEncode>" + this.UrlEncode + "</UrlEncode>" + "</BaseInfo>" + "<Result>" + "<ExportType>" + this.ExportType + "</ExportType>" + "<ExportFileName>" + this.ExportFile + "</ExportFileName>" + "<DataSource>" + this.DataSource + "</DataSource>" + "<DataTableName>" + this.DataTableName + "</DataTableName>" + "<InsertSql>" + this.InsertSql + "</InsertSql>" + "<ExportUrl>" + cTool.ReplaceTrans(this.ExportUrl) + "</ExportUrl>" + "<ExportUrlCode>" + this.ExportUrlCode + "</ExportUrlCode>" + "<ExportCookie>" + cTool.ReplaceTrans(this.ExportCookie) + "</ExportCookie>" + "</Result>"; tXml += "<Advance>" + "<GatherAgainNumber>" + this.GatherAgainNumber + "</GatherAgainNumber>" + "<IsIgnore404>" + this.IsIgnore404 + "</IsIgnore404>" + "<IsErrorLog>" + this.IsErrorLog + "</IsErrorLog>" + "<IsExportHeader>" + this.IsExportHeader + "</IsExportHeader>" + "<IsDelRepeatRow>" + this.IsDelRepRow + "</IsDelRepeatRow>" + "<IsTrigger>" + this.IsTrigger + "</IsTrigger>" + "<TriggerType>" + this.TriggerType + "</TriggerType>" + "</Advance>"; tXml += "<Trigger>"; for (i = 0; i < this.m_TriggerTask.Count; i++) { tXml += "<Task>"; tXml += "<RunTaskType>" + this.m_TriggerTask[i].RunTaskType + "</RunTaskType>"; tXml += "<RunTaskName>" + this.m_TriggerTask[i].RunTaskName + "</RunTaskName>"; tXml += "<RunTaskPara>" + this.m_TriggerTask[i].RunTaskPara + "</RunTaskPara>"; tXml += "</Task>"; } tXml += "</Trigger>"; tXml += "<WebLinks>"; if (this.WebpageLink != null) { for (i = 0; i < this.WebpageLink.Count; i++) { tXml += "<WebLink>"; tXml += "<Url>" + cTool.ReplaceTrans(this.WebpageLink[i].Weblink.ToString()) + "</Url>"; tXml += "<IsNag>" + this.WebpageLink[i].IsNavigation + "</IsNag>"; tXml += "<IsNextPage>" + this.WebpageLink[i].IsNextpage + "</IsNextPage>"; tXml += "<NextPageRule>" + cTool.ReplaceTrans(this.WebpageLink[i].NextPageRule) + "</NextPageRule>"; //默认插入一个节点,表示此链接地址还未进行采集,因为是系统添加任务,所以默认为UnGather tXml += "<IsGathered>" + (int)cGlobalParas.UrlGatherResult.UnGather + "</IsGathered>"; //插入此网址的导航规则 if (this.WebpageLink[i].IsNavigation == true) { tXml += "<NavigationRules>"; for (int j = 0; j < this.WebpageLink[i].NavigRules.Count; j++) { tXml += "<Rule>"; tXml += "<Url>" + cTool.ReplaceTrans(this.WebpageLink[i].NavigRules[j].Url) + "</Url>"; tXml += "<Level>" + this.WebpageLink[i].NavigRules[j].Level + "</Level>"; tXml += "<NagRule>" + cTool.ReplaceTrans(this.WebpageLink[i].NavigRules[j].NavigRule) + "</NagRule>"; tXml += "</Rule>"; } tXml += "</NavigationRules>"; } tXml += "</WebLink>"; } } tXml += "</WebLinks>" + "<GatherRule>"; if (this.WebpageCutFlag != null) { for (i = 0; i < this.WebpageCutFlag.Count; i++) { tXml += "<Rule>"; tXml += "<Title>" + cTool.ReplaceTrans(this.WebpageCutFlag[i].Title) + "</Title>"; tXml += "<DataType>" + this.WebpageCutFlag[i].DataType + "</DataType>"; tXml += "<StartFlag>" + cTool.ReplaceTrans(this.WebpageCutFlag[i].StartPos) + "</StartFlag>"; tXml += "<EndFlag>" + cTool.ReplaceTrans(this.WebpageCutFlag[i].EndPos) + "</EndFlag>"; tXml += "<LimitSign>" + this.WebpageCutFlag[i].LimitSign + "</LimitSign>"; tXml += "<RegionExpression>" + cTool.ReplaceTrans(this.WebpageCutFlag[i].RegionExpression) + "</RegionExpression>"; tXml += "<ExportLimit>" + this.WebpageCutFlag[i].ExportLimit + "</ExportLimit>"; tXml += "<ExportExpression>" + cTool.ReplaceTrans(this.WebpageCutFlag[i].ExportExpression) + "</ExportExpression>"; tXml += "</Rule>"; } } tXml += "</GatherRule>" + "</Task>"; xmlConfig = new cXmlIO(); xmlConfig.NewXmlFile(tPath + this.TaskName + ".xml", tXml); xmlConfig = null; }
public void GetTaskDataByClass(string ClassName) { string ClassPath ; if (ClassName == "") { ClassPath = Program.getPrjPath() + "Tasks"; } else { Task.cTaskClass tClass = new Task.cTaskClass(); ClassPath = tClass.GetTaskClassPathByName(ClassName) ; tClass = null; } m_TaskPath = ClassPath; xmlConfig = new cXmlIO(ClassPath + "\\index.xml"); //��ȡTaskClass�ڵ� Tasks = xmlConfig.GetData("TaskIndex"); }
//��ȡ��������Ŀ¼�µ�������������Ŀ¼ΪӦ�ó���·��\\tasks�� //�˷���Ϊ�̶����ݣ����ṩ�û��ɲ������κδ���� public void GetTaskDataByClass() { string ClassPath = Program.getPrjPath() + "tasks"; m_TaskPath = ClassPath; xmlConfig = new cXmlIO(ClassPath + "\\index.xml"); //��ȡTaskClass�ڵ� Tasks = xmlConfig.GetData("TaskIndex"); }
public void GetTaskDataByClass(int ClassID) { Task.cTaskClass tClass = new Task.cTaskClass(); string ClassPath = tClass.GetTaskClassPathByID(ClassID); m_TaskPath = ClassPath; tClass = null; xmlConfig = new cXmlIO(ClassPath + "\\index.xml"); //��ȡTaskClass�ڵ� Tasks = xmlConfig.GetData("TaskIndex"); }
public cPlanIndex() { xmlConfig = new cXmlIO(); }
//����ִ�е�����ID����������Ϣ public void LoadSingleTask(Int64 TaskID) { try { xmlConfig = new cXmlIO(Program.getPrjPath() + "Tasks\\TaskRun.xml"); } catch (System.Exception ex) { throw ex; } //��ȡTaskClass�ڵ�,���ܷ��ص�Ҳ��DataView,������ֻ����һ����¼ //��������Ϊ�˸��õļ��ݷ��ʲ��� Tasks = xmlConfig.GetData("Tasks","TaskID",TaskID.ToString () ); }
public Int64 InsertTaskRun(string Path, string File) { ///�����жϴ������ִ�е�Ŀ¼�Ƿ���� ///��Ŀ¼�ǹ̶�Ŀ¼�������ϵͳ\\Task\\run string RunPath = Program.getPrjPath() + "Tasks\\run"; if (!System.IO.Directory.Exists(RunPath)) { System.IO.Directory.CreateDirectory(RunPath); } ///�Ƚ��������ժҪ��Ϣ���ص�TaskRun.xml�ļ��� Task.cTask t = new Task.cTask(); t.LoadTask(Path + "\\" + File); //��ʼ����xml�ڵ����� LoadTaskRunData(); Int64 maxID = GetNewID(); string tRunxml = ""; tRunxml = "<TaskID>" + maxID + "</TaskID>"; tRunxml += "<TaskName>" + t.TaskName + "</TaskName>"; tRunxml += "<TaskState>" + (int)cGlobalParas.TaskState.UnStart + "</TaskState>"; tRunxml += "<TaskType>" + t.TaskType + "</TaskType>"; tRunxml += "<RunType>" + t.RunType + "</RunType>"; tRunxml += "<ExportFile>" + t.ExportFile + "</ExportFile>"; tRunxml += "<tempFile>" + t.SavePath + "\\" + t.TaskName + "-" + maxID + ".xml" + "</tempFile>"; tRunxml += "<StartDate>" + DateTime.Now + "</StartDate>"; tRunxml += "<EndDate></EndDate>"; tRunxml += "<ThreadCount>" + t.ThreadCount + "</ThreadCount>"; tRunxml += "<UrlCount>" + t.UrlCount + "</UrlCount>"; ///TrueUrlCount��ʾ����ɼ�����ַ�д��ڵ�����ַ������Ҫ�ɼ�����ַ�������ݹ�ʽ���˳����� ///��Ҫ�ɼ�����ִ�У����ϸ��ݲɼ��Ĺ�����м���ɼ���ַ��������������Ҫ�ٴμ�¼��ֵ ///��¼��ֵ��Ŀ����Ϊ�˿��Ը��õĸ��ٲɼ��Ľ��ȣ���Urlcount�����ģ���Ϊ��ֵҪ��������ֽ� ///ʹ�ã�����ı���UrlCount����ܵ�������ֽ�ʧ�ܣ�����Ӫ�����ʼ����ʱ��ֵͬUrlCount����ֵ�� ///������������Ӫʱά�� tRunxml += "<TrueUrlCount>" + t.UrlCount + "</TrueUrlCount>"; tRunxml += "<GatheredUrlCount>0</GatheredUrlCount>"; tRunxml += "<GatheredTrueUrlCount>0</GatheredTrueUrlCount>"; tRunxml += "<ErrUrlCount>0</ErrUrlCount>"; tRunxml += "<TrueErrUrlCount>0</TrueErrUrlCount>"; tRunxml += "<IsLogin>" + t.IsLogin + "</IsLogin>"; tRunxml += "<PublishType>" + t.ExportType + "</PublishType>"; xmlConfig.InsertElement("Tasks", "Task", tRunxml); xmlConfig.Save(); xmlConfig = null; ///������������xml�ļ��ĸ�ʽ��Task�����ʽ��ȫһ�۸�����������ʽ��ȫ��ͬ ///������ʽ�ǰ���Task����ǰ�ļ���Taskrun�е�id����������������Ŀ����֧��ͬһ������ ///���Խ����������ʵ����Ҳ���ǵ�����������е�ʱ���û�Ҳ�����Ĵ���������� ///һ��ʵ����ʼ���С� System.IO.File.Copy(Path + "\\" + File, RunPath + "\\" + "Task" + maxID + ".xml", true); //�ļ�������ȥ����Ҫ���ļ��е�TaskID�����Ǻ�TaskRun�е�TaskID���������� //�ڼ����ļ���ʱ������,ϵͳ��ID����Ψһ���� cXmlIO xmlFile; xmlFile = new cXmlIO(RunPath + "\\" + "Task" + maxID + ".xml"); string tID = xmlFile.GetNodeValue("Task/BaseInfo/ID"); xmlFile.EditNode("ID", tID, maxID.ToString()); xmlFile.Save(); xmlFile = null; return maxID ; }
//���ص�������������ļ�����Ϣ public void LoadTaskRunData() { try { xmlConfig = new cXmlIO(Program.getPrjPath() + "Tasks\\TaskRun.xml"); } catch (System.Exception ex) { throw ex; } //��ȡTaskClass�ڵ� Tasks = xmlConfig.GetData("Tasks"); }
//ָ����������������� /// <summary> /// ����������� /// </summary> /// <param name="FileName">�������������ļ�</param> /// <param name="IsBackup">�Ƿ�</param> /// <param name="IsTask">�Ƿ�Ϊϵͳ���������ϵͳ��������Ҫά��������Ϣ��������Ǿ�ֻ�����ļ�</param> public void UpdradeTask(string FileName ,bool IsBackup,bool IsSystemTask) { //�ж��Ƿ���б��� if (IsBackup == true) { if (File.Exists(FileName + ".bak")) File.Delete(FileName + ".bak"); File.Copy(FileName, FileName + ".bak"); } //���������ļ� cXmlIO Old_Task = new cXmlIO(FileName); Single TaskVersion =Single.Parse ("0"); cTask t = new cTask(); //�ж�����汾�� try { TaskVersion = Single.Parse(Old_Task.GetNodeValue("Task/BaseInfo/Version")); } catch (System.Exception) { TaskVersion = Single.Parse("1.0"); } if (TaskVersion >= this.SupportTaskVersion) { Old_Task = null; return; } //��ʼ�½�һ������ t.New(); #region �˲����������κΰ汾�����ڵ� t.TaskID = Int64.Parse(Old_Task.GetNodeValue("Task/BaseInfo/ID")); t.TaskName = Old_Task.GetNodeValue("Task/BaseInfo/Name"); t.TaskVersion = this.SupportTaskVersion; t.TaskDemo = Old_Task.GetNodeValue("Task/BaseInfo/TaskDemo"); t.TaskClass = Old_Task.GetNodeValue("Task/BaseInfo/Class"); t.TaskType = Old_Task.GetNodeValue("Task/BaseInfo/Type"); t.RunType = Old_Task.GetNodeValue("Task/BaseInfo/RunType"); //���������·��������Ҫ����ϵͳ·�� t.SavePath = Program.getPrjPath() + Old_Task.GetNodeValue("Task/BaseInfo/SavePath"); t.UrlCount = int.Parse(Old_Task.GetNodeValue("Task/BaseInfo/UrlCount").ToString()); t.ThreadCount = int.Parse(Old_Task.GetNodeValue("Task/BaseInfo/ThreadCount")); t.Cookie = Old_Task.GetNodeValue("Task/BaseInfo/Cookie"); t.DemoUrl = Old_Task.GetNodeValue("Task/BaseInfo/DemoUrl"); t.StartPos = Old_Task.GetNodeValue("Task/BaseInfo/StartPos"); t.EndPos = Old_Task.GetNodeValue("Task/BaseInfo/EndPos"); t.WebCode = Old_Task.GetNodeValue("Task/BaseInfo/WebCode"); t.IsLogin = (Old_Task.GetNodeValue("Task/BaseInfo/IsLogin") == "True" ? true : false); t.LoginUrl = Old_Task.GetNodeValue("Task/BaseInfo/LoginUrl"); t.IsUrlEncode = (Old_Task.GetNodeValue("Task/BaseInfo/IsUrlEncode") == "True" ? true : false); t.UrlEncode = Old_Task.GetNodeValue("Task/BaseInfo/UrlEncode"); #endregion //����������ݿ�ʼ�п��ܾͳ���������ش��� //����������1.2�汾�����ӵģ������á���㵼������������1.3�汾�г��ֵ� // if (Old_Task.GetNodeValue("Task/Result/ExportType") == "") t.ExportType = ((int)cGlobalParas.PublishType.PublishTxt).ToString(); else t.ExportType = Old_Task.GetNodeValue("Task/Result/ExportType"); if (Old_Task.GetNodeValue("Task/Result/ExportFileName") == "") t.ExportFile = Program.getPrjPath() + "data\\" + t.TaskName + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + ".txt"; else t.ExportFile = Old_Task.GetNodeValue("Task/Result/ExportFileName"); if (Old_Task.GetNodeValue("Task/Result/DataSource") == "") t.DataSource = ""; else t.DataSource = Old_Task.GetNodeValue("Task/Result/DataSource"); if (Old_Task.GetNodeValue("Task/Result/DataTableName") == "") t.DataTableName = ""; else t.DataTableName = Old_Task.GetNodeValue("Task/Result/DataTableName"); if (Old_Task.GetNodeValue("Task/Result/InsertSql") == "") t.InsertSql = ""; else t.InsertSql = Old_Task.GetNodeValue("Task/Result/InsertSql"); if (Old_Task.GetNodeValue("Task/Result/ExportUrl") == "") t.ExportUrl = ""; else t.ExportUrl = Old_Task.GetNodeValue("Task/Result/ExportUrl"); if (Old_Task.GetNodeValue("Task/Result/ExportUrlCode") == "") t.ExportUrlCode = ""; else t.ExportUrlCode = Old_Task.GetNodeValue("Task/Result/ExportUrlCode"); if (Old_Task.GetNodeValue("Task/Result/ExportCookie") == "") t.ExportCookie = ""; else t.ExportCookie = Old_Task.GetNodeValue("Task/Result/ExportCookie"); //�˲�����1.3�汾�д��ڵģ���Ҫ���� //���ظ�������Ϣ if (Old_Task.GetNodeValue("Task/Advance/GatherAgainNumber") == "") t.GatherAgainNumber = 3; else t.GatherAgainNumber = int.Parse(Old_Task.GetNodeValue("Task/Advance/GatherAgainNumber")); if (Old_Task.GetNodeValue("Task/Advance/IsIgnore404") == "") t.IsIgnore404 = true; else t.IsIgnore404 = (Old_Task.GetNodeValue("Task/Advance/IsIgnore404") == "True" ? true : false); if (Old_Task.GetNodeValue("Task/Advance/IsErrorLog") == "") t.IsErrorLog = false; else t.IsErrorLog = (Old_Task.GetNodeValue("Task/Advance/IsErrorLog") == "True" ? true : false); if (Old_Task.GetNodeValue("Task/Advance/IsDelRepeatRow") == "") t.IsDelRepRow = false; else t.IsDelRepRow = (Old_Task.GetNodeValue("Task/Advance/IsDelRepeatRow") == "True" ? true : false); if (Old_Task.GetNodeValue("Task/Advance/IsExportHeader") == "") t.IsExportHeader = true; else t.IsExportHeader = (Old_Task.GetNodeValue("Task/Advance/IsExportHeader") == "True" ? true : false); if (Old_Task.GetNodeValue("Task/Advance/IsTrigger") == "") t.IsTrigger = false; else t.IsTrigger = (Old_Task.GetNodeValue("Task/Advance/IsTrigger") == "True" ? true : false); if (Old_Task.GetNodeValue("Task/Advance/TriggerType")=="") t.TriggerType = ((int)cGlobalParas.TriggerType.GatheredRun).ToString(); else t.TriggerType = Old_Task.GetNodeValue("Task/Advance/TriggerType"); DataView dw = new DataView(); int i; //�˴������У�����Ҫ����Trigger��Ϣ����ǰ����汾�в����ڣ����������п��Բ����� //dw = Old_Task.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(); // t.TriggerTask.Add(tt); // } //} ////dw = null; ////dw = new DataView(); dw = Old_Task.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 (dw[i].Row["IsNag"].ToString() == "True") { //�ڴ˴�����������������������ǰ�汾�д��ڵ���������ֻ��һ�㵼�� cNavigRule nRule = new cNavigRule(); nRule.Url = dw[i].Row["Url"].ToString(); nRule.Level =1; nRule.NavigRule = dw[i].Row["NagRule"].ToString(); w.NavigRules.Add(nRule); } else { } t.WebpageLink.Add(w); w = null; } } dw = null; dw = new DataView(); dw = Old_Task.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) { } t.WebpageCutFlag.Add(c); c = null; } } dw = null; Old_Task = null; //��ȡ���ļ���Ŀ¼���� string FilePath = Path.GetDirectoryName(FileName); if (IsSystemTask == true) { t.DeleTask(FilePath, t.TaskName); t.Save(FilePath + "\\"); } else { t.SaveTaskFile(FilePath); } t = null; }
//根据taskid修改任务的名称 public bool RenameTask(string TClass, string OldTaskName, string NewTaskName) { try { //根据任务分类获取任务的所属路径 cTaskClass tc = new cTaskClass(); string tClassPath = ""; //判断新的任务路径是否存在,如果存在则报错 if (TClass == "") { tClassPath = Program.getPrjPath() + "tasks"; } else { tClassPath = tc.GetTaskClassPathByName(TClass); } tc = null; if (File.Exists(tClassPath + "\\" + NewTaskName + ".xml")) { throw new cSoukeyException("您修改的任务名称已经存在,请重新修改!"); } cTaskIndex xmlTasks = new cTaskIndex(); if (TClass == "") { xmlTasks.GetTaskDataByClass(); } else { xmlTasks.GetTaskDataByClass(TClass); } //开始初始化此分类下的任务 int count = xmlTasks.GetTaskClassCount(); for (int i = 0; i < count; i++) { if (xmlTasks.GetTaskName(i) == NewTaskName) { xmlTasks = null; throw new cSoukeyException("您修改的任务名称已经存在,请重新修改!"); } } xmlTasks = null; //开始修改任务的名称 //先开始修改index.xml的名称 cXmlIO xmlIndex = new cXmlIO(tClassPath + "\\index.xml"); xmlIndex.EditNodeValue("TaskIndex", "Name", OldTaskName, "Name", NewTaskName); xmlIndex.Save(); xmlIndex = null; //开始修改任务的名称 cXmlIO xmlTask = new cXmlIO(tClassPath + "\\" + OldTaskName + ".xml"); xmlTask.EditNodeValue("Task/BaseInfo/Name", NewTaskName); xmlTask.Save(); xmlTask = null; File.SetAttributes(tClassPath + "\\" + OldTaskName + ".xml", System.IO.FileAttributes.Normal); File.Move(tClassPath + "\\" + OldTaskName + ".xml", tClassPath + "\\" + NewTaskName + ".xml"); } catch (System.Exception ex) { throw ex; return(false); } return(true); }
//���������������������������½�һ�����࣬����ԭ�з�������� //Ǩ�ƹ���������������Ϣ������ɾ��ԭ������ public bool RenameTaskClass(string TClassName, string NewTClassName) { try { int OldTaskClassID=0; string OldPath = GetTaskClassPathByName(TClassName); string NewPath = OldPath.Substring(0, OldPath.IndexOf(TClassName)) + NewTClassName; //�ж��µ�����·���Ƿ���ڣ���������� if (Directory.Exists (NewPath )) throw new cSoukeyException("����������·���Ѿ����ڣ�������������������ƣ�"); //ת�����·�� string NewRelativePath = cTool.GetRelativePath(NewPath); int tCount = GetTaskClassCount(); //��Ҫ�ж��½�������������Ƿ��Ѿ����� for (int i = 0; i < tCount; i++) { if (TaskClass[i].Row["Name"].ToString() == NewTClassName) { throw new cSoukeyException("��������Ѿ����ڣ�"); } if (TaskClass[i].Row["Name"].ToString() == TClassName) { //��ȡԭ�з����ID OldTaskClassID=GetTaskClassID (i); } } if (OldTaskClassID == 0) { throw new cSoukeyException("δ���ҵ���Ҫ�ķ������Ϣ��������ʧ�ܣ�"); } //��ʼ����������µ����������������� cTaskIndex xmlTasks = new cTaskIndex(); xmlTasks.GetTaskDataByClass(TClassName); //��ʼ��ʼ���˷����µ����� int count = xmlTasks.GetTaskClassCount(); cXmlIO txml; for (int i = 0; i < count; i++) { txml = new cXmlIO(OldPath + "\\" + xmlTasks.GetTaskName(i) + ".xml"); txml.EditNodeValue("Task/BaseInfo/Class", NewTClassName); txml.Save(); txml = null; } xmlTasks = null; //��ʼ��taskclass.xml�ļ��е��������������Ϣ xmlConfig.EditNodeValue("TaskClasses", "id", OldTaskClassID.ToString (), "Name", NewTClassName); xmlConfig.EditNodeValue("TaskClasses", "id", OldTaskClassID.ToString (), "Path", NewRelativePath); xmlConfig.Save(); xmlConfig = null; //��ʼ������������ʵ��·�� File.SetAttributes(OldPath, System.IO.FileAttributes.Normal); Directory.Move(OldPath, NewPath); //Directory.Delete(OldPath); } catch (System.Exception ex) { throw ex; return false; } return true; }
public void CloseLogFile() { m_PlanFile = null; }
//���ؼƻ�,���ؼƻ���ʱ����Ҫ�Լƻ���״̬����ά�� private void IniCheckPlan() { try { cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); DataView d = xmlConfig.GetData("descendant::Plans"); if (d == null) { return; } cPlan p; for (int i = 0; i < d.Count; i++) { p = new cPlan(); if (int.Parse(d[i].Row["PlanState"].ToString()) == (int)cGlobalParas.PlanState.Enabled) { p.PlanID = Int64.Parse(d[i].Row["ID"].ToString()); p.PlanName = d[i].Row["PlanName"].ToString(); p.PlanState = int.Parse(d[i].Row["PlanState"].ToString()); p.IsOverRun = d[i].Row["IsOverRun"].ToString() == "True" ? true : false; p.IsDisabled = d[i].Row["IsDisabled"].ToString() == "True" ? true : false; p.DisabledType = int.Parse(d[i].Row["DisabledType"].ToString()); p.DisabledTime = int.Parse(d[i].Row["DisabledTime"].ToString()); p.DisabledDateTime = DateTime.Parse(d[i].Row["DisabledDateTime"].ToString()); p.RunTaskPlanType = int.Parse(d[i].Row["RunTaskPlanType"].ToString()); p.EnabledDateTime = d[i].Row["EnabledDateTime"].ToString(); p.RunOnesTime = d[i].Row["RunOnesTime"].ToString(); p.RunDayTime = d[i].Row["RunDayTime"].ToString(); p.RunAMTime = d[i].Row["RunAMTime"].ToString(); p.RunPMTime = d[i].Row["RunPMTime"].ToString(); p.RunWeeklyTime = d[i].Row["RunWeeklyTime"].ToString(); p.RunWeekly = d[i].Row["RunWeekly"].ToString(); p.RunTimeCount = d[i].Row["RunTimeCount"].ToString(); p.FirstRunTime = d[i].Row["FirstRunTime"].ToString(); p.RunInterval = d[i].Row["RunInterval"].ToString(); cTaskPlan tp; DataView t = d[i].CreateChildView("Plan_Tasks")[0].CreateChildView("Tasks_Task"); for (int j = 0; j < t.Count; j++) { tp = new cTaskPlan(); tp.RunTaskType = int.Parse(t[j].Row["RunTaskType"].ToString()); tp.RunTaskName = t[j].Row["RunTaskName"].ToString(); tp.RunTaskPara = t[j].Row["RunTaskPara"].ToString(); p.RunTasks.Add(tp); } m_runTasks.Add(p); } } p = null; xmlConfig = null; //�Զ�ά���ƻ�״̬ AutoState(); } catch (System.Exception ex) { throw ex; } }
//public int GetPlanCount() //{ // return 0; //} //����һ���ƻ�,�ƻ��������� public void InsertPlan(cPlan NewPlan) { //�жϼƻ��ļ��Ƿ���ڣ�������������½� if (!IsExist()) NewIndexFile(); //�жϼƻ��Ƿ������������������Ҫ���������� cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); DataView d = xmlConfig.GetData("descendant::Plans"); if (d != null) { for (int i = 0; i < d.Count; i++) { if (NewPlan.PlanName == d[i].Row["PlanName"].ToString()) { xmlConfig = null; throw new cSoukeyException("�Ѿ����ڴ˼ƻ������ļƻ����ƣ��ƻ����Ʋ����ظ���"); } } } string pXml = CreatePlanXml(NewPlan); xmlConfig.InsertElement("Plans", "Plan", pXml); xmlConfig.Save(); xmlConfig = null; }
//���½�һ������ʱ�����ô˷��� public void New() { //this.TaskState =(int) cGlobalParas.TaskState.TaskUnStart; if (xmlConfig != null) { xmlConfig = null; } }
//����taskid����������� public bool RenameTask(string TClass,string OldTaskName, string NewTaskName) { try { //������������ȡ���������·�� cTaskClass tc = new cTaskClass(); string tClassPath = ""; //�ж��µ�����·���Ƿ���ڣ���������� if (TClass == "") { tClassPath = Program.getPrjPath() + "tasks"; } else { tClassPath = tc.GetTaskClassPathByName(TClass); } tc = null; if (File.Exists(tClassPath + "\\" + NewTaskName + ".xml")) throw new cSoukeyException("���ĵ����������Ѿ����ڣ��������ģ�"); cTaskIndex xmlTasks = new cTaskIndex(); if (TClass == "") { xmlTasks.GetTaskDataByClass(); } else { xmlTasks.GetTaskDataByClass(TClass); } //��ʼ��ʼ���˷����µ����� int count = xmlTasks.GetTaskClassCount(); for (int i = 0; i < count; i++) { if (xmlTasks.GetTaskName(i) == NewTaskName) { xmlTasks = null; throw new cSoukeyException("���ĵ����������Ѿ����ڣ��������ģ�"); } } xmlTasks = null; //��ʼ����������� //�ȿ�ʼ��index.xml������ cXmlIO xmlIndex = new cXmlIO(tClassPath + "\\index.xml"); xmlIndex.EditNodeValue("TaskIndex", "Name", OldTaskName, "Name", NewTaskName); xmlIndex.Save(); xmlIndex = null; //��ʼ����������� cXmlIO xmlTask = new cXmlIO(tClassPath + "\\" + OldTaskName + ".xml"); xmlTask.EditNodeValue("Task/BaseInfo/Name", NewTaskName); xmlTask.Save(); xmlTask = null; File.SetAttributes(tClassPath + "\\" + OldTaskName + ".xml", System.IO.FileAttributes.Normal); File.Move(tClassPath + "\\" + OldTaskName + ".xml", tClassPath + "\\" + NewTaskName + ".xml"); } catch (System.Exception ex) { throw ex; return false; } return true; }
private void ModifyPlanRunTime(Int64 PlanID, int RunTime) { cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); xmlConfig.EditNodeValue("Plans", "ID", PlanID.ToString(), "RunTimeCount", RunTime.ToString ()); xmlConfig.Save(); xmlConfig = null; }
//������������Ϣ���������ļ��������������ݵ����⣬�˷��� //��Ҫ����֧����������ʹ�� public void SaveTaskFile(string TaskPath) { //��ȡ��Ҫ���������·�� string tPath = ""; if (TaskPath == "" || TaskPath == null) { tPath = GetTaskClassPath() + "\\"; } else { tPath = TaskPath; } int i = 0; //�жϴ�·�����Ƿ��Ѿ������˴�������������ش�����Ϣ if (IsExistTaskFile(tPath + this.TaskName)) { throw new cSoukeyException("�����Ѿ����ڣ����ܽ���"); } //��ʼ����Task���� //����Task�����XML�ĵ���ʽ //��ǰ����xml�ļ�ȫ�����õ�ƴд�ַ�������ʽ,��û�в���xml���캯�� string tXml; tXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<Task>" + "<State></State>" + ///��״ֵ̬��ǰ��Ч,���ڽ�������ʹ�� "<BaseInfo>" + "<Version>1.3</Version>" + //Ĭ�ϵ�ǰ������汾��Ϊ��1.2 "<ID>" + TaskID + "</ID>" + "<Name>" + this.TaskName + "</Name>" + "<TaskDemo>" + this.TaskDemo + "</TaskDemo>" + "<Class>" + this.TaskClass + "</Class>" + "<Type>" + this.TaskType + "</Type>" + "<RunType>" + this.RunType + "</RunType>" + //ѡӴת�������·�� "<SavePath>" + cTool.GetRelativePath(this.SavePath) + "</SavePath>" + "<ThreadCount>" + this.ThreadCount + "</ThreadCount>" + "<UrlCount>" + this.UrlCount + "</UrlCount>" + "<StartPos>" + cTool.ReplaceTrans(this.StartPos) + "</StartPos>" + "<EndPos>" + cTool.ReplaceTrans(this.EndPos) + "</EndPos>" + "<DemoUrl>" + cTool.ReplaceTrans(this.DemoUrl) + "</DemoUrl>" + "<Cookie>" + cTool.ReplaceTrans(this.Cookie) + "</Cookie>" + "<WebCode>" + this.WebCode + "</WebCode>" + "<IsLogin>" + this.IsLogin + "</IsLogin>" + "<LoginUrl>" + this.LoginUrl + "</LoginUrl>" + "<IsUrlEncode>" + this.IsUrlEncode + "</IsUrlEncode>" + "<UrlEncode>" + this.UrlEncode + "</UrlEncode>" + "</BaseInfo>" + "<Result>" + "<ExportType>" + this.ExportType + "</ExportType>" + "<ExportFileName>" + this.ExportFile + "</ExportFileName>" + "<DataSource>" + this.DataSource + "</DataSource>" + "<DataTableName>" + this.DataTableName + "</DataTableName>" + "<InsertSql>" + this.InsertSql + "</InsertSql>" + "<ExportUrl>" + cTool.ReplaceTrans(this.ExportUrl) + "</ExportUrl>" + "<ExportUrlCode>" + this.ExportUrlCode + "</ExportUrlCode>" + "<ExportCookie>" + cTool.ReplaceTrans(this.ExportCookie) + "</ExportCookie>" + "</Result>"; tXml += "<Advance>" + "<GatherAgainNumber>" + this.GatherAgainNumber + "</GatherAgainNumber>" + "<IsIgnore404>" + this.IsIgnore404 + "</IsIgnore404>" + "<IsErrorLog>" + this.IsErrorLog + "</IsErrorLog>" + "<IsExportHeader>" + this.IsExportHeader + "</IsExportHeader>" + "<IsDelRepeatRow>" + this.IsDelRepRow + "</IsDelRepeatRow>" + "<IsTrigger>" + this.IsTrigger + "</IsTrigger>" + "<TriggerType>" + this.TriggerType + "</TriggerType>" + "</Advance>"; tXml += "<Trigger>"; for (i = 0; i < this.m_TriggerTask.Count; i++) { tXml += "<Task>"; tXml += "<RunTaskType>" + this.m_TriggerTask[i].RunTaskType + "</RunTaskType>"; tXml += "<RunTaskName>" + this.m_TriggerTask[i].RunTaskName + "</RunTaskName>"; tXml += "<RunTaskPara>" + this.m_TriggerTask[i].RunTaskPara + "</RunTaskPara>"; tXml += "</Task>"; } tXml += "</Trigger>"; tXml += "<WebLinks>"; if (this.WebpageLink != null) { for (i = 0; i < this.WebpageLink.Count; i++) { tXml += "<WebLink>"; tXml += "<Url>" + cTool.ReplaceTrans(this.WebpageLink[i].Weblink.ToString()) + "</Url>"; tXml += "<IsNag>" + this.WebpageLink[i].IsNavigation + "</IsNag>"; tXml += "<IsNextPage>" + this.WebpageLink[i].IsNextpage + "</IsNextPage>"; tXml += "<NextPageRule>" + cTool.ReplaceTrans(this.WebpageLink[i].NextPageRule) + "</NextPageRule>"; //Ĭ�ϲ���һ���ڵ㣬��ʾ�����ӵ�ַ��δ���вɼ�����Ϊ��ϵͳ�����������Ĭ��ΪUnGather tXml += "<IsGathered>" + (int)cGlobalParas.UrlGatherResult.UnGather + "</IsGathered>"; //�������ַ�ĵ������� if (this.WebpageLink[i].IsNavigation == true) { tXml += "<NavigationRules>"; for (int j = 0; j < this.WebpageLink[i].NavigRules.Count; j++) { tXml += "<Rule>"; tXml += "<Url>" + cTool.ReplaceTrans(this.WebpageLink[i].NavigRules[j].Url) + "</Url>"; tXml += "<Level>" + this.WebpageLink[i].NavigRules[j].Level + "</Level>"; tXml += "<NagRule>" + cTool.ReplaceTrans(this.WebpageLink[i].NavigRules[j].NavigRule) + "</NagRule>"; tXml += "</Rule>"; } tXml += "</NavigationRules>"; } tXml += "</WebLink>"; } } tXml += "</WebLinks>" + "<GatherRule>"; if (this.WebpageCutFlag != null) { for (i = 0; i < this.WebpageCutFlag.Count; i++) { tXml += "<Rule>"; tXml += "<Title>" + cTool.ReplaceTrans(this.WebpageCutFlag[i].Title) + "</Title>"; tXml += "<DataType>" + this.WebpageCutFlag[i].DataType + "</DataType>"; tXml += "<StartFlag>" + cTool.ReplaceTrans(this.WebpageCutFlag[i].StartPos) + "</StartFlag>"; tXml += "<EndFlag>" + cTool.ReplaceTrans(this.WebpageCutFlag[i].EndPos) + "</EndFlag>"; tXml += "<LimitSign>" + this.WebpageCutFlag[i].LimitSign + "</LimitSign>"; tXml += "<RegionExpression>" + cTool.ReplaceTrans(this.WebpageCutFlag[i].RegionExpression) + "</RegionExpression>"; tXml += "<ExportLimit>" + this.WebpageCutFlag[i].ExportLimit + "</ExportLimit>"; tXml += "<ExportExpression>" + cTool.ReplaceTrans(this.WebpageCutFlag[i].ExportExpression) + "</ExportExpression>"; tXml += "</Rule>"; } } tXml += "</GatherRule>" + "</Task>"; xmlConfig = new cXmlIO(); xmlConfig.NewXmlFile(tPath + this.TaskName + ".xml", tXml); xmlConfig = null; }
public Int64 InsertTaskRun(string Path, string File) { ///首先判断存放任务执行的目录是否存在 ///此目录是固定目录,存放在系统\\Task\\run string RunPath = Program.getPrjPath() + "Tasks\\run"; if (!System.IO.Directory.Exists(RunPath)) { System.IO.Directory.CreateDirectory(RunPath); } ///先将此任务的摘要信息加载到TaskRun.xml文件中 Task.cTask t = new Task.cTask(); t.LoadTask(Path + "\\" + File); //开始构造xml节点内容 LoadTaskRunData(); Int64 maxID = GetNewID(); string tRunxml = ""; tRunxml = "<TaskID>" + maxID + "</TaskID>"; tRunxml += "<TaskName>" + t.TaskName + "</TaskName>"; tRunxml += "<TaskState>" + (int)cGlobalParas.TaskState.UnStart + "</TaskState>"; tRunxml += "<TaskType>" + t.TaskType + "</TaskType>"; tRunxml += "<RunType>" + t.RunType + "</RunType>"; tRunxml += "<ExportFile>" + t.ExportFile + "</ExportFile>"; tRunxml += "<tempFile>" + t.SavePath + "\\" + t.TaskName + "-" + maxID + ".xml" + "</tempFile>"; tRunxml += "<StartDate>" + DateTime.Now + "</StartDate>"; tRunxml += "<EndDate></EndDate>"; tRunxml += "<ThreadCount>" + t.ThreadCount + "</ThreadCount>"; tRunxml += "<UrlCount>" + t.UrlCount + "</UrlCount>"; ///TrueUrlCount表示如果采集的网址中存在导航网址,则需要采集的网址是无法根据公式极端出来的 ///需要采集任务不断执行,不断根据采集的规则进行计算采集网址的总数,所以需要再次记录此值 ///记录此值的目的是为了可以更好的跟踪采集的进度,但Urlcount不能修改,因为此值要进行任务分解 ///使用,如果改变了UrlCount则可能导致任务分解失败,在运营任务初始化的时候,此值同UrlCount,此值的 ///更改在任务运营时维护 tRunxml += "<TrueUrlCount>" + t.UrlCount + "</TrueUrlCount>"; tRunxml += "<GatheredUrlCount>0</GatheredUrlCount>"; tRunxml += "<GatheredTrueUrlCount>0</GatheredTrueUrlCount>"; tRunxml += "<ErrUrlCount>0</ErrUrlCount>"; tRunxml += "<TrueErrUrlCount>0</TrueErrUrlCount>"; tRunxml += "<IsLogin>" + t.IsLogin + "</IsLogin>"; tRunxml += "<PublishType>" + t.ExportType + "</PublishType>"; xmlConfig.InsertElement("Tasks", "Task", tRunxml); xmlConfig.Save(); xmlConfig = null; ///运行区的任务xml文件的格式与Task任务格式完全一眼个,但命名方式完全不同 ///命名格式是按照Task+当前文件在Taskrun中的id来命名,这样做的目的是支持同一个任务 ///可以建立多个运行实例,也就是当这个任务运行的时候,用户也可以修改此任务后建立另 ///一个实例开始运行。 System.IO.File.Copy(Path + "\\" + File, RunPath + "\\" + "Task" + maxID + ".xml", true); //文件拷贝过去后,需要修改文件中的TaskID,以吻合TaskRun中的TaskID索引,否则 //在加载文件的时候会出错,系统用ID来做唯一索引 cXmlIO xmlFile; xmlFile = new cXmlIO(RunPath + "\\" + "Task" + maxID + ".xml"); string tID = xmlFile.GetNodeValue("Task/BaseInfo/ID"); xmlFile.EditNode("ID", tID, maxID.ToString()); xmlFile.Save(); xmlFile = null; return(maxID); }
public cTaskIndex(string xmlFile) { xmlConfig =new cXmlIO (xmlFile ); }
//��ȡһ��ִ�еļƻ� public cPlan GetSinglePlan(Int64 PlanID) { //�жϼƻ��ļ��Ƿ���ڣ�������������½� if (!IsExist()) NewIndexFile(); //�жϼƻ��Ƿ������������������Ҫ���������� cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml"); DataView d= xmlConfig.GetData("Plans", "ID", PlanID.ToString ()); DataView t = d[0].CreateChildView("Plan_Tasks")[0].CreateChildView("Tasks_Task"); cPlan p = new cPlan(); p.PlanID = Int64.Parse(d[0].Row["ID"].ToString()); p.PlanName = d[0].Row["PlanName"].ToString(); p.PlanRemark = d[0].Row["PlanRemark"].ToString(); p.PlanState = int.Parse(d[0].Row["PlanState"].ToString()); p.IsOverRun = d[0].Row["IsOverRun"].ToString() == "True" ? true : false; p.IsDisabled = d[0].Row["IsDisabled"].ToString() == "True" ? true : false; p.DisabledType = int.Parse(d[0].Row["DisabledType"].ToString()); p.DisabledTime = int.Parse(d[0].Row["DisabledTime"].ToString()); p.DisabledDateTime = DateTime.Parse(d[0].Row["DisabledDateTime"].ToString()); p.RunTaskPlanType = int.Parse(d[0].Row["RunTaskPlanType"].ToString()); p.EnabledDateTime = d[0].Row["EnabledDateTime"].ToString(); p.RunOnesTime =d[0].Row["RunOnesTime"].ToString(); p.RunDayTime = d[0].Row["RunDayTime"].ToString(); p.RunAMTime = d[0].Row["RunAMTime"].ToString(); p.RunPMTime = d[0].Row["RunPMTime"].ToString(); p.RunWeeklyTime = d[0].Row["RunWeeklyTime"].ToString(); p.RunWeekly = d[0].Row["RunWeekly"].ToString(); p.RunTimeCount = d[0].Row["RunTimeCount"].ToString(); p.FirstRunTime = d[0].Row["FirstRunTime"].ToString(); p.RunInterval = d[0].Row["RunInterval"].ToString(); cTaskPlan tp; for (int i = 0; i < t.Count; i++) { tp = new cTaskPlan(); tp.RunTaskType =int.Parse ( t[i].Row["RunTaskType"].ToString()); tp.RunTaskName = t[i].Row["RunTaskName"].ToString(); tp.RunTaskPara = t[i].Row["RunTaskPara"].ToString(); p.RunTasks.Add(tp); } xmlConfig = null; return p; }
//指定任务进行升级操作 /// <summary> /// 升级任务操作 /// </summary> /// <param name="FileName">待升级的任务文件</param> /// <param name="IsBackup">是否备份</param> /// <param name="IsTask">是否为系统任务,如果是系统任务则需要维护分类信息,如果不是就只保存文件</param> public void UpdradeTask(string FileName, bool IsBackup, bool IsSystemTask) { //判断是否进行备份 if (IsBackup == true) { if (File.Exists(FileName + ".bak")) { File.Delete(FileName + ".bak"); } File.Copy(FileName, FileName + ".bak"); } //加载任务文件 cXmlIO Old_Task = new cXmlIO(FileName); Single TaskVersion = Single.Parse("0"); cTask t = new cTask(); //判断任务版本号 try { TaskVersion = Single.Parse(Old_Task.GetNodeValue("Task/BaseInfo/Version")); } catch (System.Exception) { TaskVersion = Single.Parse("1.0"); } if (TaskVersion >= this.SupportTaskVersion) { Old_Task = null; return; } //开始新建一个任务 t.New(); #region 此部分内容是任何版本都存在的 t.TaskID = Int64.Parse(Old_Task.GetNodeValue("Task/BaseInfo/ID")); t.TaskName = Old_Task.GetNodeValue("Task/BaseInfo/Name"); t.TaskVersion = this.SupportTaskVersion; t.TaskDemo = Old_Task.GetNodeValue("Task/BaseInfo/TaskDemo"); t.TaskClass = Old_Task.GetNodeValue("Task/BaseInfo/Class"); t.TaskType = Old_Task.GetNodeValue("Task/BaseInfo/Type"); t.RunType = Old_Task.GetNodeValue("Task/BaseInfo/RunType"); //因存的是相对路径,所以要加上系统路径 t.SavePath = Program.getPrjPath() + Old_Task.GetNodeValue("Task/BaseInfo/SavePath"); t.UrlCount = int.Parse(Old_Task.GetNodeValue("Task/BaseInfo/UrlCount").ToString()); t.ThreadCount = int.Parse(Old_Task.GetNodeValue("Task/BaseInfo/ThreadCount")); t.Cookie = Old_Task.GetNodeValue("Task/BaseInfo/Cookie"); t.DemoUrl = Old_Task.GetNodeValue("Task/BaseInfo/DemoUrl"); t.StartPos = Old_Task.GetNodeValue("Task/BaseInfo/StartPos"); t.EndPos = Old_Task.GetNodeValue("Task/BaseInfo/EndPos"); t.WebCode = Old_Task.GetNodeValue("Task/BaseInfo/WebCode"); t.IsLogin = (Old_Task.GetNodeValue("Task/BaseInfo/IsLogin") == "True" ? true : false); t.LoginUrl = Old_Task.GetNodeValue("Task/BaseInfo/LoginUrl"); t.IsUrlEncode = (Old_Task.GetNodeValue("Task/BaseInfo/IsUrlEncode") == "True" ? true : false); t.UrlEncode = Old_Task.GetNodeValue("Task/BaseInfo/UrlEncode"); #endregion //从下面的内容开始有可能就出现任务加载错误, //导出部分是1.2版本中增加的,高级设置、多层导航及触发器是1.3版本中出现的 // if (Old_Task.GetNodeValue("Task/Result/ExportType") == "") { t.ExportType = ((int)cGlobalParas.PublishType.PublishTxt).ToString(); } else { t.ExportType = Old_Task.GetNodeValue("Task/Result/ExportType"); } if (Old_Task.GetNodeValue("Task/Result/ExportFileName") == "") { t.ExportFile = Program.getPrjPath() + "data\\" + t.TaskName + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + ".txt"; } else { t.ExportFile = Old_Task.GetNodeValue("Task/Result/ExportFileName"); } if (Old_Task.GetNodeValue("Task/Result/DataSource") == "") { t.DataSource = ""; } else { t.DataSource = Old_Task.GetNodeValue("Task/Result/DataSource"); } if (Old_Task.GetNodeValue("Task/Result/DataTableName") == "") { t.DataTableName = ""; } else { t.DataTableName = Old_Task.GetNodeValue("Task/Result/DataTableName"); } if (Old_Task.GetNodeValue("Task/Result/InsertSql") == "") { t.InsertSql = ""; } else { t.InsertSql = Old_Task.GetNodeValue("Task/Result/InsertSql"); } if (Old_Task.GetNodeValue("Task/Result/ExportUrl") == "") { t.ExportUrl = ""; } else { t.ExportUrl = Old_Task.GetNodeValue("Task/Result/ExportUrl"); } if (Old_Task.GetNodeValue("Task/Result/ExportUrlCode") == "") { t.ExportUrlCode = ""; } else { t.ExportUrlCode = Old_Task.GetNodeValue("Task/Result/ExportUrlCode"); } if (Old_Task.GetNodeValue("Task/Result/ExportCookie") == "") { t.ExportCookie = ""; } else { t.ExportCookie = Old_Task.GetNodeValue("Task/Result/ExportCookie"); } //此部分是1.3版本中存在的,需要升级 //加载高级配置信息 if (Old_Task.GetNodeValue("Task/Advance/GatherAgainNumber") == "") { t.GatherAgainNumber = 3; } else { t.GatherAgainNumber = int.Parse(Old_Task.GetNodeValue("Task/Advance/GatherAgainNumber")); } if (Old_Task.GetNodeValue("Task/Advance/IsIgnore404") == "") { t.IsIgnore404 = true; } else { t.IsIgnore404 = (Old_Task.GetNodeValue("Task/Advance/IsIgnore404") == "True" ? true : false); } if (Old_Task.GetNodeValue("Task/Advance/IsErrorLog") == "") { t.IsErrorLog = false; } else { t.IsErrorLog = (Old_Task.GetNodeValue("Task/Advance/IsErrorLog") == "True" ? true : false); } if (Old_Task.GetNodeValue("Task/Advance/IsDelRepeatRow") == "") { t.IsDelRepRow = false; } else { t.IsDelRepRow = (Old_Task.GetNodeValue("Task/Advance/IsDelRepeatRow") == "True" ? true : false); } if (Old_Task.GetNodeValue("Task/Advance/IsExportHeader") == "") { t.IsExportHeader = true; } else { t.IsExportHeader = (Old_Task.GetNodeValue("Task/Advance/IsExportHeader") == "True" ? true : false); } if (Old_Task.GetNodeValue("Task/Advance/IsTrigger") == "") { t.IsTrigger = false; } else { t.IsTrigger = (Old_Task.GetNodeValue("Task/Advance/IsTrigger") == "True" ? true : false); } if (Old_Task.GetNodeValue("Task/Advance/TriggerType") == "") { t.TriggerType = ((int)cGlobalParas.TriggerType.GatheredRun).ToString(); } else { t.TriggerType = Old_Task.GetNodeValue("Task/Advance/TriggerType"); } DataView dw = new DataView(); int i; //此次升级中,不需要加载Trigger信息,以前任务版本中不存在,升级过程中可以不考虑 //dw = Old_Task.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(); // t.TriggerTask.Add(tt); // } //} ////dw = null; ////dw = new DataView(); dw = Old_Task.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 (dw[i].Row["IsNag"].ToString() == "True") { //在此处理导航的升级操作,如果以前版本中存在导航规则,则只是一层导航 cNavigRule nRule = new cNavigRule(); nRule.Url = dw[i].Row["Url"].ToString(); nRule.Level = 1; nRule.NavigRule = dw[i].Row["NagRule"].ToString(); w.NavigRules.Add(nRule); } else { } t.WebpageLink.Add(w); w = null; } } dw = null; dw = new DataView(); dw = Old_Task.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) { } t.WebpageCutFlag.Add(c); c = null; } } dw = null; Old_Task = null; //获取此文件的目录传入 string FilePath = Path.GetDirectoryName(FileName); if (IsSystemTask == true) { t.DeleTask(FilePath, t.TaskName); t.Save(FilePath + "\\"); } else { t.SaveTaskFile(FilePath); } t = null; }
public void OpenLogFile() { if (!IsExist()) NewLogFile(); m_PlanFile = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\RunLog.xml"); }