Ejemplo n.º 1
0
        /// <summary>
        /// Writes the executed result to the debug console.
        /// </summary>
        /// <param name="context">The executed context.</param>
        /// <returns>Null to continue or an instance that implement <see cref="IMethodReturn" />.</returns>
        public override IMethodReturn OnExecuted(FilterExecutedContext context)
        {
            Debug.WriteLine("Executed: {0}.{1}", context.MethodInvocation.Target.GetType().FullName, context.MethodInvocation.MethodBase.Name);

            Debug.WriteLine("  return value = {0}", context.MethodReturn.ReturnValue);

            if (context.MethodReturn.Outputs.Count > 0)
            {
                Debug.WriteLine("  with output arguments:");

                for (var i = 0; i < context.MethodReturn.Outputs.Count; ++i)
                {
                    var parameterInfo = context.MethodReturn.Outputs.GetParameterInfo(i);
                    Debug.WriteLine("    {0} = {1}", parameterInfo.Name, context.MethodReturn.Outputs[i]);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Cache the result.
        /// </summary>
        /// <param name="context">The executed context.</param>
        /// <returns>Null to continue or an instance that implement <see cref="IMethodReturn" />.</returns>
        public override IMethodReturn OnExecuted(FilterExecutedContext context)
        {
            var key = this.GetKeyName(context);

            if (!Cache.Contains(key))
            {
                var policy = new CacheItemPolicy
                {
                    AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddMilliseconds(this.AbsoluteExpiration)),
                    Priority           = CacheItemPriority.Default,
                    SlidingExpiration  = TimeSpan.FromMilliseconds(this.SlidingExpiration),
                };

                var returnValue = context.MethodReturn.ReturnValue;
                if (returnValue != null)
                {
                    Cache.Add(key, context.MethodReturn.ReturnValue, policy);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// When overridden in a derived class, handles after the execution.
 /// </summary>
 /// <param name="context">The executed context.</param>
 /// <returns>Null to continue or an instance that implement <see cref="IMethodReturn"/>.</returns>
 public virtual IMethodReturn OnExecuted(FilterExecutedContext context)
 {
     return(null);
 }