/// <param name="id">Id of the state.</param>
        /// <param name="displayName">Displayname of the state.</param>
        /// <param name="timeoutSec">Seconds, after the asynchronous task should be aborted.</param>
        /// <param name="timeoutCallback">Callback to report, that the task was aborted because of a timeout.</param>
        /// <param name="progressCallback">Callback to report, that the task makes progress.</param>
        public WuStateAsyncJob(WuStateId id, string displayName, int timeoutSec, TimeoutCallback timeoutCallback, ProgressChangedCallback progressCallback) : base(id, displayName)
        {
            if (timeoutSec < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(timeoutSec), "Negative timeout is not allowed.");
            }
            if (timeoutSec > int.MaxValue / 1000)
            {
                throw new ArgumentOutOfRangeException(nameof(timeoutSec), $"Max timeout is {int.MaxValue / 1000} sec.");
            }
            if (timeoutCallback == null)
            {
                throw new ArgumentNullException(nameof(timeoutCallback));
            }

            TimeoutSec = timeoutSec;
            TimeoutCallbackDelegate         = timeoutCallback;
            ProgressChangedCallbackDelegate = progressCallback;
        }
예제 #2
0
        public void TestCallbackDepth()
        {
            var justFine = false;
            ProgressChangedCallback callback = (p) => {
                if (p.Any(pi => pi.TaskKey == "Too Deep!"))
                {
                    Assert.Fail("'Too Deep!' invoked a callback!");
                }
                if (p.Any(pi => pi.TaskKey == "Just fine"))
                {
                    justFine = true;
                }
            };

            var items = new[] { 1, 2, 3, 4, 5 };

            // Here, we set the callback with a maximum depth of 3:
            foreach (var zero in items.WithProgress().SetCallback(callback, (ProgressDepth)3))
            {
                foreach (var one in items.WithProgress())
                {
                    foreach (var two in items.WithProgress())
                    {
                        // This progress is 3-deep, so it should work Just fine:
                        foreach (var three in items.WithProgress().SetTaskKey("Just fine"))
                        {
                            // This progress is 4-deep, so it shouldn't fire the callback:
                            foreach (var four in items.WithProgress().SetTaskKey("Too Deep!"))
                            {
                                DoNothing(four);
                            }
                        }
                    }
                }
            }

            if (justFine == false)
            {
                Assert.Fail("'Just fine' did not invoke a callback!");
            }
        }
        public WuStateInstalling(IUpdateInstaller uInstaller, IUpdateCollection updates,
                                 InstallCompletedCallback completedCallback, TimeoutCallback timeoutCallback, ProgressChangedCallback progressCallback,
                                 int timeoutSec) : base(WuStateId.Installing, "Installing Updates", timeoutSec, timeoutCallback, progressCallback)
        {
            if (uInstaller == null)
            {
                throw new ArgumentNullException(nameof(uInstaller));
            }
            if (updates == null)
            {
                throw new ArgumentNullException(nameof(updates));
            }
            if (completedCallback == null)
            {
                throw new ArgumentNullException(nameof(completedCallback));
            }

            _uInstaller        = uInstaller;
            _updates           = updates;
            _completedCallback = completedCallback;
        }
 /// <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>
 public ProgressEnumerator <T> SetCallback(ProgressChangedCallback callback)
 {
     progress.SetCallback(callback);
     return(this);
 }
예제 #6
0
 /// <summary>
 /// Attaches the callback to fire when the progress task ends (successfully or not).
 ///
 /// This is usually attached 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 ProgressEnded event</param>
 public ProgressTask SetCallbackEnded(ProgressChangedCallback callback)
 {
     this.progressEndedCallback += callback;
     return(this);
 }
예제 #7
0
 /// <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);
 }
예제 #8
0
 /// <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);
 }
예제 #9
0
 public WuStateAsyncJobProxy(WuStateId id, string displayName, int timeoutSec, TimeoutCallback timeoutCallback, ProgressChangedCallback progressCallback)
     : base(id, displayName, timeoutSec, timeoutCallback, progressCallback)
 {
 }
예제 #10
0
 internal static extern int SetProgressCallback(int requestId, ProgressChangedCallback callback, IntPtr userData);
예제 #11
0
 /// <summary>
 /// Attaches the callback to fire when the progress task ends (successfully or not).
 /// 
 /// This is usually attached 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 ProgressEnded event</param>
 public ProgressTask SetCallbackEnded(ProgressChangedCallback callback)
 {
     this.progressEndedCallback += callback;
     return this;
 }
예제 #12
0
 /// <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;
 }
예제 #13
0
 /// <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;
 }
예제 #14
0
 /// <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);
 }
예제 #15
0
 /// <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));
 }