Exemplo n.º 1
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);
                }

                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;
            }
        }
        /// <summary>
        /// Causes Raygun4Net to listen for exceptions.
        /// </summary>
        /// <param name="config">The HttpConfiguration to attach to.</param>
        /// <param name="generateRaygunClient">An optional function to provide a custom RaygunWebApiClient instance to use for reporting exceptions.</param>
        public static void Attach(HttpConfiguration config, Func <RaygunWebApiClient> generateRaygunClient = null)
        {
            Detach(config);

            var clientCreator = new RaygunWebApiClientProvider(generateRaygunClient);

            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));
        }
Exemplo n.º 3
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;
            }

            var owinAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName.StartsWith("Owin"));

            if (owinAssembly == null)
            {
                config.MessageHandlers.Add(new RaygunWebApiDelegatingHandler());
            }

            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));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Causes Raygun4Net to listen for exceptions.
        /// </summary>
        /// <param name="config">The HttpConfiguration to attach to.</param>
        /// <param name="generateRaygunClient">An optional function to provide a custom RaygunWebApiClient instance to use for reporting exceptions.</param>
        public static void Attach(HttpConfiguration config, Func <RaygunWebApiClient> generateRaygunClient = null)
        {
            Detach(config);

            string applicationVersion;

            if (!string.IsNullOrEmpty(RaygunSettings.Settings.ApplicationVersion))
            {
                applicationVersion = RaygunSettings.Settings.ApplicationVersion;
            }
            else
            {
                var entryAssembly = Assembly.GetCallingAssembly();
                applicationVersion = entryAssembly.GetName().Version.ToString();
            }

            config.MessageHandlers.Add(new RaygunWebApiDelegatingHandler());

            var clientCreator = new RaygunWebApiClientProvider(generateRaygunClient, 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));
        }
    /// <summary>
    /// Causes Raygun4Net to listen for exceptions.
    /// </summary>
    /// <param name="config">The HttpConfiguration to attach to.</param>
    /// <param name="generateRaygunClient">An optional function to provide a custom RaygunWebApiClient instance to use for reporting exceptions.</param>
    public static void Attach(HttpConfiguration config, Func<RaygunWebApiClient> generateRaygunClient = null)
    {
      Detach(config);

      var clientCreator = new RaygunWebApiClientProvider(generateRaygunClient);

      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));
    }
Exemplo n.º 7
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;
              }

              var owinAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName.StartsWith("Owin"));
              if (owinAssembly == null)
              {
            config.MessageHandlers.Add(new RaygunWebApiDelegatingHandler());
              }

              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));
        }
Exemplo n.º 8
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);
            }

            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;
              }
        }