/// <summary> /// Do the executing. /// </summary> /// <param name="input">Inputs to the current call to the target.</param> /// <param name="getNext">Delegate to execute to get the next delegate in the handler chain.</param> /// <returns>Return value from the target or null to continue.</returns> protected virtual IMethodReturn DoExecuting(IMethodInvocation input, GetNextHandlerDelegate getNext) { var executingContext = new FilterExecutingContext(input); var executing = this.filterAttribute.OnExecuting(executingContext); if (executingContext.Cancel) { var cancel = this.filterAttribute.OnCancel(new FilterCancelContext(input)); return(cancel ?? input.CreateExceptionMethodReturn(new OperationCanceledException())); } if (executing != null) { var executed = this.DoExecuted(input, getNext, executing); if (executed != null) { return(executed); } return(executing); } return(null); }
/// <summary> /// Returns the cache result; otherwise it execute method. /// </summary> /// <param name="context">The executing context.</param> /// <returns>Null to continue or an instance that implement <see cref="IMethodReturn" />.</returns> public override IMethodReturn OnExecuting(FilterExecutingContext context) { var key = this.GetKeyName(context); if (Cache.Contains(key)) { return(context.MethodInvocation.CreateMethodReturn(Cache[key])); } return(null); }
/// <summary> /// When overridden in a derived class, handles before the execution. /// </summary> /// <param name="context">The executing context.</param> /// <returns>Null to continue or an instance that implement <see cref="IMethodReturn" />.</returns> public override IMethodReturn OnExecuting(FilterExecutingContext context) { if (Thread.CurrentPrincipal == null || !Thread.CurrentPrincipal.Identity.IsAuthenticated) { return(context.MethodInvocation.CreateExceptionMethodReturn(new UnauthorizedAccessException())); } if (this.Roles != null && !this.Roles.Any(x => Thread.CurrentPrincipal.IsInRole(x))) { return(context.MethodInvocation.CreateExceptionMethodReturn(new UnauthorizedAccessException())); } return(null); }
/// <summary> /// Writes the input parameters to the debug console. /// </summary> /// <param name="context">The executing context.</param> /// <returns>Null to continue or an instance that implement <see cref="IMethodReturn" />.</returns> public override IMethodReturn OnExecuting(FilterExecutingContext context) { Debug.WriteLine("Executing: {0}.{1}", context.MethodInvocation.Target.GetType().FullName, context.MethodInvocation.MethodBase.Name); if (context.MethodInvocation.Arguments.Count > 0) { Debug.WriteLine(" with arguments:"); for (var i = 0; i < context.MethodInvocation.Arguments.Count; ++i) { var parameterInfo = context.MethodInvocation.Arguments.GetParameterInfo(i); Debug.WriteLine(" {0} = {1}", parameterInfo.Name, context.MethodInvocation.Arguments[i]); } } return(null); }
/// <summary> /// When overridden in a derived class, handles before the execution. /// </summary> /// <param name="context">The executing context.</param> /// <returns>Null to continue or an instance that implement <see cref="IMethodReturn"/>.</returns> public virtual IMethodReturn OnExecuting(FilterExecutingContext context) { return(null); }