/// <summary> /// Method called before the action method starts processing /// </summary> /// <param name="filterContext">An ActionExecutingContext object</param> public override void OnActionExecuting(ActionExecutingContext filterContext) { // First thing is to check if performance is enabled globally. If not, return if (ConfigInfo.Value.PerformanceEnabled == false) { return; } // Second thing, check if performance tracking has been turned off for this action // If the DoNotTrackAttribute is present, then return ActionDescriptor actionDescriptor = filterContext.ActionDescriptor; if (actionDescriptor.GetCustomAttributes(typeof(DoNotTrackPerformanceAttribute), true).Length > 0 || actionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(DoNotTrackPerformanceAttribute), true).Length > 0) { return; } // ActionInfo encapsulates all the info about the action being invoked ActionInfo info = this.CreateActionInfo(filterContext); // PerformanceTracker is the object that tracks performance and is attached to the request PerformanceTracker tracker = new PerformanceTracker(info); // Store this on the request String contextKey = this.GetUniqueContextKey(filterContext.ActionDescriptor.UniqueId); HttpContext.Current.Items.Add(contextKey, tracker); // Process the action start - this is what starts the timer and increments any // required counters before the action executes tracker.ProcessActionStart(); }
/// <summary> /// Method that runs before the Web API action is invoked /// </summary> /// <param name="actionContext">An HttpActionContext with info about the action that is executing</param> public override void OnActionExecuting(HttpActionContext actionContext) { // First thing is to check if performance is enabled globally if (ConfigInfo.Value.PerformanceEnabled == false) { return; } // Second thing is to check if performance tracking has been turned off for this action // If the DoNotTrackAttribute is present, then we set a flag not to track performance and return HttpActionDescriptor actionDescriptor = actionContext.ActionDescriptor; if (actionDescriptor.GetCustomAttributes <DoNotTrackPerformanceAttribute>().Count > 0 || actionDescriptor.ControllerDescriptor.GetCustomAttributes <DoNotTrackPerformanceAttribute>().Count > 0) { return; } // ActionInfo encapsulates all the info about the action being invoked ActionInfo info = this.CreateActionInfo(actionContext); // PerformanceTracker is the object that tracks performance and is attached to the request PerformanceTracker tracker = new PerformanceTracker(info); // Store this on the request actionContext.Request.Properties.Add(this.GetType().FullName, tracker); // Process the action start - this is what starts the timer and increments any // required counters before the action executes tracker.ProcessActionStart(); }