public void RegisterRestPaths(Type requestType)
        {
            var restPaths = new List <RestPath>(AppHost.Routes.Where(p => p.RequestType == requestType));

            foreach (RouteAttribute attr in AppHost.GetRouteAttributes(requestType))
            {
                var restPath = new RestPath(requestType, attr.Path, attr.Verbs, attr.Summary, attr.Notes, attr.Matches);

                if (attr is FallbackRouteAttribute defaultAttr)
                {
                    if (AppHost.Config.FallbackRestPath != null)
                    {
                        throw new NotSupportedException(
                                  "Config.FallbackRestPath is already defined. Only 1 [FallbackRoute] is allowed.");
                    }

                    AppHost.Config.FallbackRestPath = httpReq => restPath.IsMatch(httpReq) ? restPath : null;

                    continue;
                }
                restPaths.Add(restPath);
            }

            foreach (var restPath in restPaths)
            {
                RegisterRestPath(restPath);
            }
        }
Пример #2
0
        public void RegisterRestPaths(Type requestType)
        {
            var attrs = appHost.GetRouteAttributes(requestType);

            foreach (RouteAttribute attr in attrs)
            {
                var restPath = new RestPath(requestType, attr.Path, attr.Verbs, attr.Summary, attr.Notes);

                var defaultAttr = attr as FallbackRouteAttribute;
                if (defaultAttr != null)
                {
                    if (appHost.Config.FallbackRestPath != null)
                    {
                        throw new NotSupportedException(string.Format(
                                                            "Config.FallbackRestPath is already defined. Only 1 [FallbackRoute] is allowed."));
                    }

                    appHost.Config.FallbackRestPath = (httpMethod, pathInfo, filePath) =>
                    {
                        var pathInfoParts = RestPath.GetPathPartsForMatching(pathInfo);
                        return(restPath.IsMatch(httpMethod, pathInfoParts) ? restPath : null);
                    };

                    continue;
                }

                if (!restPath.IsValid)
                {
                    throw new NotSupportedException(string.Format(
                                                        "RestPath '{0}' on Type '{1}' is not Valid", attr.Path, requestType.GetOperationName()));
                }

                RegisterRestPath(restPath);
            }
        }
Пример #3
0
        public void RegisterRestPaths(Type requestType)
        {
            var attrs = appHost.GetRouteAttributes(requestType);
            //foreach (RouteAttribute attr in attrs)
            //{
            //    var restPath = new RestPath(requestType, attr.Path, attr.Verbs, attr.Summary, attr.Notes, attr.Matches)
            //    {
            //        Priority = attr.Priority
            //    };

            //    if (attr is FallbackRouteAttribute defaultAttr)
            //    {
            //        if (appHost.Config.FallbackRestPath != null)
            //            throw new NotSupportedException(
            //                "Config.FallbackRestPath is already defined. Only 1 [FallbackRoute] is allowed.");

            //        appHost.Config.FallbackRestPath = httpReq => restPath.IsMatch(httpReq) ? restPath : null;
            //        fallbackRestPath = restPath;

            //        continue;
            //    }

            //    if (!restPath.IsValid)
            //        throw new NotSupportedException(
            //            $"RestPath '{attr.Path}' on Type '{requestType.GetOperationName()}' is not Valid");

            //    RegisterRestPath(restPath);
            //}
        }