internal ODataRouteBuilderContext(ODataRouteMapping routeMapping, ControllerActionDescriptor actionDescriptor)
        {
            Contract.Requires(routeMapping != null);
            Contract.Requires(actionDescriptor != null);

            ApiVersion       = routeMapping.ApiVersion;
            serviceProvider  = routeMapping.Services;
            EdmModel         = serviceProvider.GetRequiredService <IEdmModel>();
            routeAttribute   = actionDescriptor.MethodInfo.GetCustomAttributes <ODataRouteAttribute>().FirstOrDefault();
            RouteTemplate    = routeAttribute?.PathTemplate;
            Route            = routeMapping.Route;
            ActionDescriptor = actionDescriptor;
            UrlKeyDelimiter  = serviceProvider.GetRequiredService <ODataOptions>().UrlKeyDelimiter ?? Parentheses;

            var container = EdmModel.EntityContainer;

            if (container == null)
            {
                IsRouteExcluded = true;
                return;
            }

            var controllerName = actionDescriptor.ControllerName;
            var actionName     = actionDescriptor.ActionName;

            EntitySet = container.FindEntitySet(controllerName);
            Operation = container.FindOperationImports(controllerName).FirstOrDefault()?.Operation ??
                        EdmModel.FindDeclaredOperations(string.Concat(container.Namespace, ".", actionName)).FirstOrDefault();
            ActionType = GetActionType(EntitySet, Operation);
        }
        internal ODataRouteBuilderContext(
            ApiVersion apiVersion,
            ODataRouteMapping routeMapping,
            ControllerActionDescriptor actionDescriptor,
            ODataApiVersioningOptions options)
        {
            ApiVersion       = apiVersion;
            Services         = routeMapping.Services;
            routeAttribute   = actionDescriptor.MethodInfo.GetCustomAttributes <ODataRouteAttribute>().FirstOrDefault();
            RouteTemplate    = routeAttribute?.PathTemplate;
            RoutePrefix      = routeMapping.RoutePrefix;
            ActionDescriptor = actionDescriptor;
            Options          = options;
            UrlKeyDelimiter  = UrlKeyDelimiterOrDefault(Services.GetRequiredService <ODataOptions>().UrlKeyDelimiter);

            var selector  = Services.GetRequiredService <IEdmModelSelector>();
            var model     = selector.SelectModel(apiVersion);
            var container = model?.EntityContainer;

            if (model == null || container == null)
            {
                EdmModel        = Services.GetRequiredService <IEdmModel>();
                IsRouteExcluded = true;
                return;
            }

            EdmModel        = model;
            Services        = new FixedEdmModelServiceProviderDecorator(Services, model);
            EntitySet       = container.FindEntitySet(actionDescriptor.ControllerName);
            Singleton       = container.FindSingleton(actionDescriptor.ControllerName);
            Operation       = ResolveOperation(container, actionDescriptor.ActionName);
            ActionType      = GetActionType(actionDescriptor);
            IsRouteExcluded = ActionType == ODataRouteActionType.Unknown;
        }
        internal ODataRouteBuilderContext(
            ODataRouteMapping routeMapping,
            ControllerActionDescriptor actionDescriptor,
            ODataApiExplorerOptions options)
        {
            ApiVersion            = routeMapping.ApiVersion;
            Services              = routeMapping.Services;
            EdmModel              = Services.GetRequiredService <IEdmModel>();
            routeAttribute        = actionDescriptor.MethodInfo.GetCustomAttributes <ODataRouteAttribute>().FirstOrDefault();
            RouteTemplate         = routeAttribute?.PathTemplate;
            Route                 = routeMapping.Route;
            ActionDescriptor      = actionDescriptor;
            ParameterDescriptions = new List <ApiParameterDescription>();
            Options               = options;
            UrlKeyDelimiter       = UrlKeyDelimiterOrDefault(Services.GetRequiredService <ODataOptions>().UrlKeyDelimiter);

            var container = EdmModel.EntityContainer;

            if (container == null)
            {
                IsRouteExcluded = true;
                return;
            }

            var controllerName = actionDescriptor.ControllerName;
            var actionName     = actionDescriptor.ActionName;

            EntitySet = container.FindEntitySet(controllerName);
            Operation = container.FindOperationImports(controllerName).FirstOrDefault()?.Operation ??
                        EdmModel.FindDeclaredOperations(string.Concat(container.Namespace, ".", actionName)).FirstOrDefault();
            ActionType = GetActionType(EntitySet, Operation);
        }
