private static ODataRoute CustomMapODataServiceRoute( HttpRouteCollection routes, string routeName, string routePrefix, Func<HttpRequestMessage, IEdmModel> modelProvider, IODataPathHandler pathHandler, IEnumerable<IODataRoutingConvention> routingConventions, ODataBatchHandler batchHandler) { if (!string.IsNullOrEmpty(routePrefix)) { int prefixLastIndex = routePrefix.Length - 1; if (routePrefix[prefixLastIndex] == '/') { routePrefix = routePrefix.Substring(0, routePrefix.Length - 1); } } if (batchHandler != null) { batchHandler.ODataRouteName = routeName; string batchTemplate = string.IsNullOrEmpty(routePrefix) ? ODataRouteConstants.Batch : routePrefix + '/' + ODataRouteConstants.Batch; routes.MapHttpBatchRoute(routeName + "Batch", batchTemplate, batchHandler); } CustomODataPathRouteConstraint routeConstraint = new CustomODataPathRouteConstraint( pathHandler, modelProvider, routeName, routingConventions); CustomODataRoute odataRoute = new CustomODataRoute(routePrefix, routeConstraint); routes.Add(routeName, odataRoute); return odataRoute; }
public static ODataRoute MapODataServiceRoute(this HttpConfiguration configuration, string routeName, string routePrefix, IEdmModel model, IODataPathHandler pathHandler, IEnumerable<IODataRoutingConvention> routingConventions, ODataBatchHandler batchHandler) { if (configuration == null) { throw Error.ArgumentNull("configuration"); } HttpRouteCollection routes = configuration.Routes; routePrefix = RemoveTrailingSlash(routePrefix); if (batchHandler != null) { batchHandler.ODataRouteName = routeName; string batchTemplate = String.IsNullOrEmpty(routePrefix) ? ODataRouteConstants.Batch : routePrefix + '/' + ODataRouteConstants.Batch; routes.MapHttpBatchRoute(routeName + "Batch", batchTemplate, batchHandler); } DefaultODataPathHandler odataPathHandler = pathHandler as DefaultODataPathHandler; if (odataPathHandler != null) { odataPathHandler.ResolverSetttings = configuration.GetResolverSettings(); } ODataPathRouteConstraint routeConstraint = new ODataPathRouteConstraint(pathHandler, model, routeName, routingConventions); ODataRoute route = new ODataRoute(routePrefix, routeConstraint); routes.Add(routeName, route); return route; }
/// <summary> /// Maps the specified OData route and the OData route attributes. When the <paramref name="batchHandler"/> is /// non-<c>null</c>, it will create a '$batch' endpoint to handle the batch requests. /// </summary> /// <param name="configuration">The server configuration.</param> /// <param name="routeName">The name of the route to map.</param> /// <param name="routePrefix">The prefix to add to the OData route's path template.</param> /// <param name="model">The EDM model to use for parsing OData paths.</param> /// <param name="batchHandler">The <see cref="ODataBatchHandler"/>.</param> /// <returns>The added <see cref="ODataRoute"/>.</returns> public static ODataRoute MapODataServiceRoute(this HttpConfiguration configuration, string routeName, string routePrefix, IEdmModel model, ODataBatchHandler batchHandler) { return MapODataServiceRoute(configuration, routeName, routePrefix, model, new DefaultODataPathHandler(), ODataRoutingConventions.CreateDefaultWithAttributeRouting(configuration, model), batchHandler); }
public static ODataRoute MapODataServiceRoute(this HttpRouteCollection routes, string routeName, string routePrefix, IEdmModel model, IODataPathHandler pathHandler, IEnumerable<IODataRoutingConvention> routingConventions, ODataBatchHandler batchHandler) { if (routes == null) { throw Error.ArgumentNull("routes"); } if (!String.IsNullOrEmpty(routePrefix)) { int prefixLastIndex = routePrefix.Length - 1; if (routePrefix[prefixLastIndex] == '/') { // Remove the last trailing slash if it has one. routePrefix = routePrefix.Substring(0, routePrefix.Length - 1); } } if (batchHandler != null) { batchHandler.ODataRouteName = routeName; string batchTemplate = String.IsNullOrEmpty(routePrefix) ? ODataRouteConstants.Batch : routePrefix + '/' + ODataRouteConstants.Batch; routes.MapHttpBatchRoute(routeName + "Batch", batchTemplate, batchHandler); } ODataPathRouteConstraint routeConstraint = new ODataPathRouteConstraint(pathHandler, model, routeName, routingConventions); ODataRoute route = new ODataRoute(routePrefix, routeConstraint); routes.Add(routeName, route); return route; }
/// <summary> /// Maps the specified OData route. When the <paramref name="batchHandler"/> is provided, it will create a /// '$batch' endpoint to handle the batch requests. /// </summary> /// <param name="routes">A collection of routes for the application.</param> /// <param name="routeName">The name of the route to map.</param> /// <param name="routePrefix">The prefix to add to the OData route's path template.</param> /// <param name="model">The EDM model to use for parsing OData paths.</param> /// <param name="batchHandler">The <see cref="ODataBatchHandler"/>.</param> /// <returns>The added <see cref="ODataRoute"/>.</returns> public static ODataRoute MapODataServiceRoute(this HttpRouteCollection routes, string routeName, string routePrefix, IEdmModel model, ODataBatchHandler batchHandler) { return MapODataServiceRoute(routes, routeName, routePrefix, model, new DefaultODataPathHandler(), ODataRoutingConventions.CreateDefault(), batchHandler); }