public void ProgressChanged(ProgressChangedInfo p) { var c = p.CurrentTask; switch (c.TaskKey) { case "Primary": eta2.Reset(); break; case "Second": eta3.Reset(); break; case "Third": break; } var ui = new[] { new { ETA = eta1, Progress = progressBar1, Label = label1 }, new { ETA = eta2, Progress = progressBar2, Label = label2 }, new { ETA = eta3, Progress = progressBar3, Label = label3 }, }; for (int i = 0; i <= p.CurrentDepth; i++) { ui[i].ETA.Update(p[i].Progress); ui[i].Progress.Value = p[i].Progress * 100d; ui[i].Label.Content = ui[i].ETA.ETAIsAvailable ? string.Format("{0:00}% done\t{1:0.0} seconds remaining\t(ETA is {2:h:mm:ss})", p[i].Progress * 100f, ui[i].ETA.ETR.TotalSeconds, ui[i].ETA.ETA) : "Calculating..."; } }
private void AssertProgressIsGrowing(ProgressChangedInfo p) { var newProgress = p.TotalProgress * 100; //Console.WriteLine("{0:00.00}% (+{1:0.00}%) - \"{2}\"", newProgress, newProgress - currentProgress, p[0].TaskKey); Assert.GreaterOrEqual(newProgress, currentProgress); Assert.LessOrEqual(newProgress, 100f, "Progress during an unknown progress should never exceed 100% but is {0:000.00}%", newProgress); currentProgress = newProgress; }
public void ProgressChanged(ProgressChangedInfo p) { var c = p.CurrentTask; switch (c.TaskKey) { case "Primary": eta2.Reset(); break; case "Second": eta3.Reset(); break; case "Third": break; } var ui = new[] { new {ETA = eta1, Progress = progressBar1, Label = label1}, new {ETA = eta2, Progress = progressBar2, Label = label2}, new {ETA = eta3, Progress = progressBar3, Label = label3}, }; for (int i = 0; i <= p.CurrentDepth; i++) { ui[i].ETA.Update(p[i].Progress); ui[i].Progress.Value = p[i].Progress*100d; ui[i].Label.Content = ui[i].ETA.ETAIsAvailable ? string.Format("{0:00}% done\t{1:0.0} seconds remaining\t(ETA is {2:h:mm:ss})", p[i].Progress * 100f, ui[i].ETA.ETR.TotalSeconds, ui[i].ETA.ETA) : "Calculating..."; } }
public void ProgressWatcher_ProgressChanged(object sender, ProgressChangedInfo p) { ProgressChanged(p); }
private void OnProgressEnding(ProgressChangedInfo progresschangedinfo) { StopPolling(); }
/// <summary> /// Calculates the current progress, /// and invokes the callback for the /// current task and all parent tasks. /// </summary> private void OnProgressChanged(object currentStepArg) { // First, an optimization: // we might not need to calculate progress at all, // if no one is listening: ProgressDepth depth = 0; var task = this; while (true) { // Determine if we've reached the bottom of the stack or the maximum depth: if (task == null || task.maximumDepth < depth) { // No one's listening this deep! // Skip calculations. return; } // Check for a callback: if (task.progressChangedCallback != null) { break; } // Check for polling: if (task.pollingEnabled) { if (task.currentProgressAccessed || (int)depth < task.currentProgress.CurrentDepth) { // Polling is enabled and is ready for a new CurrentProgress. break; } } // Traverse the progress stack: depth++; task = task.parent; } depth = 0; task = this; var taskProgress = 0.0f; var allProgress = new Stack<ProgressInfo>(); while (true) { // Calculate the task's progress: if (task.isEnded) // 100%! taskProgress = 1.0f; else taskProgress = task.calculator.CalculateProgress(taskProgress); allProgress.Push(new ProgressInfo(taskProgress, task.taskKey, task.taskArg)); // Raise events or update Polling: ProgressChangedInfo progressChangedInfo = null; // Raise the event if necessary: if (task.progressChangedCallback != null) { progressChangedInfo = new ProgressChangedInfo(allProgress, currentStepArg); task.progressChangedCallback(progressChangedInfo); } // Update the CurrentProgress so that it can be used for polling. if (task.pollingEnabled) { // If the current CurrentProgress hasn't been accessed, // then we will only update if the new item is higher priority (lower depth): if (task.currentProgressAccessed || (int)depth < task.currentProgress.CurrentDepth) { if (progressChangedInfo == null) { progressChangedInfo = new ProgressChangedInfo(allProgress, currentStepArg); } task.currentProgressAccessed = false; task.currentProgress = progressChangedInfo; } } // Traverse the progress stack: depth++; task = task.parent; // Determine if we've reached the bottom of the stack or the maximum depth: if (task == null || task.maximumDepth < depth) { break; } } }
/// <summary> /// Enables progress polling. /// Use <see cref="CurrentProgress"/> to retrieve the task's current progress. /// Returns the current progress task, so that methods may be chained. /// </summary> public ProgressTask EnablePolling(int maximumDepth) { this.pollingEnabled = true; this.currentProgressAccessed = true; this.currentProgress = new ProgressChangedInfo(new ProgressInfo(0f, null, null), null); this.maximumDepth = (ProgressDepth)maximumDepth; return this; }