Пример #1
0
        protected override object Invoke(MethodInfo targetMethod, object[] args)
        {
            object result = null;

            try
            {
                BeforeExecution?.Invoke(this, targetMethod);

                result = targetMethod.Invoke(DecoratedClass, args);

                if (targetMethod.ReturnType != typeof(void))
                {
                    HandleResult(targetMethod, result);
                }
            }
            catch (Exception ex)
            {
                if (ex is TargetInvocationException)
                {
                    throw ex.InnerException ?? ex;
                }
            }
            AfterExecution?.Invoke(this, targetMethod);

            return(result);
        }
Пример #2
0
        protected ConcurrentFunctionBase(FunctionBaseDecorator funcBase, int maxConcurrency)
        {
            _funcBase      = funcBase;
            _semaphoreSlim = new SemaphoreSlim(maxConcurrency);

            _funcBase.BeforeExecution  += (sender, objects) => BeforeExecution?.Invoke(sender, objects);
            _funcBase.AfterExecution   += (sender, objects) => AfterExecution?.Invoke(sender, objects);
            _funcBase.ExecutionDelayed += (sender, objects) => ExecutionDelayed?.Invoke(sender, objects);
        }
Пример #3
0
        protected RateLimitedFunctionBase(FunctionBaseDecorator funcBase, Func <object[], Task <bool> > ignoreRateLimitFunc)
        {
            _funcBase            = funcBase;
            _ignoreRateLimitFunc = ignoreRateLimitFunc;

            _funcBase.BeforeExecution  += (sender, objects) => BeforeExecution?.Invoke(sender, objects);
            _funcBase.AfterExecution   += (sender, o) => AfterExecution?.Invoke(sender, o);
            _funcBase.ExecutionDelayed += (sender, objects) => ExecutionDelayed?.Invoke(sender, objects);
        }
Пример #4
0
        /// <summary>
        /// Before command execution.
        /// </summary>
        protected void OnBeforeExecute
        (
            [NotNull] ExecutionContext context
        )
        {
            Sure.NotNull(context, nameof(context));
            Log.Trace(nameof(AbstractEngine) + "::" + nameof(OnBeforeExecute));

            BeforeExecution?.Invoke(this, new ExecutionEventArgs(context));
        }
Пример #5
0
        protected RetryFunctionBase(FunctionBaseDecorator funcBase, int maxRetryCount, Func <object, bool> retryOnResult, Func <Exception, bool> retryOnException)
        {
            _funcBase         = funcBase;
            _maxRetryCount    = maxRetryCount;
            _retryOnResult    = retryOnResult;
            _retryOnException = retryOnException;

            _funcBase.BeforeExecution  += (sender, objects) => BeforeExecution?.Invoke(sender, objects);
            _funcBase.AfterExecution   += (sender, objects) => AfterExecution?.Invoke(sender, objects);
            _funcBase.ExecutionDelayed += (sender, objects) => ExecutionDelayed?.Invoke(sender, objects);
        }
Пример #6
0
        public override async Task <object> ExecuteInnerAsync(object[] arguments)
        {
            BeforeExecution?.Invoke(this, arguments);
            object result = null;

            try
            {
                result = await _func(arguments);

                return(result);
            }
            finally
            {
                AfterExecution?.Invoke(this, result);
            }
        }
Пример #7
0
 private TaskResult RunTask()
 {
     try
     {
         BeforeExecution?.Invoke(this, new JobEventArgs {
             Context = Context
         });
         Context.ExecutionStartedOn = DateTime.UtcNow;
         var result = Context.Task.Run(Context.JobName, Context.ScheduleName, Context.Parameters);
         Context.ExecutionFinishedOn = DateTime.UtcNow;
         ExecutionCompleted?.Invoke(this, new JobEventArgs {
             Context = Context
         });
         return(result);
     }
     catch (Exception e)
     {
         ErrorHandler.HandleException(e);
         return(TaskResult.Aborted);
     }
 }
Пример #8
0
 /// <summary>
 /// Fires the before execution event.
 /// </summary>
 internal void FireBeforeExecutionEvent()
 {
     BeforeExecution?.Invoke(this, new EventArgs());
 }