Example #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;
        }
        //ָ�����������������
        /// <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;
        }
Example #3
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���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;
        }
Example #4
0
        //指定任务进行升级操作
        /// <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;
        }