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); }
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); }
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); }
/// <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)); }
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); }
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); } }
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); } }
/// <summary> /// Fires the before execution event. /// </summary> internal void FireBeforeExecutionEvent() { BeforeExecution?.Invoke(this, new EventArgs()); }