Beispiel #1
0
        //加载指定任务的信息
        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 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 ;
        }
        //����ָ���������Ϣ
        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;
        }
        //ָ�����������������
        /// <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;
        }
        //指定任务进行升级操作
        /// <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;
        }
Beispiel #6
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);
        }