Ejemplo n.º 1
0
        private static void AttachInternal(HttpConfiguration config, Func <HttpRequestMessage, RaygunWebApiClient> generateRaygunClientWithMessage, string applicationVersionFromAttach)
        {
            Detach(config);

            string applicationVersion;

            if (!string.IsNullOrEmpty(RaygunSettings.Settings.ApplicationVersion))
            {
                applicationVersion = RaygunSettings.Settings.ApplicationVersion;
            }
            else
            {
                applicationVersion = applicationVersionFromAttach;
            }

            if (RaygunSettings.Settings.IsRawDataIgnored == false)
            {
                _delegatingHandler = new RaygunWebApiDelegatingHandler();
                config.MessageHandlers.Add(_delegatingHandler);
            }

            var clientCreator = new RaygunWebApiClientProvider(generateRaygunClientWithMessage, applicationVersion);

            config.Services.Add(typeof(IExceptionLogger), new RaygunWebApiExceptionLogger(clientCreator));

            _exceptionFilter = new RaygunWebApiExceptionFilter(clientCreator);
            config.Filters.Add(_exceptionFilter);

            _actionFilter = new RaygunWebApiActionFilter(clientCreator);
            config.Filters.Add(_actionFilter);

            var concreteActivator = config.Services.GetHttpControllerActivator();

            config.Services.Replace(typeof(IHttpControllerActivator), new RaygunWebApiControllerActivator(concreteActivator, clientCreator));

            var concreteControllerSelector = config.Services.GetHttpControllerSelector() ?? new DefaultHttpControllerSelector(config);

            config.Services.Replace(typeof(IHttpControllerSelector), new RaygunWebApiControllerSelector(concreteControllerSelector, clientCreator));

            var concreteActionSelector = config.Services.GetActionSelector() ?? new ApiControllerActionSelector();

            config.Services.Replace(typeof(IHttpActionSelector), new RaygunWebApiActionSelector(concreteActionSelector, clientCreator));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Causes Raygun4Net to stop listening for exceptions.
        /// </summary>
        /// <param name="config">The HttpConfiguration to detach from.</param>
        public static void Detach(HttpConfiguration config)
        {
            if (_exceptionFilter != null)
            {
                int exceptionLoggerIndex = config.Services.FindIndex(typeof(IExceptionLogger), (o) => o is RaygunWebApiExceptionLogger);
                if (exceptionLoggerIndex != -1)
                {
                    config.Services.RemoveAt(typeof(IExceptionLogger), exceptionLoggerIndex);
                }

                if (_delegatingHandler != null)
                {
                    config.MessageHandlers.Remove(_delegatingHandler);
                    _delegatingHandler = null;
                }

                config.Filters.Remove(_exceptionFilter);
                config.Filters.Remove(_actionFilter);

                RaygunWebApiControllerActivator controllerActivator = config.Services.GetHttpControllerActivator() as RaygunWebApiControllerActivator;
                if (controllerActivator != null)
                {
                    config.Services.Replace(typeof(IHttpControllerActivator), controllerActivator.ConcreteActivator);
                }

                RaygunWebApiControllerSelector controllerSelector = config.Services.GetHttpControllerSelector() as RaygunWebApiControllerSelector;
                if (controllerSelector != null)
                {
                    config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector.ConcreteSelector);
                }

                RaygunWebApiActionSelector actionSelector = config.Services.GetActionSelector() as RaygunWebApiActionSelector;
                if (actionSelector != null)
                {
                    config.Services.Replace(typeof(IHttpActionSelector), actionSelector.ConcreteSelector);
                }

                _exceptionFilter = null;
                _actionFilter    = null;
            }
        }