コード例 #1
0
ファイル: frmMain.cs プロジェクト: nolanlum/4chanscraper
        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();
        }
コード例 #2
0
ファイル: frmMain.cs プロジェクト: nolanlum/4chanscraper
        private void mnuMain_ScraperConf_Click(object sender, EventArgs e)
        {
            Dialogs.frmInputDialog input = new Scraper.Dialogs.frmInputDialog("Enter the amount of time between automatic scrapes, with a time unit following the number. (h=hour,m=minute,s=second)\nYou may choose any combination of the units.\nEx: 30s = 30 seconds; 5m30s = 5 minutes, 30 seconds");
            TimeSpan sp = new TimeSpan(this.timerAutoScrape.Interval * TimeSpan.TicksPerMillisecond);
            input.InputText = string.Format("{0}h{1}m{2}s", sp.Hours, sp.Minutes, sp.Seconds).Replace("0h", "").Replace("0m", "").Replace("0s", "");
            input.ShowDialog();

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

            Regex h = new Regex("([0-9]*)h", RegexOptions.IgnoreCase), m = new Regex("([0-9]*)m", RegexOptions.IgnoreCase), s = new Regex("([0-9]*)s", RegexOptions.IgnoreCase);
            Match hm = h.Match(timestring), mm = m.Match(timestring), sm = s.Match(timestring);
            int newInterval = 0;

            if (hm.Success)
                newInterval += int.Parse(hm.Groups[1].Value) * 3600000;
            if (mm.Success)
                newInterval += int.Parse(mm.Groups[1].Value) * 60000;
            if (sm.Success)
                newInterval += int.Parse(sm.Groups[1].Value) * 1000;

            if (newInterval == 0)
                Program._genericMessageBox("There was an error parsing your input; ensure you specified a valid time string.", MessageBoxIcon.Exclamation);
            else
                this.timerAutoScrape.Interval = newInterval;
        }