Ejemplo n.º 1
0
        public void PrepareReports()
        {
            var dealershipList = GetDealershipList();
            var outstanding = new List<DataCollector>();
            var processing = new List<DataCollector>();
            var failed = new List<DataCollector>();

            var dataHub = new DataHub();
            CollectDealershipData(dealershipList, dataHub);
        }
Ejemplo n.º 2
0
        private void CollectDealershipData(List<string[]> dealershipList, DataHub dataHub)
        {
            dealershipDataSet = new List<DealershipData>();
            var workerThreads = 99;
            using (var worker = new BackgroundWorkerQueue(workerThreads))
            {
                foreach (var dealership in dealershipList)
                {
                    var work = new DataCollector(dealership[0], new Uri(dealership[1]));
                    worker.Enqueue(work);
                }

                dataHub.SendTotal(dealershipList.Count);
                var completed = 0;
                var status = worker.Status();
                do
                {
                    if (status.Failed.Any())
                        worker.ReAddFailed(status.Failed);
                    Thread.Sleep(1000);
                    status = worker.Status();

                    if (Monitor.TryEnter(theLock, 100))
                    {
                        try
                        {
                            completed = dealershipDataSet.Count;
                        }
                        finally
                        {
                            Monitor.Exit(theLock);
                        }
                    }

                    dataHub.SendProgress(completed, status.Processing.Count(), status.Failed.Count());
                } while (status.Backlog.Any() || status.Processing.Any() || status.Failed.Any());
                worker.Stop();
                worker.ClearErrors();
                dataHub.CompleteDataCollection();
            }
        }