Пример #4
0
        void UpdateBindingInfo(
            ControllerActionDescriptor action,
            ApiVersion apiVersion,
            ODataRouteMapping mapping,
            ICollection <ODataAttributeRouteInfo> routeInfos)
        {
            var routeContext = new ODataRouteBuilderContext(mapping, apiVersion, action, Options);

            if (routeContext.IsRouteExcluded)
            {
                return;
            }

            var routeBuilder     = new ODataRouteBuilder(routeContext);
            var parameterContext = new ActionParameterContext(routeBuilder, routeContext);

            if (!parameterContext.IsSupported)
            {
                return;
            }

            for (var i = 0; i < action.Parameters.Count; i++)
            {
                UpdateBindingInfo(parameterContext, action.Parameters[i]);
            }

            var templates = parameterContext.Templates;

            for (var i = 0; i < templates.Count; i++)
            {
                var template  = templates[i];
                var routeInfo = new ODataAttributeRouteInfo()
                {
                    Template      = template.RouteTemplate,
                    ODataTemplate = template.PathTemplate,
                    RouteName     = mapping.RouteName,
                    RoutePrefix   = mapping.RoutePrefix,
                };

                routeInfos.Add(routeInfo);
            }

            if (routeContext.IsOperation)
            {
                EnsureOperationHttpMethod(action, routeContext.Operation !);
            }
        }
Пример #5
0
            internal void Add(ODataRouteMapping item)
            {
                var key = item.ApiVersion;

                if (dictionary.TryGetValue(key, out var list))
                {
                    list.Add(item);
                }
                else
                {
                    dictionary.Add(key, new List <ODataRouteMapping>()
                    {
                        item
                    });
                }

                items.Add(item);
            }
Пример #6
0
        void UpdateBindingInfo(ControllerActionDescriptor action, ODataRouteMapping mapping, ICollection <ODataAttributeRouteInfo> routeInfos)
        {
            var routeContext     = new ODataRouteBuilderContext(mapping, action, Options);
            var routeBuilder     = new ODataRouteBuilder(routeContext);
            var parameterContext = new ActionParameterContext(routeBuilder, routeContext);

            for (var i = 0; i < action.Parameters.Count; i++)
            {
                UpdateBindingInfo(parameterContext, action.Parameters[i]);
            }

            var routeInfo = new ODataAttributeRouteInfo()
            {
                Template      = routeBuilder.BuildPath(includePrefix: true),
                ODataTemplate = parameterContext.PathTemplate,
            };

            routeInfos.Add(routeInfo);
        }
        static void UpdateBindingInfo(
            ControllerActionDescriptor action,
            ODataRouteMapping mapping,
            ICollection <ODataAttributeRouteInfo> routeInfos)
        {
            string template;
            string path;

            switch (action.ActionName)
            {
            case nameof(MetadataController.GetMetadata):
            case nameof(VersionedMetadataController.GetOptions):
                path = "$metadata";

                if (string.IsNullOrEmpty(mapping.RoutePrefix))
                {
                    template = path;
                }
                else
                {
                    template = mapping.RoutePrefix + '/' + path;
                }

                break;

            default:
                path     = "/";
                template = string.IsNullOrEmpty(mapping.RoutePrefix) ? path : mapping.RoutePrefix;
                break;
            }

            var handler   = mapping.Services.GetRequiredService <IODataPathTemplateHandler>();
            var routeInfo = new ODataAttributeRouteInfo()
            {
                Name          = mapping.RouteName,
                Template      = template,
                ODataTemplate = handler.ParseTemplate(path, mapping.Services),
                RoutePrefix   = mapping.RoutePrefix,
            };

            routeInfos.Add(routeInfo);
        }
        void UpdateBindingInfo(ControllerActionDescriptor action, ODataRouteMapping mapping, ICollection <ODataAttributeRouteInfo> routeInfos)
        {
            Contract.Requires(action != null);
            Contract.Requires(mapping != null);
            Contract.Requires(routeInfos != null);

            var routeContext     = new ODataRouteBuilderContext(mapping, action, Options);
            var routeBuilder     = new ODataRouteBuilder(routeContext);
            var parameterContext = new ActionParameterContext(routeBuilder, routeContext);

            foreach (var parameter in action.Parameters)
            {
                UpdateBindingInfo(parameterContext, parameter);
            }

            var routeInfo = new ODataAttributeRouteInfo()
            {
                Template      = routeBuilder.BuildPath(includePrefix: true),
                ODataTemplate = parameterContext.PathTemplate,
            };

            routeInfos.Add(routeInfo);
        }
Пример #9
0
        internal ODataRouteBuilderContext(
            ODataRouteMapping routeMapping,
            ApiVersion apiVersion,
            ControllerActionDescriptor actionDescriptor,
#if API_EXPLORER
            ODataApiExplorerOptions options)
Пример #10
0
 public int IndexOf(ODataRouteMapping item) => items.IndexOf(item);
Пример #11
0
 public bool Contains(ODataRouteMapping item) => items.Contains(item);
Пример #12
0
 /// <inheritdoc />
 public void Add(ODataRouteMapping item)
 {
     Arg.NotNull(item, nameof(item));
     items.Add(item);
 }
Пример #13
0
 /// <inheritdoc />
 public void Add(ODataRouteMapping item) => items.Add(item ?? throw new ArgumentNullException(nameof(item)));
Пример #14
0
 internal void Add(ODataRouteMapping item) => items.Add(item);