Esempio n. 1
0
        /// <summary>
        ///     Adds a type to a <see cref="FilterCollection" /> if it doesn't already exist.
        /// </summary>
        /// <typeparam name="TType">The type of the t type.</typeparam>
        /// <param name="col">The col.</param>
        /// <param name="order">Filter order</param>
        /// <returns>FilterCollection.</returns>
        public static FilterCollection TryAdd <TType>(this FilterCollection col, int?order = null)
            where TType : IFilterMetadata
        {
            var vt = typeof(TType);

            if (col.All(t =>
            {
                // Yet more lameness, really should be able to do a simple test here...
                return(t switch
                {
                    TypeFilterAttribute tf => tf.ImplementationType != vt,
                    ServiceFilterAttribute sf => sf.ServiceType != vt,
                    FormatFilterAttribute ff => ff.GetType() != vt,
                    ResultFilterAttribute rs => rs.GetType() != vt,
                    ExceptionFilterAttribute ef => ef.GetType() != vt,
                    ActionFilterAttribute af => af.GetType() != vt,
                    _ => t.GetType() != vt
                });
            }
 public override void OnException(HttpActionExecutedContext actionExecutedContext)
 {
     _traceStore.TraceBeginEnd(
         actionExecutedContext.Request,
         TraceCategories.FiltersCategory,
         TraceLevel.Info,
         _innerFilter.GetType().Name,
         OnExceptionMethodName,
         beginTrace: (tr) =>
     {
         HttpResponseMessage response = actionExecutedContext.Response;
         if (response != null)
         {
             tr.Status = response.StatusCode;
         }
     },
         execute: () =>
     {
         _innerFilter.OnException(actionExecutedContext);
     },
         endTrace: (tr) =>
     {
         Exception returnedException = actionExecutedContext.Exception;
         tr.Level     = returnedException == null ? TraceLevel.Info : TraceLevel.Error;
         tr.Exception = returnedException;
         HttpResponseMessage response = actionExecutedContext.Response;
         if (response != null)
         {
             tr.Status = response.StatusCode;
         }
     },
         errorTrace: (tr) =>
     {
         HttpResponseMessage response = actionExecutedContext.Response;
         if (response != null)
         {
             tr.Status = response.StatusCode;
         }
     });
 }