示例#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 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();
        }
示例#3
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();
        }
示例#4
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;
        }
示例#5
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;
        }
示例#6
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;
        }
示例#7
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);
        }
示例#8
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;
        }
示例#9
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);
        }
示例#10
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;
        }
示例#11
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);
        }
示例#12
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;
        }
示例#13
0
 public void InsertTaskIndex(string strXml)
 {
     xmlConfig.InsertElement("TaskIndex", "Task", strXml);
     xmlConfig.Save();
 }
        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;
        }