private Task NofificarError(string message, string stackTrace)
 {
     return (ProcessFailed?.Invoke(this, new ExecutorFailEventArgs()
     {
         JobId = this.JobId,
         Mensaje = message,
         StackTrace = stackTrace
     }) ?? Task.CompletedTask);//.ConfigureAwait(false);
 }
예제 #2
0
        /// <summary>
        /// Processes.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <param name="resetCancelState">true if need to reset the cancel state; otherwise, false.</param>
        /// <returns>The verb handler.</returns>
        private async Task <Verb> ProcessAsync(Arguments args, bool resetCancelState)
        {
            if (isCanceled)
            {
                if (resetCancelState)
                {
                    isCanceled = false;
                }
                return(null);
            }

            var verb = PrepareVerb(args);

            if (verb == null)
            {
                return(null);
            }
            if (ProcessingVerb != null && !ProcessingVerb.HasDisposed)
            {
                try
                {
                    if (!ProcessingVerb.IsCancelled)
                    {
                        ProcessingVerb.Cancel();
                    }
                }
                catch (NullReferenceException)
                {
                }
                catch (InvalidOperationException)
                {
                }
                catch (ArgumentException)
                {
                }
                catch (OperationCanceledException)
                {
                }
                finally
                {
                    ProcessingVerb.Dispose();
                }
            }

            if (ProcessingVerb == verb)
            {
                return(null);
            }
            ProcessingVerb = verb;
            Processing?.Invoke(this, new ProcessEventArgs(args, verb));
            try
            {
                if (!verb.IsCancelled && !isCanceled && !verb.HasDisposed)
                {
                    verb.Init(this);
                }
                if (!verb.IsCancelled && !isCanceled && !verb.HasDisposed)
                {
                    if (verb is AsyncVerb asyncVerb)
                    {
                        await asyncVerb.ProcessAsync();
                    }
                    else
                    {
                        verb.Process();
                    }
                }

                else if (resetCancelState)
                {
                    isCanceled = false;
                }
                Processed?.Invoke(this, new ProcessEventArgs(args, verb));
            }
            catch (OperationCanceledException ex)
            {
                ProcessCanceled?.Invoke(this, new FailedProcessEventArgs(args, verb, ex));
            }
            catch (Exception ex)
            {
                ProcessFailed?.Invoke(this, new FailedProcessEventArgs(args, verb, ex));
                throw ex;
            }
            finally
            {
                verb.Dispose();
                ProcessingVerb = null;
            }

            return(verb);
        }