Ejemplo n.º 1
0
        long receive2 = 0;                                              //若干时间差后获得的数据

        /// <summary>
        /// 构造函数
        /// </summary>
        public HunterDownload(Hunter _p)
        {
            hunterProject = _p;
            hunterConsole = _p.mHunterConsole;
            database      = _p.xmlDatabase;
            pInfo         = _p.projectInfo;
            strategy      = _p.projectInfo.strategy;
        }
Ejemplo n.º 2
0
 public HunterUri(Hunter h)
 {
     strategy = h.projectInfo.strategy;
     if (h.projectInfo.index.ToString() == h.projectInfo.strategy.StrategyData.configuration.StartIndex)
     {
         urlAddress = h.projectInfo.strategy.GetFirstSearchURL();
     }
     else
     {
         urlAddress = h.projectInfo.strategy.GetSearchURL(h.projectInfo.index, h.projectInfo.strategy.Keywords[h.projectInfo.strategy.CurrentKeywordProgress]);
     }
     mHunterConsole = h.mHunterConsole;
     uriQueue       = h.uriQueue;
 }
Ejemplo n.º 3
0
        public static ProjectInfo LoadProject(HunterConsole c, string pjPath, string _strategyPath, bool loadKeywords)
        {
            XmlSerializer ser    = new XmlSerializer(typeof(ProjectInfo));
            FileStream    f      = new FileStream(pjPath, FileMode.Open, FileAccess.Read);
            StreamReader  sr     = new StreamReader(f, Encoding.UTF8);
            ProjectInfo   result = (ProjectInfo)ser.Deserialize(sr);

            result.mHunterConsole = c;
            result.projectPath    = pjPath;
            result.strategyPath   = _strategyPath;
            result.strategy       = new Strategy(result, loadKeywords); //一个百度搜索策略
            result.CurrentMode    = result.mode;
            f.Close();

            result.DatabaseHelper = new HunterDatabaseHelper(result);
            return(result);
        }
Ejemplo n.º 4
0
 public ProjectInfo(HunterConsole c, string pjPath, string _strategyPath)
 {
     mHunterConsole = c;
     projectPath    = pjPath;
     strategyPath   = _strategyPath;
 }
Ejemplo n.º 5
0
        //asReflectionObject 表示此编辑器是用反射、序列化来处理文本,还是作为普通文本编辑器来处理文本
        public HunterEditor(HunterConsole c, HunterConfig config, String LoadFile, bool AsAModel, String fileFilter, bool asReflectionObject, Type objectType, object loadObject, Hunter3.HunterRichTextBox.TextType textType)
        {
            FileFilter              = fileFilter;
            this.AsAModel           = AsAModel;
            this.LoadFile           = LoadFile;
            ObjectType              = objectType;
            Config                  = config;
            Console                 = c;
            this.AsReflectionObject = asReflectionObject;
            LoadObject              = loadObject;
            InitializeComponent();

            hSearchBar.Init(hTextBox, tsLabel, HunterConfig.ColorBarForeColor);
            hHTMLGetterBar.Init(hTextBox, HunterConfig.ColorBarForeColor);
            hTextBox.ContentType = textType;
            tsLabel.BackColor    = Color.Transparent;
            FormBorderStyle      = FormBorderStyle.Sizable;
            MainToolStrip        = msMenu;
            try
            {
                if (LoadFile != null)
                {
                    hTextBox.LoadFile(LoadFile);
                    if (AsAModel)
                    {
                        FileSaved = false;
                    }
                    else
                    {
                        Filename = LoadFile;
                    }

                    ClearDirty();
                }
            }
            catch (Exception ex)
            {
                Console.WriteException(ex);
            }

            if (!AsReflectionObject)
            {
                sContainer.Panel2Collapsed = true;
            }
            else
            {
                try
                {
                    RefreshXML();
                    LoadProperty();
                }
                catch (Exception ex)
                {
                    Console.WriteException(ex);
                }
            }

            FormClosing += new FormClosingEventHandler(HunterEditor_FormClosing);
            propertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid_PropertyValueChanged);
            hTextBox.SelectionChanged         += new EventHandler(hTextBox_SelectionChanged);
            hTextBox.TextChanged += new EventHandler((object s, EventArgs ea) =>
            {
                if (hTextBox.Modified)
                {
                    FileSaved = false;
                    Text      = CaptionFilename + " *";
                }
                RefreshUI();
                RefreshPropertyGrid();
            });
            RefreshUI();
        }
Ejemplo n.º 6
0
        public Hunter(HunterConsole oh, HunterConfig config, ProjectInfo _pj, HunterForm main)
        {
            try
            {
                MainForm       = main;
                Error          = false;
                mHunterConsole = oh;
                projectInfo    = _pj;
                mHunterConfig  = config;
                ProxyFetcher   = new HunterProxyFetcher(AvailableProxies);
                projectInfo    = ProjectInfo.LoadProject(_pj.mHunterConsole, _pj.projectPath, _pj.strategyPath, true);

                downloadThreadNum = int.Parse(projectInfo.threadnum);
                hunterThreads     = new HunterDownloadThread[downloadThreadNum];

                //获取代理的线程
                ProxyGetThreads = new Thread[downloadThreadNum];

                if (mHunterConfig.UseProxy == true)
                {
                    FileStream   fs = new FileStream("proxy.hip", FileMode.Open, FileAccess.Read);
                    StreamReader sr = new StreamReader(fs);
                    ProxyText = sr.ReadToEnd();
                    sr.Close();
                    fs.Close();
                    AllProxies = HunterProxy.GetProxy(ProxyText, mHunterConfig.ProxyFilterKeywords);
                }

                mHunterConsole.WriteMessage(projectInfo.ConfigInformation());
                mHunterConsole.WriteMessage("");
                mHunterConsole.WriteMessage(projectInfo.strategy.GetStrategyInformation());

                xmlDatabase = new XMLDatabase(projectInfo.database, mHunterConsole);
                xmlDatabase.openDatabase();

                try
                {
                    if (downloadThreadNum <= 0)
                    {
                        mHunterConsole.WriteMessage("配置错误:下载线程数不能小于0。");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    mHunterConsole.WriteException(ex);
                    return;
                }

                for (int i = 0; i < hunterThreads.Length; i++)
                {
                    hunterThreads[i] = new HunterDownloadThread();
                    hunterThreads[i].downloadThread = new Thread(threadDownloadUris);
                }

                if (mHunterConfig.UseProxy)
                {
                    for (int i = 0; i < ProxyGetThreads.Length; i++)
                    {
                        ProxyGetThreads[i] = new Thread(GetAvaliableProxies);
                    }
                }

                if (projectInfo.strategy.Keywords.Count <= 0)
                {
                    projectInfo.mHunterConsole.WriteMessage("没有找到关键字,任务取消。");
                    Error = true;
                    return;
                }

                thHuntUris = new Thread(threadHuntUris);
                thHuntUris.SetApartmentState(ApartmentState.STA);

                hUri = new HunterUri(this);
                projectInfo.strategy.RecordFirstWord();

                mHunterConsole.WriteMessage("下载线程总数:" + hunterThreads.Length);
                mHunterConsole.WriteMessage("读取配置完毕。");
                mHunterConsole.WriteMessage("正在运行任务...");
            }
            catch (Exception e)
            {
                mHunterConsole.WriteException(e);
            }
        }