Exemple #1
0
        /// <summary>
        /// Creates an <see cref="ExecutionManager"/> to run the <see cref="ExecutorBase{TArgs}"/> created by the <paramref name="executorCreate"/> function with a <paramref name="trigger"/> and arguments.
        /// </summary>
        /// <param name="executorCreate">The function to create the executor with arguments.</param>
        /// <param name="trigger">The trigger.</param>
        /// <returns>An <see cref="ExecutionManager"/>.</returns>
        public static ExecutionManager Create <TArgs>(Func <ExecutorBase <TArgs> > executorCreate, TriggerBase <TArgs> trigger)
        {
            if (executorCreate == null)
            {
                throw new ArgumentNullException(nameof(executorCreate));
            }

            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            return(new ExecutionManager(trigger, () => executorCreate.Invoke(), async(executor, args) =>
            {
                var exe = (executor as ExecutorBase <TArgs>) !;

                if (args is TriggerEventArgs tea)
                {
                    exe.ExecutorArgs = tea.Args;
                }

                var ea = new ExecutorRunArgs <TArgs>(exe);
                await exe.RunWrapperAsync(ExceptionHandling.Stop, async() =>
                {
                    await exe.RunAsync(ea).ConfigureAwait(false);
                }, ea).ConfigureAwait(false);
            }));
        }
Exemple #2
0
        /// <summary>
        /// Runs the work.
        /// </summary>
        /// <param name="args">The <see cref="ExecutorRunArgs{TArgs}"/>.</param>
        internal async Task RunAsync(ExecutorRunArgs <TArgs> args)
        {
            try
            {
                await OnRunAsync(args).ConfigureAwait(false);

                OnPerRunType(args);
            }
            catch (Exception ex)
            {
                if (!args.HasException)
                {
                    args.SetException(ex);
                    OnPerRunType(args);
                }
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// Runs the work.
        /// </summary>
        /// <param name="args">The <see cref="ExecutorRunArgs"/>.</param>
        internal async Task RunAsync(ExecutorRunArgs args)
        {
            try
            {
                await OnRunAsync(args);

                OnPerRunType(args);
            }
            catch (Exception ex)
            {
                if (!args.HasException)
                {
                    args.SetException(ex);
                    OnPerRunType(args);
                }

                throw;
            }
        }
Exemple #4
0
        /// <summary>
        /// Create an <see cref="ExecutionManager"/> to run the <see cref="ExecutorBase"/> created by the <paramref name="executorCreate"/> function with a <paramref name="trigger"/> and no arguments.
        /// </summary>
        /// <param name="executorCreate">The function to create the executor with no arguments.</param>
        /// <param name="trigger">The trigger.</param>
        /// <returns>An <see cref="ExecutionManager"/>.</returns>
        public static ExecutionManager Create(Func <ExecutorBase> executorCreate, TriggerBase trigger)
        {
            if (executorCreate == null)
            {
                throw new ArgumentNullException(nameof(executorCreate));
            }

            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            return(new ExecutionManager(trigger, () => executorCreate.Invoke(), async(executor, args) =>
            {
                var exe = executor as ExecutorBase;
                var ea = new ExecutorRunArgs(exe);
                await exe.RunWrapperAsync(ExceptionHandling.Stop, async() =>
                {
                    await exe.RunAsync(ea);
                }, ea);
            }));
        }
Exemple #5
0
 /// <summary>
 /// Runs the unit of work.
 /// </summary>
 /// <param name="args">The <see cref="ExecutorRunArgs"/>.</param>
 protected override Task OnRunAsync(ExecutorRunArgs args)
 {
     return(_func(args));
 }
Exemple #6
0
 /// <summary>
 /// Runs the unit of work.
 /// </summary>
 /// <param name="args">The <see cref="ExecutorRunArgs"/>.</param>
 protected abstract Task OnRunAsync(ExecutorRunArgs args);