public RouteEntry CreateRoute(DirectRouteFactoryContext context) { var builder = context.CreateBuilder(string.Empty); var action = builder.Actions.First(); var attr = action.GetCustomAttributes<System.Web.Http.RouteAttribute>(true).FirstOrDefault(); if(attr != null) { builder.Template = string.Concat(builder.Template, "/", attr.Template); } var res = context.CreateBuilder(string.Empty).Build(); return res; }
private static IHttpRoute BuildWithResolver( string template, IInlineConstraintResolver constraintResolver ) { HttpActionDescriptor[] actions = new HttpActionDescriptor[] { new ReflectedHttpActionDescriptor() }; DirectRouteFactoryContext context = new DirectRouteFactoryContext( null, actions, constraintResolver, targetIsAction: true ); // Act IDirectRouteBuilder builder = context.CreateBuilder(template); IHttpRoute route = builder.Build().Route; // Assertions for default, unspecified behavior: Assert.NotNull(route); Assert.Equal(actions, route.DataTokens["actions"]); return(route); }
public RouteEntry CreateRoute(DirectRouteFactoryContext context) { if (!context.TargetIsAction) { throw new InvalidOperationException("AutoNamedRouteAttribute should be only used on actions"); } if (!context.Actions.Any()) { throw new InvalidOperationException("Actions should be empty"); } IDirectRouteBuilder builder = context.CreateBuilder(Template); // generate name: // get the first action descriptor from our list because we only need to get its name var actionDescriptor = context.Actions.First(); var controllerDescriptor = actionDescriptor.ControllerDescriptor; var actionName = actionDescriptor.ActionName; var controllerName = controllerDescriptor.ControllerName; // get area also var areaName = getAreaName(controllerDescriptor); // compose a name builder.Name = T4Extensions.ComposeAutoRouteName(areaName, controllerName, actionName); builder.Order = Order; return(builder.Build()); }
public C1PathInfoRouteConstraint(String suffix) { var routeFactory = new DirectRouteFactoryContext(String.Empty, String.Empty, new List <ActionDescriptor>(), new DefaultInlineConstraintResolver(), true); var builder = routeFactory.CreateBuilder(suffix); var route = new Route(builder.Template, builder.Defaults, builder.Constraints, null); _routeInfo = new RouteInfo(route); }
public RouteEntry CreateRoute(DirectRouteFactoryContext context) { IDirectRouteBuilder builder = context.CreateBuilder(Template); builder.Name = Name; builder.Order = Order; return(builder.Build()); }
private static IHttpRoute BuildWithoutResolver(string template, IReadOnlyCollection<HttpActionDescriptor> actions) { DirectRouteFactoryContext context = new DirectRouteFactoryContext(null, actions, new Mock<IInlineConstraintResolver>(MockBehavior.Strict).Object, targetIsAction: true); IDirectRouteBuilder builder = context.CreateBuilder(template, constraintResolver: null); return builder.Build().Route; }
private static IHttpRoute BuildWithoutResolver(string template, IReadOnlyCollection <HttpActionDescriptor> actions) { DirectRouteFactoryContext context = new DirectRouteFactoryContext(null, actions, new Mock <IInlineConstraintResolver>(MockBehavior.Strict).Object, targetIsAction: true); IDirectRouteBuilder builder = context.CreateBuilder(template, constraintResolver: null); return(builder.Build().Route); }
/// <summary> /// Creates a direct route entry. /// </summary> /// <param name="context">The context to use to create the route.</param> /// <returns> /// The direct route entry. /// </returns> public RouteEntry CreateRoute(DirectRouteFactoryContext context) { // context.Actions will always contain at least one action - and all of the // actions will always belong to the same controller. IDirectRouteBuilder builder = context.CreateBuilder(this.Template); builder.Name = this.Name; builder.Order = this.Order; return(builder.Build()); }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { var builder = context.CreateBuilder(Template); builder.Name = Name; builder.Order = Order; builder.DataTokens = new Dictionary <string, object>(); builder.DataTokens["culture"] = Culture ?? "en-US"; return(builder.Build()); }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { var builder = context.CreateBuilder(Template); builder.Name = Name; builder.Order = Order; builder.DataTokens = new Dictionary<string, object>(); builder.DataTokens["culture"] = Culture ?? "en-US"; return builder.Build(); }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { Contract.Assert(context != null); IDirectRouteBuilder builder = context.CreateBuilder(Template); Contract.Assert(builder != null); builder.Name = Name; builder.Order = Order; return builder.Build(); }
public RouteEntry CreateRoute(DirectRouteFactoryContext context) { var builder = context.CreateBuilder(Template); builder.Name = Name; builder.Order = Order; var result = builder.Build(); return(result); //return new RouteEntry(Template, new HttpRoute(Template)); }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { Contract.Assert(context != null); IDirectRouteBuilder builder = context.CreateBuilder(Template); Contract.Assert(builder != null); builder.Name = Name; builder.Order = Order; return(builder.Build()); }
public new RouteEntry CreateRoute(DirectRouteFactoryContext context) { // context.Actions will always contain at least one action - and all of the // actions will always belong to the same controller. var controllerDescriptor = context.Actions.First().ControllerDescriptor; var template = Template.Replace("{controller}", controllerDescriptor.ControllerName); IDirectRouteBuilder builder = context.CreateBuilder(template); builder.Name = controllerDescriptor.ControllerName+"Api"; builder.Order = Order; return builder.Build(); }
public new RouteEntry CreateRoute(DirectRouteFactoryContext context) { // context.Actions will always contain at least one action - and all of the // actions will always belong to the same controller. var controllerDescriptor = context.Actions.First().ControllerDescriptor; var template = Template.Replace("{controller}", controllerDescriptor.ControllerName); IDirectRouteBuilder builder = context.CreateBuilder(template); builder.Name = Name; builder.Order = Order; return(builder.Build()); }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { Contract.Assert(context != null); IDirectRouteBuilder builder = context.CreateBuilder(Template); Contract.Assert(builder != null); builder.Name = Name; builder.Order = Order; var entry = builder.Build(); return(new LocalizedRouteEntry(entry.Name, entry.Route, ExplicitCulture, TranslateUrl)); }
/// <summary> /// Creates <see cref="T:System.Web.Http.Routing.RouteEntry" /> instances based on the provided factories and action. The route entries provide direct routing to the provided action. /// </summary> /// <returns>A set of route entries.</returns> /// <param name="actionDescriptor">The action descriptor.</param> /// <param name="factories">The direct route factories.</param> /// <param name="constraintResolver">The constraint resolver.</param> protected override IReadOnlyList <RouteEntry> GetActionDirectRoutes(HttpActionDescriptor actionDescriptor, IReadOnlyList <IDirectRouteFactory> factories, IInlineConstraintResolver constraintResolver) { Contract.Assume(actionDescriptor != null); // let the DefaultDirectRouteProvider create the normal routes based on all factories var routes = new List <RouteEntry>(base.GetActionDirectRoutes(actionDescriptor, factories, constraintResolver)); // check if the current action is part of the default API version and the action is not version neutral var defaultVersion = actionDescriptor.Configuration.GetApiVersioningOptions().DefaultApiVersion; var versionModel = actionDescriptor.ControllerDescriptor.GetApiVersionModel(); var isDefaultVersionRoute = !versionModel.IsApiVersionNeutral && versionModel.DeclaredApiVersions.Any(v => v == defaultVersion); if (isDefaultVersionRoute) { // find all routes for the action that have a version constraint var versionizedRoutes = routes.Where(r => r.Route.Constraints.Any(c => c.Value is ApiVersionRouteConstraint)).ToArray(); foreach (var versionizedRoute in versionizedRoutes) { // separate the URL template into the path segments var chunks = versionizedRoute.Route.RouteTemplate.Split('/'); // build the {version} string based on the route constraint name var versionConstraint = "{" + versionizedRoute.Route.Constraints.Where( c => c.Value is ApiVersionRouteConstraint).Select(c => c.Key).First() + "}"; // join the segments again together but remove the chunks containing the URL constraint var newRouteTemplate = string.Join("/", chunks.Where(c => !c.Contains(versionConstraint))); // build a new route for the new URL template var context = new DirectRouteFactoryContext(string.Empty, new[] { actionDescriptor }, constraintResolver, false); var builder = context.CreateBuilder(newRouteTemplate); if (!string.IsNullOrEmpty(versionizedRoute.Name)) { builder.Name = versionizedRoute.Name + "DefaultVersion"; } builder.DataTokens = new Dictionary <string, object> { { IsDefaultVersionRouteKey, true } }; routes.Add(builder.Build()); } } return(routes); }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { var action = context.Actions.FirstOrDefault(); var template = string.Format("{0}/{1}", action.ControllerDescriptor.ControllerName, action.ActionName); if (!string.IsNullOrWhiteSpace(Template)) { template += "/" + Template; } var builder = context.CreateBuilder(template); builder.Name = Name; builder.Order = Order; return builder.Build(); }
public RouteEntry CreateRoute(DirectRouteFactoryContext context) { Contract.Assert(context != null); IDirectRouteBuilder builder = context.CreateBuilder(_infoProvider.Template); Contract.Assert(builder != null); builder.Name = _infoProvider.Name; #if ASPNETWEBAPI builder.Order = _infoProvider.Order; #endif return builder.Build(); }
private static IHttpRoute BuildWithResolver(string template, IInlineConstraintResolver constraintResolver) { HttpActionDescriptor[] actions = new HttpActionDescriptor[] { new ReflectedHttpActionDescriptor() }; DirectRouteFactoryContext context = new DirectRouteFactoryContext(null, actions, constraintResolver, targetIsAction: true); // Act IDirectRouteBuilder builder = context.CreateBuilder(template); IHttpRoute route = builder.Build().Route; // Assertions for default, unspecified behavior: Assert.NotNull(route); Assert.Equal(actions, route.DataTokens["actions"]); return route; }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { var action = context.Actions.FirstOrDefault(); var template = string.Format("{0}/{1}", action.ControllerDescriptor.ControllerName, action.ActionName); if (!string.IsNullOrWhiteSpace(Template)) { template += "/" + Template; } var builder = context.CreateBuilder(template); builder.Name = Name; builder.Order = Order; return(builder.Build()); }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { Contract.Assert(context != null); if (context.InlineConstraintResolver is RavenInlineConstraintResolver == false) return FakeRouteEntry; IDirectRouteBuilder builder = context.CreateBuilder(Template); Contract.Assert(builder != null); builder.Name = Name; builder.Order = Order; return builder.Build(); }
public RouteEntry CreateRoute(DirectRouteFactoryContext context) { Contract.Assert(context != null); IDirectRouteBuilder builder = context.CreateBuilder(_infoProvider.Template); Contract.Assert(builder != null); builder.Name = _infoProvider.Name; #if ASPNETWEBAPI builder.Order = _infoProvider.Order; #endif return(builder.Build()); }
protected RouteEntry createRouteInternal(DirectRouteFactoryContext context) { string actionName = context.Actions.FirstOrDefault().ActionName; string controllerName = context.Actions.FirstOrDefault().ControllerDescriptor.ControllerName; string route = $"{controllerName}/{actionName}"; if (DirectRoutingEnabled && RouteEncryptionService.EncryptionUsed()) { route = RouteEncryptionService.GetEncrypted(route); } IDirectRouteBuilder builder = context.CreateBuilder(route); //builder.Name = this.Name; //builder.Order = this.Order; return(builder.Build()); }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { var tmplt = "api" + "/" + Template; var assembly = context.Actions.FirstOrDefault().ControllerDescriptor.ControllerType.Assembly; var plugin = PluginLoader.Instance[assembly]; if (plugin == null) { throw new Exception("has to have a matching plugin"); } IDirectRouteBuilder builder = context.CreateBuilder("modules/" + plugin.Name + "/" + tmplt); builder.Name = Name; builder.Order = Order; return(builder.Build()); }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { Contract.Assert(context != null); if (context.InlineConstraintResolver is RavenInlineConstraintResolver == false) { return(FakeRouteEntry); } IDirectRouteBuilder builder = context.CreateBuilder(Template); Contract.Assert(builder != null); builder.Name = Name; builder.Order = Order; return(builder.Build()); }
public RouteEntry CreateRoute(DirectRouteFactoryContext context) { if (context == null) { throw Error.ArgumentNull("context"); } // Current action method var actionDescriptor = context.Actions.First(); var currentVersion = GetVersion(actionDescriptor); IDirectRouteBuilder builder = context.CreateBuilder(Template); builder.Constraints.Add( new KeyValuePair <string, object>("version", new ApiVersionConstraint(currentVersion))); builder.Name = Name; builder.Order = Order; return(builder.Build()); }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { Contract.Assert(context != null); IDirectRouteBuilder builder = context.CreateBuilder(Template); Contract.Assert(builder != null); var name = Name; if (context.TargetIsAction && String.IsNullOrEmpty(name)) { var actionDescriptor = context.Actions.SingleOrDefault() as IMethodInfoActionDescriptor; if (actionDescriptor != null) { name = "MethodInfo!" + actionDescriptor.MethodInfo.MethodHandle.Value + "_" + Template; } } builder.Name = name; builder.Order = Order; return(builder.Build()); }
RouteEntry IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) { Contract.Assert(context != null); var template = Template; if (AppendRouteSuffix) { var controllerDescriptor = context.Actions.First().ControllerDescriptor; var routeSuffixAttributes = controllerDescriptor.GetCustomAttributes <IRouteSuffix>(inherit: false); foreach (var routeSuffixAttribute in routeSuffixAttributes) { if (routeSuffixAttribute.SuffixType != AppendedRouteSuffixType) { continue; } if (string.IsNullOrEmpty(template)) { template = routeSuffixAttribute.Suffix; } else { template += "/" + routeSuffixAttribute.Suffix; } break; } } IDirectRouteBuilder builder = context.CreateBuilder(template); Contract.Assert(builder != null); builder.Name = Name; builder.Order = Order; return(builder.Build()); }
public IDirectRouteBuilder CreateRouteBuilder(string routeTemplate) { return(_routeFactoryContext.CreateBuilder(routeTemplate)); }
public RouteEntry CreateRoute(DirectRouteFactoryContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } // get the prefix var routePrefixAttributes = context .Actions .First() .ControllerDescriptor .GetCustomAttributes <RoutePrefixAttribute>(); string prefix = null; if (routePrefixAttributes != null && routePrefixAttributes.Any()) { if (routePrefixAttributes.Count > 1) { throw new Exception("Multiple route prefix attributes are not allowed."); } prefix = routePrefixAttributes.Single().Prefix; } string[] templateSplit = Template.Split('/'); string constraintName = $"v_{MinimumValue}_{MaximumValue}"; List <string> routeSegments = new List <string> { "api", $"v{{{constraintName}:int:min({MinimumValue}):max({MaximumValue})}}", prefix }; Constraints = new Dictionary <string, object> { { constraintName, new CompoundRouteConstraint(new List <IHttpRouteConstraint> { new IntRouteConstraint(), new MinRouteConstraint(MinimumValue), new MaxRouteConstraint(MaximumValue) }) } }; routeSegments.AddRange(templateSplit); string newTemplate = string.Join("/", routeSegments); IDirectRouteBuilder builder = context.CreateBuilder(newTemplate); builder.Name = Name; builder.Order = Order; IDictionary <string, object> defaults1 = builder.Defaults; if (defaults1 == null) { builder.Defaults = Defaults; } else { IDictionary <string, object> defaults2 = Defaults; if (defaults2 != null) { foreach (KeyValuePair <string, object> keyValuePair in defaults2) { defaults1[keyValuePair.Key] = keyValuePair.Value; } } } IDictionary <string, object> constraints1 = builder.Constraints; if (constraints1 == null) { builder.Constraints = Constraints; } else { IDictionary <string, object> constraints2 = Constraints; if (constraints2 != null) { foreach (KeyValuePair <string, object> keyValuePair in constraints2) { constraints1[keyValuePair.Key] = keyValuePair.Value; } } } IDictionary <string, object> dataTokens1 = builder.DataTokens; if (dataTokens1 == null) { builder.DataTokens = DataTokens; } else { IDictionary <string, object> dataTokens2 = DataTokens; if (dataTokens2 != null) { foreach (KeyValuePair <string, object> keyValuePair in dataTokens2) { dataTokens1[keyValuePair.Key] = keyValuePair.Value; } } } var result = builder.Build(); return(result); }
/// <inheritdoc /> public RouteEntry CreateRoute(DirectRouteFactoryContext context) { if (context == null) { throw new ArgumentNullException("context"); } IDirectRouteBuilder builder = context.CreateBuilder(Template); Contract.Assert(builder != null); builder.Name = Name; builder.Order = Order; TRouteDictionary builderDefaults = builder.Defaults; if (builderDefaults == null) { builder.Defaults = Defaults; } else { TRouteDictionary defaults = Defaults; if (defaults != null) { foreach (KeyValuePair <string, object> defaultItem in defaults) { builderDefaults[defaultItem.Key] = defaultItem.Value; } } } TRouteDictionary builderConstraints = builder.Constraints; if (builderConstraints == null) { builder.Constraints = Constraints; } else { TRouteDictionary constraints = Constraints; if (constraints != null) { foreach (KeyValuePair <string, object> constraint in constraints) { builderConstraints[constraint.Key] = constraint.Value; } } } TRouteDictionary builderDataTokens = builder.DataTokens; if (builderDataTokens == null) { builder.DataTokens = DataTokens; } else { TRouteDictionary dataTokens = DataTokens; if (dataTokens != null) { foreach (KeyValuePair <string, object> dataToken in dataTokens) { builderDataTokens[dataToken.Key] = dataToken.Value; } } } return(builder.Build()); }
/// <inheritdoc /> public RouteEntry CreateRoute(DirectRouteFactoryContext context) { if (context == null) { throw new ArgumentNullException("context"); } IDirectRouteBuilder builder = context.CreateBuilder(Template); Contract.Assert(builder != null); builder.Name = Name; builder.Order = Order; TRouteDictionary builderDefaults = builder.Defaults; if (builderDefaults == null) { builder.Defaults = Defaults; } else { TRouteDictionary defaults = Defaults; if (defaults != null) { foreach (KeyValuePair<string, object> defaultItem in defaults) { builderDefaults[defaultItem.Key] = defaultItem.Value; } } } TRouteDictionary builderConstraints = builder.Constraints; if (builderConstraints == null) { builder.Constraints = Constraints; } else { TRouteDictionary constraints = Constraints; if (constraints != null) { foreach (KeyValuePair<string, object> constraint in constraints) { builderConstraints[constraint.Key] = constraint.Value; } } } TRouteDictionary builderDataTokens = builder.DataTokens; if (builderDataTokens == null) { builder.DataTokens = DataTokens; } else { TRouteDictionary dataTokens = DataTokens; if (dataTokens != null) { foreach (KeyValuePair<string, object> dataToken in dataTokens) { builderDataTokens[dataToken.Key] = dataToken.Value; } } } return builder.Build(); }