Пример #1
0
        //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;
        }
Пример #2
0
        //修改制定计划的名称
        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);
        }
Пример #3
0
        //增加分类节点,如果添加成功,则返回添加成功后的分类节点ID
        //系统中存储的路径全部都是相对路径,不允许存储绝对路径
        //系统参数是绝对路径,绝对路径到相对路径的转换在方法在内部完成
        //系统对外看都是绝对路径
        public int AddTaskClass(string TaskClassName, string TaskClassPath)
        {
            //转换相对路径
            TaskClassPath = cTool.GetRelativePath(TaskClassPath);

            int tCount = GetTaskClassCount();

            //需要判断新建立的任务分类是否已经存在
            for (int i = 0; i < tCount; i++)
            {
                if (TaskClass[i].Row["Name"].ToString() == TaskClassName)
                {
                    throw new cSoukeyException("任务分类已经存在!");
                }
            }

            string strTaskClass = "";
            int    MaxID        = 0;

            if (tCount > 0)
            {
                int index = TaskClass.Count - 1;
                MaxID = int.Parse(TaskClass[index].Row["id"].ToString()) + 1;
            }
            else
            {
            }

            strTaskClass  = "<id>" + MaxID + "</id>";
            strTaskClass += "<Name>" + TaskClassName + "</Name>";
            strTaskClass += "<Path>" + TaskClassPath + "</Path>";
            xmlConfig.InsertElement("TaskConfig/TaskClasses", "TaskClass", strTaskClass);
            xmlConfig.Save();


            //建立物理的任务分类的目录和索引文件
            if (!System.IO.Directory.Exists(TaskClassPath))
            {
                System.IO.Directory.CreateDirectory(TaskClassPath);
            }

            Task.cTaskIndex tIndex = new Task.cTaskIndex();
            tIndex.NewIndexFile(TaskClassPath);
            tIndex = null;

            return(MaxID);
        }
Пример #4
0
        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;
        }
Пример #5
0
        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;
        }
Пример #6
0
        public void DelPlan(string PlanID)
        {
            //判断计划是否重名,如果重名则需要进行名称修改
            cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml");

            //删除计划节点
            xmlConfig.DeleteChildNodes("Plans", "ID", PlanID);
            xmlConfig.Save();
            xmlConfig = null;
        }
Пример #7
0
        public void DelPlan(string PlanID)
        {
            //�жϼƻ��Ƿ������������������Ҫ���������޸�
            cXmlIO xmlConfig = new cXmlIO(Program.getPrjPath() + "tasks\\plan\\plan.xml");

            //ɾ���ƻ��ڵ�
            xmlConfig.DeleteChildNodes("Plans", "ID", PlanID);
            xmlConfig.Save();
            xmlConfig = null;
        }
Пример #8
0
        public void InsertLog(cGlobalParas.LogType lType, string PlanID, string PlanName, cGlobalParas.RunTaskType rType, string FileName, string Para)
        {
            string strXml = "<LogType>" + ((int)lType).ToString() + "</LogType>" +
                            "<PlanID>" + PlanID + "</PlanID>" +
                            "<PlanName>" + PlanName + "</PlanName>" +
                            "<FileName>" + FileName + "</FileName>" +
                            "<FilePara>" + Para + "</FilePara>" +
                            "<TaskType>" + ((int)rType).ToString() + "</TaskType>" +
                            "<RunTime>" + DateTime.Now.ToString() + "</RunTime>";

            m_PlanFile.InsertElement("Logs", "Log", strXml);
            m_PlanFile.Save();
        }
Пример #9
0
        //插入一个计划索引
        //插入计划是需要判断计划的状态,通常情况下,新建计划都是有效的。
        //当前计划中有生效时间,但此时间当前并不做计划状态的判断
        public void InsertPlanIndex(string strXml, cGlobalParas.PlanState pState)
        {
            switch (pState)
            {
            case cGlobalParas.PlanState.Disabled:
                xmlConfig.InsertElement("PlanIndex\\Disabled", "Plan", strXml);
                break;

            case cGlobalParas.PlanState.Enabled:
                xmlConfig.InsertElement("PlanIndex\\Enabled", "Plan", strXml);
                break;

            case cGlobalParas.PlanState.Expired:
                xmlConfig.InsertElement("PlanIndex\\Expired", "Plan", strXml);
                break;

            default:
                break;
            }

            xmlConfig.Save();
        }
Пример #10
0
        ///保存运行的任务,主要是保存当前运行的状态
        ///任务保存需要同时保存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;
        }
