internal ActionParameterContext(ODataRouteBuilder routeBuilder, ODataRouteBuilderContext routeContext) { var odataPathTemplate = routeBuilder.BuildPath(includePrefix: false); RouteContext = routeContext; PathTemplate = RouteContext.PathTemplateHandler.ParseTemplate(odataPathTemplate, Services); }
internal ActionParameterContext(ODataRouteBuilder routeBuilder, ODataRouteBuilderContext routeContext) { RouteContext = routeContext; var template = routeBuilder.BuildPath(includePrefix: false); var prefix = routeBuilder.GetRoutePrefix(); if (routeBuilder.IsNavigationPropertyLink) { var routeTemplates = routeBuilder.ExpandNavigationPropertyLinkTemplate(template); var templates = new List <ActionTemplates>(capacity: routeTemplates.Count); for (var i = 0; i < routeTemplates.Count; i++) { var routeTemplate = routeTemplates[i]; var pathTemplate = routeContext.PathTemplateHandler.SafeParseTemplate(routeTemplate, Services); if (pathTemplate == null) { continue; } if (!string.IsNullOrEmpty(prefix)) { routeTemplate = string.Concat(prefix, "/", routeTemplate); } templates.Add(new ActionTemplates(routeTemplate, pathTemplate)); } Templates = templates.ToArray(); } else { var pathTemplate = routeContext.PathTemplateHandler.SafeParseTemplate(template, Services); if (pathTemplate == null) { Templates = Array.Empty <ActionTemplates>(); } else { if (!string.IsNullOrEmpty(prefix)) { template = string.Concat(prefix, "/", template); } Templates = new[] { new ActionTemplates(template, pathTemplate) }; } } }
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 !); } }
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); }
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); }
internal ODataRouteBuilder(ODataRouteBuilderContext context) => Context = context;