예제 #1
0
            public void NewImplementation(IAlternateMethodContext context)
            {
                if (context.RuntimePolicyStrategy() == RuntimePolicy.Off)
                {
                    context.Proceed();
                    return;
                }

                context.Proceed();
                var state       = (IActionInvokerStateMixin)context.Proxy;
                var timer       = context.TimerStrategy();
                var timerResult = timer.Stop(state.Offset);

                var args                 = state.Arguments;
                var actionDescriptor     = args.ActionDescriptor;
                var controllerDescriptor = args.ActionDescriptor.ControllerDescriptor;
                var actionName           = actionDescriptor.ActionName;
                var actionParams         = actionDescriptor.GetParameters().Select(p => p.ParameterType).ToArray();

                var message = new ActionInvoker.InvokeActionMethod.Message(context.ReturnValue.GetType())
                              .AsTimedMessage(timerResult)
                              .AsSourceMessage(controllerDescriptor.ControllerType, controllerDescriptor.ControllerType.GetMethod(actionName, actionParams) ?? controllerDescriptor.ControllerType.GetMethod(actionName + "Async", actionParams))
                              .AsChildActionMessage(state.Arguments.ControllerContext)
                              .AsActionMessage(state.Arguments.ControllerContext)
                              .AsMvcTimelineMessage(MvcTimelineCategory.Controller);

                context.MessageBroker.Publish(message);
            }
예제 #2
0
            public void NewImplementation(IAlternateMethodContext context)
            {
                // BeginInvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary<string, object> parameters, AsyncCallback callback, object state)
                if (context.RuntimePolicyStrategy() == RuntimePolicy.Off)
                {
                    context.Proceed();
                    return;
                }

                var state = (IActionInvokerStateMixin)context.Proxy;
                var timer = context.TimerStrategy();

                state.Arguments = new ActionInvoker.InvokeActionMethod.Arguments(context.Arguments);
                state.Offset    = timer.Start();
                context.Proceed();
            }
예제 #3
0
        /// <summary>
        /// Calls <c>Proceed</c> on the original implementation, if the current <c>RuntimePolicy</c> is not <c>Off</c>, and provides a corresponding <see cref="TimerResult"/>.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="timerResult">The timer result.</param>
        /// <returns>
        /// Returns <c>true</c> if <c>Proceed</c> was called on the original object, and sets <paramref name="timerResult" />. Returns <c>false</c> and sets <paramref name="timerResult" /> to <c>null</c> if <c>RuntimePolicy</c> is <c>Off</c>.
        /// </returns>
        public static bool TryProceedWithTimer(this IAlternateMethodContext context, out TimerResult timerResult)
        {
            if (context.RuntimePolicyStrategy() == RuntimePolicy.Off)
            {
                context.Proceed();
                timerResult = null;
                return(false);
            }

            var timer = context.TimerStrategy();

            timerResult = timer.Time(context.Proceed);
            return(true);
        }