Example #1
0
        private void RunSingleQuery()
        {
            // Test function to scrape a single office

            var search = new FormSearch
            {
                ElectionYear = "2018",
                OfficeTypeId = "120",
                OfficeName   = "State%20Senate",
                District     = "",
                Circuit      = "",
                Division     = "",
                County       = "",
                City         = "",
                FilerId      = ""
            };

            backgroundWorkerScrape.ReportProgress(1, "Begin new search with FormSearch : " + Environment.NewLine + search);

            if (!UpdateCandidates.ReadFirstPage(search))
            {
                backgroundWorkerScrape.ReportProgress(1, UpdateCandidates.CurrentStatus.LastOpMessage);
                return;
            }

            var candidates = UpdateCandidates.Candidates;

            backgroundWorkerScrape.ReportProgress(2, UpdateCandidates.CurrentStatus.LastOpMessage + Environment.NewLine);

            while (UpdateCandidates.CurrentStatus.LastPageCompleted < UpdateCandidates.CurrentStatus.TotalPages)
            {
                var finished = UpdateCandidates.ReadSubsequentPage(search);
                backgroundWorkerScrape.ReportProgress(2, UpdateCandidates.CurrentStatus.LastOpMessage + Environment.NewLine);
            }
        }
Example #2
0
        // +++++++++++++++++++++++ Background worker events +++++++++++++++++++++++

        private void BackgroundWorkerScrape_DoWork(object sender, DoWorkEventArgs e)
        {
            // Array = {0-Operation enum, 1-Year string, 2-Election string}

            var sendingWorker = (BackgroundWorker)sender;   // Capture the BackgroundWorker that fired the event
            var arrObjects    = (object[])e.Argument;       // Collect the array of objects the we received from the main thread

            // Get the input values from inside the objects array, don't forget to cast
            var scrapeOp   = (ScrapeOp)arrObjects[0];
            var year       = (string)arrObjects[1];
            var electionId = (string)arrObjects[2];

            var timer = Stopwatch.StartNew();

            var scrapeResult = new ScrapeResult
            {
                Operation = scrapeOp
            };

            switch (scrapeOp)
            {
            case ScrapeOp.Elections:

                var formSrchSos = new FormSearchSos(year.ToString());
                scrapeResult.ScrapeStat = UpdateCandidates.GetElections(formSrchSos);      // returns ScrapeStatus

                break;

            case ScrapeOp.Candidates:
                var formSrchSosCand = new FormSearchSos(year, electionId);
                scrapeResult.ScrapeStat = UpdateCandidates.GetCandidates(formSrchSosCand);
                break;

            default:
                break;
            }

//            scrapeResult.SequenceStat = seqStatus;
            scrapeResult.ElapsedTime = timer.Elapsed.ToString();
            e.Result = scrapeResult;
        }