public ProgressReportScope CreateMainScope(int stepsCount, double span, double initProgress, string name) { MainScope = new ProgressReportScope(stepsCount, span, initProgress, name); _mainProgressObservers.ForEach(o => MainScope.Subscribe(o)); _mainProgressObservers.Clear(); MainScope.Subscribe(new ProgressObserver(onComplete: () => MainScope = null)); return MainScope; }
public void TestChildScopeNotCompleted() { List<double> progress = new List<double>(); ProgressObserver progressObserver = new ProgressObserver(s => progress.Add(s.Progress)); using (ProgressReportScope scope = new ProgressReportScope()) { scope.Subscribe(progressObserver); scope.CreateChildScope(0.5); } ProgressAssert.AreEqual(new[] { 0.5, 1.0 }, progress); }
public void TestNestedScopes() { List<double> progress = new List<double>(); ProgressObserver progressObserver = new ProgressObserver(s => progress.Add(s.Progress)); using (ProgressReportScope scope = new ProgressReportScope()) { scope.Subscribe(progressObserver); using (scope.CreateChildScope(0.5)) DumbFunc(); using (ProgressReportScope child = scope.CreateChildScope(0.2)) { using (child.CreateChildScope(0.5)) DumbFunc(); using (child.CreateChildScope(0.5)) DumbFunc(); } } ProgressAssert.AreEqual(new[] { 0.5, 0.6, 0.7, 1.0 }, progress); }
public void TestNestedScopesWithSteps(int stepsCount, double childScopeSpan, int childScopeStepsCount, double[] expectedProgress) { List<double> progress = new List<double>(); ProgressObserver progressObserver = new ProgressObserver(s => progress.Add(s.Progress)); using (ProgressReportScope scope = new ProgressReportScope(stepsCount)) { scope.Subscribe(progressObserver); for (int i = 0; i < stepsCount; i++) { using (ProgressReportScope childScope = scope.CreateChildScope(childScopeStepsCount, childScopeSpan)) { for (int j = 0; j < childScopeStepsCount; j++) { childScope.Increase(); } } scope.Increase(); } } ProgressAssert.AreEqual(expectedProgress, progress); }
public void TestScopeWithSteps(int stepsCount, int stepsPassed, double[] expectedProgress) { List<double> progress = new List<double>(); ProgressObserver progressObserver = new ProgressObserver(s => progress.Add(s.Progress)); using (ProgressReportScope scope = new ProgressReportScope(stepsCount)) { scope.Subscribe(progressObserver); for (int i = 0; i < stepsPassed; i++) { scope.Increase(); } } ProgressAssert.AreEqual(expectedProgress, progress); }
public void TestScopeWithSpanAndInitProgress() { List<double> progress = new List<double>(); ProgressObserver progressObserver = new ProgressObserver(s => progress.Add(s.Progress)); const int steps = 3; using (ProgressReportScope scope = new ProgressReportScope(steps, 0.3, 0.65)) { scope.Subscribe(progressObserver); for ( int i = 0; i < steps; i++) scope.Increase(); } ProgressAssert.AreEqual(new[] { 0.75, 0.85, 0.95 }, progress); }