/// <summary> /// Continues monitoring the list of tasks for failures. While no failures occur, it checks the given buffers for any remaining items. When empty it signals the /// m_rowbuilder object and then it monitors the given number of tasks in the list starting at given index. /// </summary> /// <param name="tasks"></param> /// <param name="indexOfTask"></param> /// <param name="numTasks"></param> /// <param name="buffers"></param> /// <returns></returns> protected async Task UnwindRowBuilder(List <Task> tasks, int indexOfTask, int numTasks, List <BoundedConcurrentQueu <object[]> > buffers) { while (! (tasks.Any( task => task.IsFaulted))) { //if any buffer in the list has anything in it if (buffers.Any( buffer => buffer.Any())) { await Task.Delay(DefaultMonitoringDelayInMilliSeconds); } else { m_RowBuilder.SignalCompletion(); await Task.WhenAll(tasks.GetRange(indexOfTask, numTasks)); return; } } GatherExceptionsAndThrow(tasks); }
public void RecordToRowTransformerTest() { string[] columnNames = new string[] { "First Name", "Surname", "Age" }; RecordToRowTransformer rowFactory = new RecordToRowTransformer(columnNames); object[] data = new object[3] { new object[] { "John", "Doe", 35 }, new object[] { "Jane", "Doe", 36 }, new object[] { "Frenk", "Tank, de", 19 } }; ConcurrentBag <object[]> input = new ConcurrentBag <object[]>(); for (int i = 0; i < 3; i++) { input.Add((object[])data[i]); } ConcurrentBag <Row> output = new ConcurrentBag <Row>(); ManualResetEvent pause = new ManualResetEvent(true); Progress <int> progress = new Progress <int>(); progress.ProgressChanged += progresshandler; var action = rowFactory.GetReportingPausableWorkItem(); Task work = Task.Factory.StartNew(() => action(input, output, pause, progress)); while (!input.IsEmpty) { Task.Delay(100).Wait(); } rowFactory.SignalCompletion(); work.Wait(); int sumTotalAge = 0; foreach (Row r in output) { sumTotalAge += (int)r["Age"].Item1; } Assert.AreEqual(expected: 35 + 36 + 19, actual: sumTotalAge); //check errorskipping rowFactory = new RecordToRowTransformer(columnNames, true); data = new object[3] { new object[] { "John", "Doe", 35, "" }, //this row has too many columns! new object[] { "Jane", "Doe", 36 }, new object[] { "Frenk", "Tank, de", 19 } }; for (int i = 0; i < 3; i++) { input.Add((object[])data[i]); } output = new ConcurrentBag <Row>(); action = rowFactory.GetReportingPausableWorkItem(); work = Task.Factory.StartNew(() => action(input, output, pause, progress)); while (!input.IsEmpty) { Task.Delay(100).Wait(); } rowFactory.SignalCompletion(); work.Wait(); Assert.IsTrue(output.Count == 2); }