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(); } }
public void ReaddSpecificErrors() { // ARRANGE var workerThreads = 1; var worker = new BackgroundWorkerQueue(workerThreads); var exceptionThrowingWork = new ExceptionThrowingWork(); var longRunningWorkProcessing = new LongRunningWork(); var longRunningWorkInBacklog = new LongRunningWork(); worker.Enqueue(exceptionThrowingWork); worker.Enqueue(longRunningWorkProcessing); worker.Enqueue(longRunningWorkInBacklog); // wait for a bit Thread.Sleep(500); var status = worker.Status(); // PRECONDITIONS ASSERT CollectionAssert.IsNotEmpty(status.Failed); // ACT worker.ReAddFailed(new List<IWork>() { exceptionThrowingWork }); // ASSERT var actual = worker.Status(); CollectionAssert.IsEmpty(actual.Failed); CollectionAssert.Contains(actual.Processing, longRunningWorkProcessing); CollectionAssert.Contains(actual.Backlog, longRunningWorkInBacklog); CollectionAssert.Contains(actual.Backlog, exceptionThrowingWork); }