예제 #1
0
        /// <summary>
        /// Gets the controller route.
        /// </summary>
        /// <param name="ctrlType">Type of the control.</param>
        /// <returns></returns>
        protected virtual string GetControllerRoute(Type ctrlType)
        {
            string urlRoot    = _optionsRetriever.GetOptions().UrlRoot;
            string route      = urlRoot + GetControllerName(ctrlType.FullName);
            var    rootAttrib = ctrlType.GetTypeInfo().GetCustomAttribute <ControllerRouteAttribute>();

            if (rootAttrib != null)
            {
                route = rootAttrib.Route ?? "";
            }
            return(route.ToLower().Trim('/'));
        }
예제 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="controllers">All controller contexts</param>
 /// <param name="optionsAccessor">Options accessor</param>
 /// <param name="serializer">JSON serializer</param>
 public DiscoveryHandler(
     ControllerContext[] controllers,
     ILiteApiOptionsAccessor optionsAccessor,
     IJsonSerializer serializer,
     IModelBinder modelBinders)
 {
     if (optionsAccessor == null)
     {
         throw new ArgumentNullException(nameof(optionsAccessor));
     }
     _options      = optionsAccessor.GetOptions();
     _controllers  = controllers ?? throw new ArgumentNullException(nameof(controllers));
     _serializer   = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _modelBinders = modelBinders ?? throw new ArgumentNullException(nameof(modelBinders));
 }
예제 #3
0
        /// <summary>
        /// Initializes filters and possibly other stuff
        /// </summary>
        internal void Init(ILiteApiOptionsAccessor optionsRetriever)
        {
            if (optionsRetriever == null)
            {
                throw new ArgumentNullException(nameof(optionsRetriever));
            }

            if (Filters == null)
            {
                var attribs    = Method.GetCustomAttributes().ToArray();
                var apiFilters = attribs
                                 .Where(x => typeof(IApiFilter).IsAssignableFrom(x.GetType()))
                                 .Cast <IApiFilter>()
                                 .ToArray();
                var asyncFilters = attribs
                                   .Where(x => typeof(IApiFilterAsync).IsAssignableFrom(x.GetType()))
                                   .Cast <IApiFilterAsync>()
                                   .ToArray();
                var policyFilters = attribs
                                    .Where(x => typeof(IPolicyApiFilter).IsAssignableFrom(x.GetType()))
                                    .Cast <IPolicyApiFilter>()
                                    .ToArray();

                Filters = apiFilters.Select(x => new ApiFilterWrapper(x))
                          .Union(asyncFilters.Select(x => new ApiFilterWrapper(x)))
                          .Union(policyFilters.Select(x => new ApiFilterWrapper(x, () => optionsRetriever.GetOptions().AuthorizationPolicyStore)))
                          .ToArray();

                SkipAuth = Method
                           .GetCustomAttributes()
                           .Where(x => typeof(SkipFiltersAttribute) == x.GetType())
                           .Count() > 0;

                DateTimeParsingFormat = (
                    attribs
                    .FirstOrDefault(x => x is DateTimeParsingFormatAttribute)
                    as DateTimeParsingFormatAttribute
                    )?.ParsingFormat;
            }
        }
예제 #4
0
        /// <summary>
        /// Initializes the specified options retriver.
        /// </summary>
        /// <param name="optionsRetriver">The options retriever.</param>
        /// <exception cref="ArgumentNullException">optionsRetriver</exception>
        internal void Init(ILiteApiOptionsAccessor optionsRetriver)
        {
            if (optionsRetriver == null)
            {
                throw new ArgumentNullException(nameof(optionsRetriver));
            }

            if (Filters == null)
            {
                var attributes = ControllerType.GetTypeInfo().GetCustomAttributes().ToArray();
                var apiFilters = attributes
                                 .Where(x => typeof(IApiFilter).IsAssignableFrom(x.GetType()))
                                 .Cast <IApiFilter>()
                                 .ToArray();
                var asyncFilters = attributes
                                   .Where(x => typeof(IApiFilterAsync).IsAssignableFrom(x.GetType()))
                                   .Cast <IApiFilterAsync>()
                                   .ToArray();
                var policyFilters = attributes
                                    .Where(x => typeof(IPolicyApiFilter).IsAssignableFrom(x.GetType()))
                                    .Cast <IPolicyApiFilter>()
                                    .ToArray();
                Filters = apiFilters.Select(x => new ApiFilterWrapper(x))
                          .Union(asyncFilters.Select(x => new ApiFilterWrapper(x)))
                          .Union(policyFilters.Select(x => new ApiFilterWrapper(x, () => optionsRetriver.GetOptions().AuthorizationPolicyStore)))
                          .ToArray();
                DateTimeParsingFormat = (
                    attributes
                    .FirstOrDefault(x => x is DateTimeParsingFormatAttribute)
                    as DateTimeParsingFormatAttribute
                    )?.ParsingFormat;
                foreach (var action in Actions)
                {
                    action.Init(optionsRetriver);
                }
            }
        }