/// <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); }
/// <summary> Pushes a new task to the top of the stack. /// </summary> /// <param name="calculator"></param> public ProgressTask(IProgressCalculator calculator) { this.calculator = calculator; // Push this new task on the top of the task stack: this.parent = currentTask; currentTask = this; // Calculate the new maximum depth: if (this.parent == null) { this.maximumDepth = ProgressDepth.Auto; } else { this.maximumDepth = parent.maximumDepth - 1; } }
/// <summary> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="maxDepth"> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". </param> public ProgressTask SetMaxDepth(int maxDepth) { this.maximumDepth = (ProgressDepth)maxDepth; return this; }
/// <summary> Attaches the callback to fire when progress is reported. /// /// This is usually called at the beginning of the task. /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="callback">Attach a callback to the ProgressChanged event</param> /// <param name="maxDepth"> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". </param> public static ProgressTask SetCallback(ProgressChangedCallback callback, ProgressDepth maxDepth) { return GetCurrentTask().SetCallback(callback, maxDepth); }
/// <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> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="maxDepth"> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". </param> public ProgressTask SetMaxDepth(int maxDepth) { this.maximumDepth = (ProgressDepth)maxDepth; return(this); }
/// <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(ProgressDepth maximumDepth) { EnablePolling((int)maximumDepth); return(this); }
/// <summary> Attaches the callback to fire when progress is reported. /// /// This is usually called at the beginning of the task. /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="callback">Attach a callback to the ProgressChanged event</param> public ProgressTask SetCallback(ProgressChangedCallback callback) { this.progressChangedCallback += callback; this.maximumDepth = ProgressDepth.Unlimited; return(this); }
/// <summary> Attaches the callback to fire when progress is reported. /// /// This is usually called at the beginning of the task. /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="callback">Attach a callback to the ProgressChanged event</param> /// <param name="maxDepth"> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". </param> public ProgressTask SetCallback(ProgressChangedCallback callback, ProgressDepth maxDepth) { this.progressChangedCallback += callback; this.maximumDepth = maxDepth; return(this); }
/// <summary> Attaches the callback to fire when progress is reported. /// /// This is usually called at the beginning of the task. /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="callback">Attach a callback to the ProgressChanged event</param> /// <param name="maxDepth"> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". </param> public ProgressEnumerator <T> SetCallback(ProgressChangedCallback callback, ProgressDepth maxDepth) { progress.SetCallback(callback, maxDepth); return(this); }
/// <summary> Attaches the callback to fire when progress is reported. /// /// This is usually called at the beginning of the task. /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="callback">Attach a callback to the ProgressChanged event</param> /// <param name="maxDepth"> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". </param> public static ProgressTask SetCallback(ProgressChangedCallback callback, ProgressDepth maxDepth) { return(GetCurrentTask().SetCallback(callback, maxDepth)); }
/// <summary> Attaches the callback to fire when progress is reported. /// /// This is usually called at the beginning of the task. /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="callback">Attach a callback to the ProgressChanged event</param> /// <param name="maxDepth"> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". </param> public ProgressTask SetCallback(ProgressChangedCallback callback, ProgressDepth maxDepth) { this.progressChangedCallback += callback; this.maximumDepth = maxDepth; return this; }
/// <summary> Attaches the callback to fire when progress is reported. /// /// This is usually called at the beginning of the task. /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="callback">Attach a callback to the ProgressChanged event</param> public ProgressTask SetCallback(ProgressChangedCallback callback) { this.progressChangedCallback += callback; this.maximumDepth = ProgressDepth.Unlimited; return this; }
/// <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; }
/// <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(ProgressDepth maximumDepth) { EnablePolling((int) maximumDepth); return this; }
/// <summary> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="maxDepth"> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". </param> public static ProgressTask SetMaxDepth(ProgressDepth maxDepth) { return GetCurrentTask().SetMaxDepth(maxDepth); }
/// <summary> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="maxDepth"> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". </param> public ProgressEnumerator <T> SetMaxDepth(ProgressDepth maxDepth) { progress.SetMaxDepth(maxDepth); return(this); }
/// <summary> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". /// Returns the current progress task, so that methods may be chained. /// </summary> /// <param name="maxDepth"> An integer value that determines the maximum number of nested progress tasks. Progress reported at deeper levels will be ignored. All negative values are equivalent to "Auto". </param> public static ProgressTask SetMaxDepth(ProgressDepth maxDepth) { return(GetCurrentTask().SetMaxDepth(maxDepth)); }