Example #1
0
        /// <summary>
        /// Read the function
        /// </summary>
        public void Read()
        {
            // Request the first page
            var urlPage1 = GetApiPerPage(1);
            var document = RequestXmlResponse(urlPage1);

            // Read header
            var rootNode = document.SelectSingleNode(config.RootXPath, namespaceManager);

            TotalPages = Convert.ToInt32(rootNode.Attributes["pages"].Value);

            var ApiRequestList = new List <string>();

            ForLoop.Run(2, TotalPages, (i) => ApiRequestList.Add(GetApiPerPage(i)));

            // Tasks
            //var taskList = new List<Task>();
            tasksConsumerService.Enqueue(
                () => ReadNodes(urlPage1, document.SelectNodes(config.XPathDataNodes, namespaceManager)));
            foreach (var api in ApiRequestList)
            {
                tasksConsumerService.Enqueue(() => LoadAndRead(api));
            }

            //taskList.ForEach(task => task.Start());
            //await Task.WhenAll(taskList.ToArray());
            //taskList.ForEach(task => task.Start());

            OnCompleted();

            //Task.WaitAll(taskList.ToArray());
        }
Example #2
0
        /// <summary>
        /// Read the function
        /// </summary>
        public void Read()
        {
            // Request the first page
            var urlPage1  = GetApiPerPage(1);
            var xmlParser = RequestXmlResponse(urlPage1);

            // Read header
            xmlParser.Select(config.RootXPath);
            TotalPages = Convert.ToInt32(xmlParser.GetAttribute("pages"));

            var ApiRequestList = new List <string>();

            ForLoop.Run(2, TotalPages, (i) => ApiRequestList.Add(GetApiPerPage(i)));

            // Tasks
            xmlParser.Select(config.XPathDataNodes);
            taskQueue.SendAsync(new WBWebArgs()
            {
                urlPage   = urlPage1,
                XmlParser = xmlParser
            });

            foreach (var api in ApiRequestList)
            {
                taskQueue.SendAsync(new WBWebArgs()
                {
                    urlPage = api
                });
            }

            taskQueue.Complete();
            taskQueue.Completion.Wait();

            batchResultBlock.Complete();
            persistenceAction.Completion.Wait();

            OnCompleted();
        }