Пример #1
0
        /// <summary>
        /// The given Action will be performed when the task succeeds.
        /// </summary>
        /// <param name="task">The task.</param>
        /// <param name="action">The action to perform.</param>
        /// <param name="actionTarget">The action target.</param>
        /// <returns>
        /// This task.
        /// </returns>
        public static CustomTask WhenSucceeded(this CustomTask task, Action <CustomTask> action,
                                               CustomTaskDispatcherBase actionTarget)
        {
            Action <CustomTask> perform = t =>
            {
                if (actionTarget == null)
                {
                    action(t);
                }
                else
                {
                    actionTarget.Dispatch(() => { if (t.IsSucceeded)
                                                  {
                                                      action(t);
                                                  }
                                          });
                }
            };

            return(task.WhenEnded(t => { if (t.IsSucceeded)
                                         {
                                             perform(t);
                                         }
                                  }, null));
        }
Пример #2
0
 /// <summary>
 /// The given Action will be performed when the task fails.
 /// </summary>
 /// <param name="task">The task.</param>
 /// <param name="action">The action to perform.</param>
 /// <param name="target">The DispatcherBase to perform the action on.</param>
 /// <returns>
 /// This task.
 /// </returns>
 public static CustomTask WhenFailed(this CustomTask task, Action <CustomTask> action, CustomTaskDispatcherBase target)
 {
     return(task.WhenEnded(t => { if (t.IsFailed)
                                  {
                                      action(t);
                                  }
                           }, target));
 }
Пример #3
0
 /// <summary>
 /// The given Action will be performed when the task fails.
 /// </summary>
 /// <param name="task">The task.</param>
 /// <param name="action">The action to perform.</param>
 /// <returns>
 /// This task.
 /// </returns>
 public static CustomTask WhenFailed(this CustomTask task, Action <CustomTask> action)
 {
     return(task.WhenEnded(t => { if (t.IsFailed)
                                  {
                                      action(t);
                                  }
                           }));
 }
Пример #4
0
 /// <summary>
 /// The given Action will be performed when the task succeeds.
 /// </summary>
 /// <param name="task">The task.</param>
 /// <param name="action">The action to perform.</param>
 /// <returns>
 /// This task.
 /// </returns>
 public static CustomTask WhenSucceeded(this CustomTask task, Action action)
 {
     return(task.WhenEnded(t => { if (t.IsSucceeded)
                                  {
                                      action();
                                  }
                           }));
 }
Пример #5
0
        /// <summary>
        /// Performs the given Func sequential for each element in the enumerable.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <typeparam name="T"></typeparam>
        /// <param name="that">The that.</param>
        /// <param name="action">The Func to perform for each element.</param>
        /// <param name="target">The TaskDistributor instance on which the operation should perform.</param>
        /// <returns>
        /// IEnumerable of created tasks.
        /// </returns>
        public static IEnumerable <CustomTask <TResult> > SequentialForEach <TResult, T>(this IEnumerable <T> that,
                                                                                         Func <T, TResult> action, TaskDistributor target)
        {
            var        result   = new List <CustomTask <TResult> >();
            CustomTask lastTask = null;

            foreach (var element in that)
            {
                var tmp  = element;
                var task = CustomTask.Create(() => action(tmp));
                if (lastTask == null)
                {
                    task.Run(target);
                }
                else
                {
                    lastTask.WhenEnded(() => task.Run(target));
                }
                lastTask = task;
                result.Add(task);
            }
            return(result);
        }
Пример #6
0
 /// <summary>
 /// The given Action will be performed when the task ends.
 /// </summary>
 /// <param name="task">The task.</param>
 /// <param name="action">The action to perform.</param>
 /// <returns>
 /// This task.
 /// </returns>
 public static CustomTask WhenEnded(this CustomTask task, Action <CustomTask> action)
 {
     return(task.WhenEnded(action, null));
 }
Пример #7
0
 /// <summary>
 /// The given Action will be performed when the task ends.
 /// </summary>
 /// <param name="task">The task.</param>
 /// <param name="action">The action to perform.</param>
 /// <returns>
 /// This task.
 /// </returns>
 public static CustomTask WhenEnded(this CustomTask task, Action action)
 {
     return(task.WhenEnded(t => action()));
 }
Пример #8
0
 /// <summary>
 /// The given Action will be performed when the task ends.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="task">The task.</param>
 /// <param name="action">The action to perform.</param>
 /// <returns>
 /// This task.
 /// </returns>
 public static CustomTask <T> WhenEnded <T>(this CustomTask <T> task, Action <CustomTask <T> > action)
 {
     return(task.WhenEnded(action, null));
 }
Пример #9
0
 /// <summary>
 /// The given Action will be performed when the task ends.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="task">The task.</param>
 /// <param name="action">The action to perform.</param>
 /// <returns>
 /// This task.
 /// </returns>
 public static CustomTask <T> WhenEnded <T>(this CustomTask <T> task, Action action)
 {
     return(task.WhenEnded(t => action(), null));
 }