/// <summary>
 /// Override this method to implement your asynchronous operation. Ensure that you schedule any long term execution
 /// with the executor.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="executor"></param>
 /// <returns></returns>
 protected abstract Task ExecuteAsync(AsyncCodeActivityContext context, AsyncTaskExecutor executor);
Exemple #2
0
        protected override Task <TResult> ExecuteAsync(AsyncCodeActivityContext context, AsyncTaskExecutor executor)
        {
            var arg1 = Argument1.Get(context);

            return(Func != null?executor.ExecuteAsync(() => Func(arg1)) : null);
        }
Exemple #3
0
        /// <summary>
        /// Returns an <see cref="Activity"/> that executes <paramref name="func"/>.
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="func"></param>
        /// <param name="displayName"></param>
        /// <param name="executor"></param>
        /// <returns></returns>
        public static AsyncFuncActivity <TResult> Invoke <TResult>(Func <Task <TResult> > func, string displayName = null, AsyncTaskExecutor executor = null)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }

            return(new AsyncFuncActivity <TResult>(func)
            {
                DisplayName = displayName,
                Executor = executor,
            });
        }
Exemple #4
0
 protected override Task <TResult> ExecuteAsync(AsyncCodeActivityContext context, AsyncTaskExecutor executor)
 {
     return(Func != null?executor.ExecuteAsync(Func) : null);
 }
        /// <summary>
        /// Returns a <see cref="Activity"/> that executes <paramref name="action"/> with arguments.
        /// </summary>
        /// <typeparam name="TArg1"></typeparam>
        /// <param name="action"></param>
        /// <param name="arg1"></param>
        /// <param name="displayName"></param>
        /// <param name="executor"></param>
        /// <returns></returns>
        public static AsyncActionActivity <TArg1> Invoke <TArg1>(Func <TArg1, Task> func, Activity <TArg1> arg1, string displayName = null, AsyncTaskExecutor executor = null)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }
            if (arg1 == null)
            {
                throw new ArgumentNullException(nameof(arg1));
            }

            return(new AsyncActionActivity <TArg1>(func, arg1)
            {
                DisplayName = displayName,
                Executor = executor,
            });
        }
        /// <summary>
        /// Returns a <see cref="Activity"/> that executes <paramref name="action"/> with arguments.
        /// </summary>
        /// <typeparam name="TArg1"></typeparam>
        /// <typeparam name="TArg2"></typeparam>
        /// <typeparam name="TArg3"></typeparam>
        /// <typeparam name="TArg4"></typeparam>
        /// <typeparam name="TArg5"></typeparam>
        /// <typeparam name="TArg6"></typeparam>
        /// <typeparam name="TArg7"></typeparam>
        /// <typeparam name="TArg8"></typeparam>
        /// <param name="action"></param>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <param name="arg4"></param>
        /// <param name="arg5"></param>
        /// <param name="arg6"></param>
        /// <param name="arg7"></param>
        /// <param name="arg8"></param>
        /// <param name="displayName"></param>
        /// <param name="executor"></param>
        /// <returns></returns>
        public static AsyncActionActivity <TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8> Invoke <TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>(Func <TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, Task> func, InArgument <TArg1> arg1, InArgument <TArg2> arg2, InArgument <TArg3> arg3, InArgument <TArg4> arg4, InArgument <TArg5> arg5, InArgument <TArg6> arg6, InArgument <TArg7> arg7, InArgument <TArg8> arg8, string displayName = null, AsyncTaskExecutor executor = null)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }
            if (arg1 == null)
            {
                throw new ArgumentNullException(nameof(arg1));
            }
            if (arg2 == null)
            {
                throw new ArgumentNullException(nameof(arg2));
            }
            if (arg3 == null)
            {
                throw new ArgumentNullException(nameof(arg3));
            }
            if (arg4 == null)
            {
                throw new ArgumentNullException(nameof(arg4));
            }
            if (arg5 == null)
            {
                throw new ArgumentNullException(nameof(arg5));
            }
            if (arg6 == null)
            {
                throw new ArgumentNullException(nameof(arg6));
            }
            if (arg7 == null)
            {
                throw new ArgumentNullException(nameof(arg7));
            }
            if (arg8 == null)
            {
                throw new ArgumentNullException(nameof(arg8));
            }

            return(new AsyncActionActivity <TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8>(func, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
            {
                DisplayName = displayName,
                Executor = executor,
            });
        }
