Example #1
0
        private static void commandsDetailsGetterWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            List <string> urlRefs = (List <string>)e.Argument;

            List <Ligne> results = new List <Ligne>();

            int done = 0;

            foreach (string url in urlRefs)
            {
                // TODO retrieve the page
                StringDictionary sd = new StringDictionary();
                sd.Add(NetworkConstants.PARAM_COMMAND_DETAILS_RELATIVE_URL, url);
                XmlDocument doc = NetworkInterface.retrieve(NetworkInterface.RequestType.COMMAND_DETAIL, sd);

                results.AddRange(DetailCommandeParser.parseCommandDetails(doc));

                int page = 1; // Number of the page from the command details we're looking at.

                while (ParsingUtils.exist("detection_detail_commande_pages_restantes", doc))
                {
                    ++page;
                    sd = new StringDictionary();
                    sd.Add(NetworkConstants.PARAM_COMMAND_DETAILS_RELATIVE_URL, url);
                    sd.Add(NetworkConstants.PARAM_LIST_PAGE, page.ToString());
                    doc = NetworkInterface.retrieve(NetworkInterface.RequestType.COMMAND_DETAIL, sd);
                    results.AddRange(DetailCommandeParser.parseCommandDetails(doc));
                }

                // This command is over, we update the progress bar.
                ++done;
                worker.ReportProgress(done * 100 / urlRefs.Count);
            }

            e.Result = results;
        }