Ejemplo n.º 1
0
        private void mnuMain_ScraperManAdd_Click(object sender, EventArgs e)
        {
            Dialogs.frmInputDialog input = new Scraper.Dialogs.frmInputDialog("Enter the URL or thread ID of a thread in the board.");
            input.ShowDialog();

            string str = input.InputText.Trim();
            if (str == "")
                return;

            int id = 0;
            if (!int.TryParse(str, out id))
            {
                Match m = frmMain.threadIdR.Match(str);
                if (m.Success)
                    id = int.Parse(m.Groups[1].Value);
            }

            if (id == 0)
                return;

            System.Net.HttpWebRequest req = System.Net.WebRequest.Create(this._db.URL + (this._db.URL.EndsWith("/") ? "" : "/") + "res/" + id) as System.Net.HttpWebRequest;
            req.Credentials = System.Net.CredentialCache.DefaultCredentials;
            req.Method = "HEAD";
            System.Net.HttpWebResponse resp = req.GetResponse() as System.Net.HttpWebResponse;
            if (resp.StatusCode != System.Net.HttpStatusCode.OK)
            {
                Program._genericMessageBox("The thread you specified was not found. Please check your input.", MessageBoxIcon.Exclamation); return;
            }
            resp.Close();

            if (this._threadParse != null && this._threadParse.IsAlive)
            {
                Program._genericMessageBox("A metadata scrape is already in progress. Please wait until the current metadata scrape is complete.", MessageBoxIcon.Warning); return;
            }

            Thread t = new Thread(id);
            this._threadParse = new SysThread(new ThreadStart(delegate()
            {
                this.Invoke(new __UpdateStatusText(this.UpdateStatusText), "Grabbing metadata for 1 thread...");
                try
                {
                    using (BoardParser bp = new BoardParser(this._db.URL))
                    {
                        bp.CrawlThread(t);
                    }
                }
                catch
                {
                    Program._genericMessageBox("Crawling the thread failed. It may have been 404'd.", MessageBoxIcon.Error);
                }
            }));

            this._threadParse.Start();
            while (this._running && this._threadParse.IsAlive)
            {
                Application.DoEvents();
                SysThread.Sleep(50);
            }

            this._db.AddThread(t);
            this.DrawDatabaseTree(this._db);

            this._crawlThread(this._db[id], this._db.ImageDir);
            _statusLoopDownloading();
        }
Ejemplo n.º 2
0
        void cmTree_Rescrape_Click(object sender, EventArgs e)
        {
            if (this.treePostWindowMouseAt == null) return;

            if (this.treePostWindowMouseAt.Tag.Equals("thread"))
            {
                if (this._threadParse != null && this._threadParse.IsAlive)
                {
                    Program._genericMessageBox("A metadata scrape is already in progress. Please wait until the current metadata scrape is complete.", MessageBoxIcon.Warning); return;
                }

                Thread t = this._db[this.treePostWindowMouseAt.Text];
                if (t == null) return;

                this._threadParse = new SysThread(new ThreadStart(delegate()
                {
                    this.Invoke(new __UpdateStatusText(this.UpdateStatusText), "Grabbing metadata for 1 thread...");
                    try
                    {
                        using (BoardParser bp = new BoardParser(this._db.URL))
                        {
                            Thread tt = new Thread(t.Id);
                            bp.CrawlThread(tt);
                            t += tt;
                        }
                    }
                    catch
                    {
                        Program._genericMessageBox("Crawling the thread failed. It may have been 404'd.", MessageBoxIcon.Error);
                    }
                    this._db[this.treePostWindowMouseAt.Text] = t;
                }));

                this._threadParse.Start();
                while (this._running && this._threadParse.IsAlive)
                {
                    Application.DoEvents();
                    SysThread.Sleep(50);
                }

                this.DrawDatabaseTree(this._db);
                this.treePostWindow.SelectedNode = this.treePostWindowMouseAt;

                this._crawlThread(t, this._db.ImageDir);
                _statusLoopDownloading();
            }
        }