Exemple #7
0
        /// <summary>
        /// Returns a <see cref="Activity"/> that executes <paramref name="func"/> with arguments.
        /// </summary>
        /// <typeparam name="TArg1"></typeparam>
        /// <typeparam name="TArg2"></typeparam>
        /// <typeparam name="TArg3"></typeparam>
        /// <typeparam name="TArg4"></typeparam>
        /// <typeparam name="TArg5"></typeparam>
        /// <typeparam name="TArg6"></typeparam>
        /// <typeparam name="TArg7"></typeparam>
        /// <param name="func"></param>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <param name="arg4"></param>
        /// <param name="arg5"></param>
        /// <param name="arg6"></param>
        /// <param name="arg7"></param>
        /// <param name="displayName"></param>
        /// <param name="executor"></param>
        /// <returns></returns>
        public static AsyncFuncActivity <TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TResult> Invoke <TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TResult>(Func <TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, Task <TResult> > func, DelegateInArgument <TArg1> arg1, DelegateInArgument <TArg2> arg2, DelegateInArgument <TArg3> arg3, DelegateInArgument <TArg4> arg4, DelegateInArgument <TArg5> arg5, DelegateInArgument <TArg6> arg6, DelegateInArgument <TArg7> arg7, string displayName = null, AsyncTaskExecutor executor = null)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }
            if (arg1 == null)
            {
                throw new ArgumentNullException(nameof(arg1));
            }
            if (arg2 == null)
            {
                throw new ArgumentNullException(nameof(arg2));
            }
            if (arg3 == null)
            {
                throw new ArgumentNullException(nameof(arg3));
            }
            if (arg4 == null)
            {
                throw new ArgumentNullException(nameof(arg4));
            }
            if (arg5 == null)
            {
                throw new ArgumentNullException(nameof(arg5));
            }
            if (arg6 == null)
            {
                throw new ArgumentNullException(nameof(arg6));
            }
            if (arg7 == null)
            {
                throw new ArgumentNullException(nameof(arg7));
            }

            return(new AsyncFuncActivity <TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TResult>(func, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
            {
                DisplayName = displayName,
                Executor = executor,
            });
        }
        /// <summary>
        /// Returns a <see cref="Activity"/> that executes <paramref name="action"/> with arguments.
        /// </summary>
        /// <typeparam name="TArg1"></typeparam>
        /// <typeparam name="TArg2"></typeparam>
        /// <typeparam name="TArg3"></typeparam>
        /// <typeparam name="TArg4"></typeparam>
        /// <typeparam name="TArg5"></typeparam>
        /// <param name="action"></param>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <param name="arg4"></param>
        /// <param name="arg5"></param>
        /// <param name="displayName"></param>
        /// <param name="executor"></param>
        /// <returns></returns>
        public static AsyncActionActivity <TArg1, TArg2, TArg3, TArg4, TArg5> Invoke <TArg1, TArg2, TArg3, TArg4, TArg5>(Func <TArg1, TArg2, TArg3, TArg4, TArg5, Task> func, Activity <TArg1> arg1, Activity <TArg2> arg2, Activity <TArg3> arg3, Activity <TArg4> arg4, Activity <TArg5> arg5, string displayName = null, AsyncTaskExecutor executor = null)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }
            if (arg1 == null)
            {
                throw new ArgumentNullException(nameof(arg1));
            }
            if (arg2 == null)
            {
                throw new ArgumentNullException(nameof(arg2));
            }
            if (arg3 == null)
            {
                throw new ArgumentNullException(nameof(arg3));
            }
            if (arg4 == null)
            {
                throw new ArgumentNullException(nameof(arg4));
            }
            if (arg5 == null)
            {
                throw new ArgumentNullException(nameof(arg5));
            }

            return(new AsyncActionActivity <TArg1, TArg2, TArg3, TArg4, TArg5>(func, arg1, arg2, arg3, arg4, arg5)
            {
                DisplayName = displayName,
                Executor = executor,
            });
        }
Exemple #9
0
        /// <summary>
        /// Returns a <see cref="Activity"/> that executes <paramref name="func"/> with arguments.
        /// </summary>
        /// <typeparam name="TArg1"></typeparam>
        /// <typeparam name="TArg2"></typeparam>
        /// <typeparam name="TArg3"></typeparam>
        /// <param name="func"></param>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <param name="displayName"></param>
        /// <param name="executor"></param>
        /// <returns></returns>
        public static AsyncFuncActivity <TArg1, TArg2, TArg3, TResult> Invoke <TArg1, TArg2, TArg3, TResult>(Func <TArg1, TArg2, TArg3, Task <TResult> > func, InArgument <TArg1> arg1, InArgument <TArg2> arg2, InArgument <TArg3> arg3, string displayName = null, AsyncTaskExecutor executor = null)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }
            if (arg1 == null)
            {
                throw new ArgumentNullException(nameof(arg1));
            }
            if (arg2 == null)
            {
                throw new ArgumentNullException(nameof(arg2));
            }
            if (arg3 == null)
            {
                throw new ArgumentNullException(nameof(arg3));
            }

            return(new AsyncFuncActivity <TArg1, TArg2, TArg3, TResult>(func, arg1, arg2, arg3)
            {
                DisplayName = displayName,
                Executor = executor,
            });
        }
Exemple #10
0
 /// <summary>
 /// Executes the activity.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="executor"></param>
 /// <returns></returns>
 protected override Task ExecuteAsync(AsyncCodeActivityContext context, AsyncTaskExecutor executor)
 {
     return(Action != null?executor.ExecuteAsync(Action) : null);
 }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="executor"></param>
 public AsyncTaskExecutorScope(AsyncTaskExecutor executor, Activity body)
     : this(executor)
 {
     Body = body;
 }
Exemple #12
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="executor"></param>
 public AsyncTaskExecutorScope(AsyncTaskExecutor executor)
     : this()
 {
     Executor = executor;
 }
Exemple #13
0
        /// <summary>
        /// Executes the <paramref name="body"/> using a given <see cref="Cogito.Activities.AsyncTaskExecutor" />.
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="body"></param>
        /// <param name="executor">Provides execution services to nested activities.</param>
        /// <returns></returns>
        public static AsyncTaskExecutorScope <TResult> WithAsyncTaskExecutor <TResult>(this Activity <TResult> body, AsyncTaskExecutor executor)
        {
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }
            if (executor == null)
            {
                throw new ArgumentNullException(nameof(executor));
            }

            return(new AsyncTaskExecutorScope <TResult>(executor, body));
        }