示例#1
0
        /// <summary>
        /// This method is called before the body of the aspected method is about to be
        /// invoked.
        /// </summary>
        /// <param name="args">Descriptor representing the method call</param>
        /// <param name="result">Result descriptor coming from the previous aspect.</param>
        /// <returns>
        /// This method should return null value indicating that the aspected method's body should
        /// be called. If the method body invocation should be omitted, this method returns the
        /// result descriptor substituting the result coming from the invocation of the method body.
        /// </returns>
        public override IMethodResultDescriptor OnEntry(IMethodCallDescriptor args, IMethodResultDescriptor result)
        {
            if (args.Method.DeclaringType == typeof(IServiceObject))
            {
                return(null);
            }

            CallContext.LogicalSetData(START_TICK_LABEL, EnvironmentInfo.GetCurrentDateTimeUtc().Ticks);
            var details    = new StringBuilder();
            var traceAttrs = args.Method.GetCustomAttributes(typeof(NoArgumentTraceAttribute), true);

            if (traceAttrs.Length == 0)
            {
                for (var i = 0; i < args.ArgumentCount; i++)
                {
                    var arg     = args.GetArgument(i);
                    var argJson = JsonConvert.SerializeObject(arg.Value);
                    details.AppendFormat("{0}: {1}\r\n", arg.Name, argJson);
                }
            }

            var logItem = new TraceLogItem
            {
                Type            = TraceLogItemType.Informational,
                OperationType   = GetOperationName(args),
                Message         = "Enter",
                DetailedMessage = details.ToString()
            };

            Tracer.Log(logItem);
            return(null);
        }
