protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) { var allFilters = FiltersStore(controllerContext); FieldInfo dynField = typeof(ControllerActionInvoker).GetField("_getFiltersThunk", BindingFlags.NonPublic | BindingFlags.Instance); var filters = dynField.GetValue(this) as Func <ControllerContext, ActionDescriptor, IEnumerable <Filter> >; var filtersEnum = filters(controllerContext, actionDescriptor); var filterInfo = base.GetFilters(controllerContext, actionDescriptor); var isChild = controllerContext.IsChildAction; var actionFilters = filterInfo.ActionFilters; for (int i = 0; i < actionFilters.Count; i++) { if (!(actionFilters[i] is GlimpseActionFilter)) { //Wrap it for call logging var innerFilter = filtersEnum.Where(f => f.Instance == actionFilters[i]).SingleOrDefault(); var newFilter = new GlimpseActionFilter(actionFilters[i]) { Filter = innerFilter, OnActionExecutedGuid = Guid.NewGuid(), OnActionExecutingGuid = Guid.NewGuid() }; actionFilters[i] = newFilter; //Store metadata for later analysis allFilters.Add(new GlimpseFilterCallMetadata("Action", newFilter.OnActionExecutedGuid, "OnActionExecuted()", innerFilter, isChild)); allFilters.Add(new GlimpseFilterCallMetadata("Action", newFilter.OnActionExecutingGuid, "OnActionExecuting()", innerFilter, isChild)); } } var authorizationFilters = filterInfo.AuthorizationFilters; for (int i = 0; i < authorizationFilters.Count; i++) { if (!(authorizationFilters[i] is GlimpseAuthorizationFilter)) { var innerFilter = filtersEnum.Where(f => f.Instance == authorizationFilters[i]).SingleOrDefault(); var newFilter = new GlimpseAuthorizationFilter(authorizationFilters[i]) { Filter = innerFilter, Guid = Guid.NewGuid() }; authorizationFilters[i] = newFilter; allFilters.Add(new GlimpseFilterCallMetadata("Authorization", newFilter.Guid, "OnAuthorization()", innerFilter, isChild)); } } var exceptionFilters = filterInfo.ExceptionFilters; for (int i = 0; i < exceptionFilters.Count; i++) { if (!(exceptionFilters[i] is GlimpseExceptionFilter)) { var innerFilter = filtersEnum.Where(f => f.Instance == exceptionFilters[i]).SingleOrDefault(); var newFilter = new GlimpseExceptionFilter(exceptionFilters[i]) { Filter = innerFilter, Guid = Guid.NewGuid() }; exceptionFilters[i] = newFilter; allFilters.Add(new GlimpseFilterCallMetadata("Exception", newFilter.Guid, "OnException()", innerFilter, isChild)); } } var resultFilters = filterInfo.ResultFilters; for (int i = 0; i < resultFilters.Count; i++) { if (!(resultFilters[i] is GlimpseResultFilter)) { var innerFilter = filtersEnum.Where(f => f.Instance == resultFilters[i]).SingleOrDefault(); var newFilter = new GlimpseResultFilter(resultFilters[i]) { Filter = innerFilter, OnResultExecutedGuid = Guid.NewGuid(), OnResultExecutingGuid = Guid.NewGuid() }; resultFilters[i] = newFilter; allFilters.Add(new GlimpseFilterCallMetadata("Result", newFilter.OnResultExecutedGuid, "OnResultExecuted()", innerFilter, isChild)); allFilters.Add(new GlimpseFilterCallMetadata("Result", newFilter.OnResultExecutingGuid, "OnResultExecuting()", innerFilter, isChild)); } } return(filterInfo); }
protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) { var allFilters = FiltersStore(controllerContext); FieldInfo dynField = typeof (ControllerActionInvoker).GetField("_getFiltersThunk", BindingFlags.NonPublic | BindingFlags.Instance); var filters = dynField.GetValue(this) as Func<ControllerContext, ActionDescriptor, IEnumerable<Filter>>; var filtersEnum = filters(controllerContext, actionDescriptor); var filterInfo = base.GetFilters(controllerContext, actionDescriptor); var isChild = controllerContext.IsChildAction; var actionFilters = filterInfo.ActionFilters; for (int i = 0; i < actionFilters.Count; i++) { if (!(actionFilters[i] is GlimpseActionFilter)) { //Wrap it for call logging var innerFilter = filtersEnum.Where(f => f.Instance == actionFilters[i]).SingleOrDefault(); var newFilter = new GlimpseActionFilter(actionFilters[i]) { Filter = innerFilter, OnActionExecutedGuid = Guid.NewGuid(), OnActionExecutingGuid = Guid.NewGuid() }; actionFilters[i] = newFilter; //Store metadata for later analysis allFilters.Add(new GlimpseFilterCallMetadata("Action", newFilter.OnActionExecutedGuid, "OnActionExecuted()", innerFilter, isChild)); allFilters.Add(new GlimpseFilterCallMetadata("Action", newFilter.OnActionExecutingGuid, "OnActionExecuting()", innerFilter, isChild)); } } var authorizationFilters = filterInfo.AuthorizationFilters; for (int i = 0; i < authorizationFilters.Count; i++) { if (!(authorizationFilters[i] is GlimpseAuthorizationFilter)) { var innerFilter = filtersEnum.Where(f => f.Instance == authorizationFilters[i]).SingleOrDefault(); var newFilter = new GlimpseAuthorizationFilter(authorizationFilters[i]) { Filter = innerFilter, Guid = Guid.NewGuid() }; authorizationFilters[i] = newFilter; allFilters.Add(new GlimpseFilterCallMetadata("Authorization", newFilter.Guid, "OnAuthorization()", innerFilter, isChild)); } } var exceptionFilters = filterInfo.ExceptionFilters; for (int i = 0; i < exceptionFilters.Count; i++) { if (!(exceptionFilters[i] is GlimpseExceptionFilter)) { var innerFilter = filtersEnum.Where(f => f.Instance == exceptionFilters[i]).SingleOrDefault(); var newFilter = new GlimpseExceptionFilter(exceptionFilters[i]) { Filter = innerFilter, Guid = Guid.NewGuid() }; exceptionFilters[i] = newFilter; allFilters.Add(new GlimpseFilterCallMetadata("Exception", newFilter.Guid, "OnException()", innerFilter, isChild)); } } var resultFilters = filterInfo.ResultFilters; for (int i = 0; i < resultFilters.Count; i++) { if (!(resultFilters[i] is GlimpseResultFilter)) { var innerFilter = filtersEnum.Where(f => f.Instance == resultFilters[i]).SingleOrDefault(); var newFilter = new GlimpseResultFilter(resultFilters[i]) { Filter = innerFilter, OnResultExecutedGuid = Guid.NewGuid(), OnResultExecutingGuid = Guid.NewGuid() }; resultFilters[i] = newFilter; allFilters.Add(new GlimpseFilterCallMetadata("Result", newFilter.OnResultExecutedGuid, "OnResultExecuted()", innerFilter, isChild)); allFilters.Add(new GlimpseFilterCallMetadata("Result", newFilter.OnResultExecutingGuid, "OnResultExecuting()", innerFilter, isChild)); } } return filterInfo; }