Пример #11
0
        public Int64 InsertTaskComplete(Int64 TaskID, cGlobalParas.GatherResult tSate)
        {
            ///首先判断存放任务执行的目录是否存在
            ///此目录是固定目录,存放在系统\\data
            string cPath = Program.getPrjPath() + "data";

            if (!System.IO.Directory.Exists(cPath))
            {
                System.IO.Directory.CreateDirectory(cPath);
            }

            ///先将此任务的摘要信息加载到index.xml文件中
            Task.cTaskRun t = new Task.cTaskRun();
            t.LoadSingleTask(TaskID);

            //开始构造xml节点内容
            LoadTaskData();
            //int MaxID=GetCount () + 1;

            string txml = "";

            txml  = "<TaskID>" + t.GetTaskID(0) + "</TaskID>";
            txml += "<TaskName>" + t.GetTaskName(0) + "</TaskName>";
            txml += "<TaskState>" + tSate + "</TaskState>";
            txml += "<TaskType>" + (int)t.GetTaskType(0) + "</TaskType>";
            txml += "<RunType>" + (int)t.GetTaskRunType(0) + "</RunType>";
            txml += "<ExportFile>" + t.GetExportFile(0) + "</ExportFile>";
            txml += "<tempFile>" + t.GetTempFile(0) + "</tempFile>";
            txml += "<UrlCount>" + t.GetUrlCount(0) + "</UrlCount>";
            txml += "<GatheredUrlCount>" + t.GetGatheredUrlCount(0) + "</GatheredUrlCount>";
            txml += "<IsLogin>" + t.GetIsLogin(0) + "</IsLogin>";
            txml += "<PublishType>" + (int)t.GetPublishType(0) + "</PublishType>";

            xmlConfig.InsertElement("Tasks", "Task", txml);
            xmlConfig.Save();

            return(TaskID);
        }
Пример #12
0
        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;
        }
Пример #13
0
        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;
        }
Пример #14
0
        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;
        }
Пример #15
0
        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;
        }
Пример #16
0
        //任务分类改名,任务分类改名就是新建一个分类,并把原有分类的任务都
        //迁移过来,并修改任务信息的任务,并删除原有内容
        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);
        }
Пример #17
0
        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;
        }
Пример #18
0
        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;
        }
Пример #19
0
        //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;
        }
Пример #20
0
        //根据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);
        }
Пример #21
0
        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 ;
        }
Пример #22
0
        /// 重置采集任务为未启动状态
        internal void ResetTaskData()
        {
            // 停止任务
            //Stop();

            m_TaskData.GatheredUrlCount  = 0;
            m_TaskData.GatherErrUrlCount = 0;

            m_TaskData.GatheredTrueUrlCount    = 0;
            m_TaskData.GatheredTrueErrUrlCount = 0;

            //修改taskrun文件中,此文件索引的采集地址和出错地址为0
            string runFileindex = Program.getPrjPath() + "tasks\\taskrun.xml";
            cXmlIO cxml         = new cXmlIO(runFileindex);

            cxml = new cXmlIO(runFileindex);

            //还原数据需要将实际需要采集的网址数量初始化为UrlCount
            cxml.EditTaskrunValue(this.TaskID.ToString(), cGlobalParas.TaskState.UnStart, "0", "0", "0", "0", m_TaskData.UrlCount.ToString());
            cxml.Save();
            cxml = null;

            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 += "<IsNextPage>" + m_TaskData.Weblink[i].IsNextpage + "</IsNextPage>";
                tXml += "<NextPageRule>" + cTool.ReplaceTrans(m_TaskData.Weblink[i].NextPageRule) + "</NextPageRule>";
                tXml += "<IsGathered>" + (int)cGlobalParas.UrlGatherResult.UnGather + "</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>" + m_TaskData.Weblink[i].NavigRules[j].Url + "</Url>";
                        tXml += "<Level>" + m_TaskData.Weblink[i].NavigRules[j].Level + "</Level>";
                        tXml += "<NagRule>" + m_TaskData.Weblink[i].NavigRules[j].NavigRule + "</NagRule>";
                        tXml += "</Rule>";
                    }
                    tXml += "</NavigationRules>";
                }

                tXml += "</WebLink>";

                m_TaskData.Weblink[i].IsGathered = (int)cGlobalParas.UrlGatherResult.UnGather;
            }

            string FileName = Program.getPrjPath() + "tasks\\run\\task" + m_TaskData.TaskID + ".xml";
            cXmlIO cxml1    = new cXmlIO(FileName);

            cxml1.DeleteNode("WebLinks");
            cxml1.InsertElement("Task", "WebLinks", tXml);
            cxml1.Save();
            cxml1 = null;

            //删除临时存储的采集数据xml文件
            string tmpFileName = m_TaskData.SavePath + "\\" + m_TaskData.TaskName + "-" + m_TaskData.TaskID + ".xml";

            if (File.Exists(tmpFileName))
            {
                File.Delete(tmpFileName);
            }

            Task.cTaskRun t = new Task.cTaskRun();
            t.LoadSingleTask(m_TaskData.TaskID);
            m_TaskData.UrlCount = t.GetUrlCount(0);
            t = null;

            //m_TaskData.TaskSplitData.Clear ();
            //m_IsDataInitialized = false;
        }
Пример #23
0
        //����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;
        }
Пример #24
0
        //���������������������������½�һ�����࣬����ԭ�з��������
        //Ǩ�ƹ��������޸�������Ϣ�����񣬲�ɾ��ԭ������
        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;
        }
Пример #25
0
        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);
        }
Пример #26
0
 public void InsertTaskIndex(string strXml)
 {
     xmlConfig.InsertElement("TaskIndex", "Task", strXml);
     xmlConfig.Save();
 }