示例#2
0
 /// <summary>
 /// Invokes the OnEntry method on all elements of the aspect chain.
 /// </summary>
 /// <param name="aspects">Aspect chain</param>
 /// <param name="args">Method arguments descriptor</param>
 /// <returns>Result of the execution</returns>
 // ReSharper disable ParameterTypeCanBeEnumerable.Local
 private static IMethodResultDescriptor OnEntry(AspectChain aspects, IMethodCallDescriptor args)
 // ReSharper restore ParameterTypeCanBeEnumerable.Local
 {
     try
     {
         if (aspects == null)
         {
             return(null);
         }
         IMethodResultDescriptor result = null;
         foreach (var aspect in aspects)
         {
             result = aspect.OnEntry(args, null);
             if (result != null)
             {
                 break;
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         throw new AspectInfrastructureException(
                   "Aspect infrastructure exception caught in OnEntry", ex);
     }
 }
示例#3
0
        /// <summary>
        /// This method is called right after the body of the aspected method has been
        /// executed, independently whether it was successful or failed.
        /// </summary>
        /// <param name="args">Descriptor representing the method call</param>
        /// <param name="result">Result descriptor representing the return values of the call</param>
        public override void OnExit(IMethodCallDescriptor args, IMethodResultDescriptor result)
        {
            // --- Decrement current call counters
            PmcManager.GetCounter <CurrentCallsPmc>(TOTAL).Decrement();
            var instanceName = GetInstanceName(args.Method);

            PmcManager.GetCounter <CurrentCallsPmc>(instanceName).Decrement();
        }
示例#4
0
        /// <summary>
        /// This method is called before the body of the aspected method is about to be
        /// invoked.
        /// </summary>
        /// <param name="args">Descriptor representing the method call</param>
        /// <param name="result">Result descriptor coming from the previous aspect.</param>
        /// <returns>
        /// This method should return null value indicating that the aspected method's body should
        /// be called. If the method body invocation should be omitted, this method returns the
        /// result descriptor substituting the result coming from the invocation of the method body.
        /// </returns>
        public override IMethodResultDescriptor OnEntry(IMethodCallDescriptor args, IMethodResultDescriptor result)
        {
            // --- Increment Total counters
            PmcManager.GetCounter <NumberOfCallsPmc>(TOTAL).Increment();
            PmcManager.GetCounter <NumberOfCallsPerSecondsPmc>(TOTAL).Increment();
            PmcManager.GetCounter <CurrentCallsPmc>(TOTAL).Increment();

            // --- Increment operation counters
            var instanceName = GetInstanceName(args.Method);

            PmcManager.GetCounter <NumberOfCallsPmc>(instanceName).Increment();
            PmcManager.GetCounter <NumberOfCallsPerSecondsPmc>(instanceName).Increment();
            PmcManager.GetCounter <CurrentCallsPmc>(instanceName).Increment();

            return(base.OnEntry(args, result));
        }
示例#5
0
 /// <summary>
 /// Invokes the OnExit method on all elements of the aspect chain.
 /// </summary>
 /// <param name="aspects">Aspect chain</param>
 /// <param name="args">Method arguments descriptor</param>
 /// <param name="result">Result of the method call</param>
 /// <returns>Result of the execution</returns>
 private static void OnExit(AspectChain aspects, IMethodCallDescriptor args,
                            IMethodResultDescriptor result)
 {
     try
     {
         if (aspects == null)
         {
             return;
         }
         foreach (var aspect in aspects.Reverse)
         {
             aspect.OnExit(args, result);
         }
     }
     catch (Exception ex)
     {
         throw new AspectInfrastructureException(
                   "Aspect infrastructure exception caught in OnExit", ex);
     }
 }
示例#6
0
 /// <summary>
 /// Invokes the OnSuccess method on all elements of the aspect chain.
 /// </summary>
 /// <param name="aspects">Aspect chain</param>
 /// <param name="args">Method arguments descriptor</param>
 /// <param name="result">Result of the method call</param>
 /// <returns>Result of the execution</returns>
 private static IMethodResultDescriptor OnSuccess(AspectChain aspects, IMethodCallDescriptor args,
                                                  IMethodResultDescriptor result)
 {
     try
     {
         if (aspects != null)
         {
             foreach (var aspect in aspects.Reverse)
             {
                 aspect.OnSuccess(args, result);
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         throw new AspectInfrastructureException(
                   "Aspect infrastructure exception caught in OnSuccess", ex);
     }
 }
 public IMethodResultDescriptor OnEntry(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
     return(null);
 }
示例#8
0
 public IMethodResultDescriptor OnSuccess(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
     return result;
 }
示例#9
0
 public void OnExit(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
 }
示例#10
0
 public IMethodResultDescriptor OnEntry(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
     return result;
 }
 public override IMethodResultDescriptor OnSuccess(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
     VisitInfo += Arg + "S";
     return base.OnSuccess(args, result);
 }
 public override void OnExit(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
     VisitInfo += Arg + "Q";
     base.OnExit(args, result);
 }
 public override IMethodResultDescriptor OnEntry(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
     VisitInfo += Arg + "E";
     return base.OnEntry(args, result);
 }
 public void OnExit(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
 }
 /// <summary>
 /// This method is called before the body of the aspected method is about to be
 /// invoked.
 /// </summary>
 /// <param name="args">Descriptor representing the method call</param>
 /// <param name="result">Result descriptor coming from the previous aspect.</param>
 /// <returns>
 /// This method should return null value indicating that the aspected method's body should
 /// be called. If the method body invocation should be omitted, this method returns the
 /// result descriptor substituting the result coming from the invocation of the method body.
 /// </returns>
 public virtual IMethodResultDescriptor OnEntry(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
     return(result);
 }
示例#16
0
 public override void OnExit(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
     VisitInfo += Arg + "Q";
     base.OnExit(args, result);
 }
示例#17
0
 public override IMethodResultDescriptor OnSuccess(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
     VisitInfo += Arg + "S";
     return(base.OnSuccess(args, result));
 }
示例#18
0
 public override IMethodResultDescriptor OnEntry(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
     VisitInfo += Arg + "E";
     return(base.OnEntry(args, result));
 }
 public IMethodResultDescriptor OnSuccess(IMethodCallDescriptor args, IMethodResultDescriptor result)
 {
     return(result);
 }
示例#20
0
        /// <summary>
        /// This method is called right after <see cref="IMethodAspect.OnExit"/>, when the method body
        /// invocation was successful. Otherwise, the <see cref="IMethodAspect.OnException"/> method is
        /// called.
        /// </summary>
        /// <param name="args">Descriptor representing the method call</param>
        /// <param name="result">Result descriptor representing the return values of the call</param>
        /// <returns>
        /// This method should return the value of <paramref name="result"/> by default, or it
        /// can modify the original result on return that value.
        /// </returns>
        public override IMethodResultDescriptor OnSuccess(IMethodCallDescriptor args, IMethodResultDescriptor result)
        {
            if (args.Method.DeclaringType == typeof(IServiceObject))
            {
                return(null);
            }

            var startTimeData = CallContext.GetData(START_TICK_LABEL);
            var timeSpan      = startTimeData == null
                ? (TimeSpan?)null
                : TimeSpan.FromTicks(EnvironmentInfo.GetCurrentDateTimeUtc().Ticks - (long)startTimeData);

            var logItem = new TraceLogItem
            {
                Type            = TraceLogItemType.Success,
                OperationType   = GetOperationName(args),
                Message         = "Exit",
                DetailedMessage = string.Format("({0} ms)",
                                                timeSpan.HasValue ? timeSpan.Value.Milliseconds.ToString(CultureInfo.InvariantCulture) : "??")
            };

            Tracer.Log(logItem);
            return(result);
        }