Пример #1
0
 internal static bool CheckIgnoreMethodPerformanceAttribute <TClass>(
     ControllerActionDescriptor controllerActionDescriptor, PerformanceMeterMvcOptions <TClass> options)
     where TClass : ControllerBase
 {
     return((options == null || options.UseIgnoreMethodPerformanceAttribute) &&
            controllerActionDescriptor.MethodInfo
            .GetCustomAttributes(typeof(IgnoreMethodPerformanceAttribute), false).Any());
 }
Пример #2
0
 internal static bool CheckAnnotatedAttribute <TClass>(ControllerActionDescriptor controllerActionDescriptor,
                                                       PerformanceMeterMvcOptions <TClass> options, Type attributeType) where TClass : ControllerBase
 {
     return((options == null || options.WatchForAnnotatedWithAttributeOnly) &&
            !controllerActionDescriptor.MethodInfo
            .GetCustomAttributes(attributeType, false).Any() &&
            !controllerActionDescriptor.ControllerTypeInfo
            .GetCustomAttributes(attributeType, false).Any());
 }
Пример #3
0
        internal static bool ShouldWatching <TClass>(HttpRequest request, PerformanceMeterMvcOptions <TClass> options)
            where TClass : ControllerBase
        {
            foreach (var ignored in options.IgnoredPaths)
            {
                if (ignored != null && request.Path.Value.Contains(ignored, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            return(options.ShouldWatching?.Invoke(request) ?? true);
        }
Пример #4
0
        internal static SettingsBuilder <TClass> AddCustomDataFromCustomAttributes <TClass>(this SettingsBuilder <TClass> settingsBuilder, HttpContext context, ControllerActionDescriptor controllerActionDescriptor, PerformanceMeterMvcOptions <TClass> options) where TClass : ControllerBase
        {
            if (options == null || options.AddCustomDataFromCustomAttributes)
            {
                foreach (MethodCustomDataAttribute methodCustomData in controllerActionDescriptor.MethodInfo.GetCustomAttributes(typeof(MethodCustomDataAttribute), false))
                {
                    settingsBuilder = settingsBuilder.CustomData(methodCustomData.Key, methodCustomData.Value);
                }
                if (context.Request.QueryString.HasValue)
                {
                    settingsBuilder = settingsBuilder.CustomData(QueryStringCustomDataKey, context.Request.QueryString.Value);
                }
                if (context.User.Identity.IsAuthenticated)
                {
                    settingsBuilder = settingsBuilder.CustomData(UserIdentityNameCustomDataKey, context.User.Identity.Name);
                }

                // add caller from attributes
                settingsBuilder = settingsBuilder.CallerFrom(context.Connection?.RemoteIpAddress?.ToString() ?? context.Connection?.LocalIpAddress?.ToString());
                foreach (MethodCallerAttribute methodCaller in controllerActionDescriptor.MethodInfo.GetCustomAttributes(typeof(MethodCallerAttribute), false))
                {
                    settingsBuilder = settingsBuilder.CallerFrom(methodCaller.Caller);
                }
            }

            // add route path to custom data
            if (options == null || options.AddRoutePathToCustomData)
            {
                var url = StringBuilderCache.Get()
                          .Append(context.Request.Scheme)
                          .Append("://")
                          .Append(context.Request.Host.Value)
                          .Append(context.Request.PathBase.Value)
                          .Append(context.Request.Path.Value)
                          .Append(context.Request.QueryString.Value)
                          .ToStringRecycle();

                var routeData = context.GetRouteData();
                if (routeData != null)
                {
                    settingsBuilder = settingsBuilder.CustomData(PathCustomDataKey, routeData.Values["controller"] + "/" + routeData.Values["action"]);
                }
                else
                {
                    if (url.Length > 50)
                    {
                        url = url.Remove(50);
                    }
                    settingsBuilder = settingsBuilder.CustomData(PathCustomDataKey, url);
                }
            }

            return(settingsBuilder);
        }
Пример #5
0
 internal static bool CheckExcludedMethods <TClass>(ControllerActionDescriptor controllerActionDescriptor,
                                                    PerformanceMeterMvcOptions <TClass> options) where TClass : ControllerBase
 {
     return(options?.ExcludedMethods?.Contains(controllerActionDescriptor.ActionName) ?? false);
 }
        /// <summary>
        /// Set Action to handle exceptions that occur by default.
        /// </summary>
        /// <typeparam name="TClass">Type of the controller.</typeparam>
        /// <param name="options">The options.</param>
        /// <param name="exceptionHandler">Action to handle exceptions that occur.</param>
        /// <returns>
        /// Returns <see cref="PerformanceMeterMvcOptions{TClass}"/>.
        /// </returns>
        public static PerformanceMeterMvcOptions <TClass> SetDefaultExceptionHandler <TClass>(this PerformanceMeterMvcOptions <TClass> options, Action <Exception> exceptionHandler) where TClass : ControllerBase
        {
            PerformanceMeter <TClass> .SetDefaultExceptionHandler(exceptionHandler);

            return(options);
        }
        /// <summary>
        /// Set the time in minutes to clear collection of the method calls.
        /// </summary>
        /// <typeparam name="TClass">Type of the controller.</typeparam>
        /// <param name="options">The options.</param>
        /// <param name="minutes">Time in minutes to clear list of the method calls.</param>
        /// <returns>
        /// Returns <see cref="PerformanceMeterMvcOptions{TClass}"/>.
        /// </returns>
        public static PerformanceMeterMvcOptions <TClass> SetMethodCallsCacheTime <TClass>(this PerformanceMeterMvcOptions <TClass> options, int minutes) where TClass : ControllerBase
        {
            PerformanceMeter <TClass> .SetMethodCallsCacheTime(minutes);

            return(options);
        }
        /// <summary>
        /// Add common custom data of the controller.
        /// </summary>
        /// <typeparam name="TClass">Type of the controller.</typeparam>
        /// <param name="options">The options.</param>
        /// <param name="key">Key.</param>
        /// <param name="value">Value.</param>
        /// <returns>
        /// Returns <see cref="PerformanceMeterMvcOptions{TClass}"/>.
        /// </returns>
        public static PerformanceMeterMvcOptions <TClass> AddCustomData <TClass>(this PerformanceMeterMvcOptions <TClass> options, string key, object value) where TClass : ControllerBase
        {
            PerformanceMeter <TClass> .AddCustomData(key, value);

            return(options);
        }
 /// <summary>
 /// Excludes a path from being watched, convenience method for chaining, basically <see cref="PerformanceMeterMvcOptions{TClass}.IgnoredPaths"/>.Add(assembly)
 /// </summary>
 /// <typeparam name="TClass">Type of the controller.</typeparam>
 /// <param name="options">The options to exclude the type on.</param>
 /// <param name="path">The path to exclude from profiled.</param>
 /// <returns>
 /// Returns <see cref="PerformanceMeterMvcOptions{TClass}"/>.
 /// </returns>
 public static PerformanceMeterMvcOptions <TClass> IgnorePath <TClass>(this PerformanceMeterMvcOptions <TClass> options, string path) where TClass : ControllerBase
 {
     options.IgnoredPaths.Add(path);
     return(options);
 }