public void NonRoundtripCornerCase() { var template = new PathTemplate("**"); var name = template.ParseName("//service/"); Assert.Equal("//service", name.ToString()); }
public void ExpandWithService_Valid(string templateText, string serviceName, string[] resourceIds, string expectedResult) { var template = new PathTemplate(templateText); var actual = template.ExpandWithService(serviceName, resourceIds); Assert.Equal(expectedResult, actual); }
public DownstreamReRoute( string key, PathTemplate upstreamPathTemplate, List <HeaderFindAndReplace> upstreamHeadersFindAndReplace, List <HeaderFindAndReplace> downstreamHeadersFindAndReplace, List <DownstreamHostAndPort> downstreamAddresses, string serviceName, HttpHandlerOptions httpHandlerOptions, bool useServiceDiscovery, bool enableEndpointEndpointRateLimiting, bool isQos, QoSOptions qosOptionsOptions, string downstreamScheme, string requestIdKey, bool isCached, CacheOptions cacheOptions, string loadBalancer, RateLimitOptions rateLimitOptions, Dictionary <string, string> routeClaimsRequirement, List <ClaimToThing> claimsToQueries, List <ClaimToThing> claimsToHeaders, List <ClaimToThing> claimsToClaims, bool isAuthenticated, bool isAuthorised, AuthenticationOptions authenticationOptions, PathTemplate downstreamPathTemplate, string reRouteKey, List <string> delegatingHandlers, List <AddHeader> addHeadersToDownstream) { AddHeadersToDownstream = addHeadersToDownstream; DelegatingHandlers = delegatingHandlers; Key = key; UpstreamPathTemplate = upstreamPathTemplate; UpstreamHeadersFindAndReplace = upstreamHeadersFindAndReplace ?? new List <HeaderFindAndReplace>(); DownstreamHeadersFindAndReplace = downstreamHeadersFindAndReplace ?? new List <HeaderFindAndReplace>(); DownstreamAddresses = downstreamAddresses ?? new List <DownstreamHostAndPort>(); ServiceName = serviceName; HttpHandlerOptions = httpHandlerOptions; UseServiceDiscovery = useServiceDiscovery; EnableEndpointEndpointRateLimiting = enableEndpointEndpointRateLimiting; IsQos = isQos; QosOptionsOptions = qosOptionsOptions; DownstreamScheme = downstreamScheme; RequestIdKey = requestIdKey; IsCached = isCached; CacheOptions = cacheOptions; LoadBalancer = loadBalancer; RateLimitOptions = rateLimitOptions; RouteClaimsRequirement = routeClaimsRequirement; ClaimsToQueries = claimsToQueries ?? new List <ClaimToThing>(); ClaimsToHeaders = claimsToHeaders ?? new List <ClaimToThing>(); ClaimsToClaims = claimsToClaims ?? new List <ClaimToThing>(); IsAuthenticated = isAuthenticated; IsAuthorised = isAuthorised; AuthenticationOptions = authenticationOptions; DownstreamPathTemplate = downstreamPathTemplate; ReRouteKey = reRouteKey; }
public void ParseName_Invalid(string templateText, string name) { var template = new PathTemplate(templateText); Assert.Throws<FormatException>(() => template.ParseName(name)); ResourceName result; Assert.False(template.TryParseName(name, out result)); Assert.Null(result); }
public ReRoute(PathTemplate downstreamPathTemplate, PathTemplate upstreamPathTemplate, List <HttpMethod> upstreamHttpMethod, UpstreamPathTemplate upstreamTemplatePattern, bool isAuthenticated, AuthenticationOptions authenticationOptions, List <ClaimToThing> claimsToHeaders, List <ClaimToThing> claimsToClaims, Dictionary <string, string> routeClaimsRequirement, bool isAuthorised, List <ClaimToThing> claimsToQueries, string requestIdKey, bool isCached, CacheOptions cacheOptions, string downstreamScheme, string loadBalancer, string reRouteKey, bool isQos, QoSOptions qosOptions, bool enableEndpointRateLimiting, RateLimitOptions ratelimitOptions, HttpHandlerOptions httpHandlerOptions, bool useServiceDiscovery, string serviceName, List <HeaderFindAndReplace> upstreamHeadersFindAndReplace, List <HeaderFindAndReplace> downstreamHeadersFindAndReplace, List <DownstreamHostAndPort> downstreamAddresses, string upstreamHost) { UpstreamHost = upstreamHost; DownstreamHeadersFindAndReplace = downstreamHeadersFindAndReplace ?? new List <HeaderFindAndReplace>(); UpstreamHeadersFindAndReplace = upstreamHeadersFindAndReplace ?? new List <HeaderFindAndReplace>(); ServiceName = serviceName; UseServiceDiscovery = useServiceDiscovery; ReRouteKey = reRouteKey; LoadBalancer = loadBalancer; DownstreamAddresses = downstreamAddresses ?? new List <DownstreamHostAndPort>(); DownstreamPathTemplate = downstreamPathTemplate; UpstreamPathTemplate = upstreamPathTemplate; UpstreamHttpMethod = upstreamHttpMethod; UpstreamTemplatePattern = upstreamTemplatePattern; IsAuthenticated = isAuthenticated; AuthenticationOptions = authenticationOptions; RouteClaimsRequirement = routeClaimsRequirement; IsAuthorised = isAuthorised; RequestIdKey = requestIdKey; IsCached = isCached; CacheOptions = cacheOptions; ClaimsToQueries = claimsToQueries ?? new List <ClaimToThing>(); ClaimsToClaims = claimsToClaims ?? new List <ClaimToThing>(); ClaimsToHeaders = claimsToHeaders ?? new List <ClaimToThing>(); DownstreamScheme = downstreamScheme; IsQos = isQos; QosOptionsOptions = qosOptions; EnableEndpointEndpointRateLimiting = enableEndpointRateLimiting; RateLimitOptions = ratelimitOptions; HttpHandlerOptions = httpHandlerOptions; }
// Path points void LoadPoints(PathTemplate template) { points.Clear(); // Create a lookup table of all points, indexed by local position. foreach (Transform point in template.transform) { if (point.CompareTag("Point")) { points[point.localPosition] = new Point() { position = point.position, connections = new List <Point>(), }; } } // For each line, find and connect the points touching its collider. LayerMask pointMask = LayerMask.GetMask("Points"); ContactFilter2D pointFilter = new ContactFilter2D(); pointFilter.SetLayerMask(pointMask); foreach (Transform line in template.transform) { if (line.CompareTag("Line")) { Vector2 lineVector = line.localRotation * line.localScale; CapsuleCollider2D lineCollider = line.GetComponent <CapsuleCollider2D>(); lineCollider.size = new Vector2(1, 1 + 1 / line.localScale.y); // Find all point colliders touching the line. Collider2D[] pointColls = new Collider2D[10]; lineCollider.OverlapCollider(pointFilter, pointColls); // Convert to a list of points touching the line, ordered by their position along the line. Point[] linePoints = pointColls .Where(coll => coll != null && coll.transform.parent == template.transform) .Select(coll => points[coll.transform.localPosition]) .OrderBy(point => Vector2.Dot(point.position - line.position, lineVector)) .ToArray(); // Connect each point to its adjacent points. for (int i = 0; i < linePoints.Length; i++) { if (i > 0) { linePoints[i].connections.Add(linePoints[i - 1]); } if (i < linePoints.Length - 1) { linePoints[i].connections.Add(linePoints[i + 1]); } } } } }
/// <summary> /// 从请求中解析出路由值 /// </summary> /// <param name="request">请求数据</param> /// <returns>路由值</returns> public IReadOnlyDictionary <string, string> GetRouteValues(RouteRequestData request) { if (Scheme != null && stringComparer.Equals(Scheme, request.Scheme) == false) { return(null); } var routeValues = new Dictionary <string, string>(stringComparer); if (HostTemplate != null) { var values = HostTemplate.GetRouteValues(request.Host); if (values == null) { return(null); } foreach (var pair in values) { routeValues.Add(pair.key, pair.value); } } { var values = PathTemplate.GetRouteValues(request.Path); if (values == null) { return(null); } foreach (var pair in values) { routeValues.Add(pair.Key, pair.Value); } } if (QueryStringTemplate != null) { var values = QueryStringTemplate.GetRouteValues(request.Path); if (values == null) { return(null); } foreach (var pair in values) { routeValues.Add(pair.Key, pair.Value); } } return(routeValues); }
public void ParseName_Invalid(string templateText, string name) { var template = new PathTemplate(templateText); Assert.Throws <FormatException>(() => template.ParseName(name)); TemplatedResourceName result; Assert.False(template.TryParseName(name, out result)); Assert.Null(result); }
public ReRoute(PathTemplate downstreamPathTemplate, PathTemplate upstreamPathTemplate, List <HttpMethod> upstreamHttpMethod, string upstreamTemplatePattern, bool isAuthenticated, AuthenticationOptions authenticationOptions, List <ClaimToThing> claimsToHeaders, List <ClaimToThing> claimsToClaims, Dictionary <string, string> routeClaimsRequirement, bool isAuthorised, List <ClaimToThing> claimsToQueries, string requestIdKey, bool isCached, CacheOptions fileCacheOptions, string downstreamScheme, string loadBalancer, string downstreamHost, int downstreamPort, string reRouteKey, ServiceProviderConfiguration serviceProviderConfiguraion, bool isQos, QoSOptions qosOptions, bool enableEndpointRateLimiting, RateLimitOptions ratelimitOptions, HttpHandlerOptions httpHandlerOptions) { ReRouteKey = reRouteKey; ServiceProviderConfiguraion = serviceProviderConfiguraion; LoadBalancer = loadBalancer; DownstreamHost = downstreamHost; DownstreamPort = downstreamPort; DownstreamPathTemplate = downstreamPathTemplate; UpstreamPathTemplate = upstreamPathTemplate; UpstreamHttpMethod = upstreamHttpMethod; UpstreamTemplatePattern = upstreamTemplatePattern; IsAuthenticated = isAuthenticated; AuthenticationOptions = authenticationOptions; RouteClaimsRequirement = routeClaimsRequirement; IsAuthorised = isAuthorised; RequestIdKey = requestIdKey; IsCached = isCached; CacheOptions = fileCacheOptions; ClaimsToQueries = claimsToQueries ?? new List <ClaimToThing>(); ClaimsToClaims = claimsToClaims ?? new List <ClaimToThing>(); ClaimsToHeaders = claimsToHeaders ?? new List <ClaimToThing>(); DownstreamScheme = downstreamScheme; IsQos = isQos; QosOptionsOptions = qosOptions; EnableEndpointEndpointRateLimiting = enableEndpointRateLimiting; RateLimitOptions = ratelimitOptions; HttpHandlerOptions = httpHandlerOptions; }
public ReRoute(List <DownstreamReRoute> downstreamReRoute, PathTemplate upstreamPathTemplate, List <HttpMethod> upstreamHttpMethod, UpstreamPathTemplate upstreamTemplatePattern, string upstreamHost) { UpstreamHost = upstreamHost; DownstreamReRoute = downstreamReRoute; UpstreamPathTemplate = upstreamPathTemplate; UpstreamHttpMethod = upstreamHttpMethod; UpstreamTemplatePattern = upstreamTemplatePattern; }
public Response <DownstreamPath> Replace(PathTemplate downstreamPathTemplate, List <UrlPathPlaceholderNameAndValue> urlPathPlaceholderNameAndValues) { var downstreamPath = new StringBuilder(); downstreamPath.Append(downstreamPathTemplate.Value); foreach (var placeholderVariableAndValue in urlPathPlaceholderNameAndValues) { downstreamPath.Replace(placeholderVariableAndValue.TemplateVariableName, placeholderVariableAndValue.TemplateVariableValue); } return(new OkResponse <DownstreamPath>(new DownstreamPath(downstreamPath.ToString()))); }
/// <summary> /// Path factory for recycler. /// </summary> /// <param name="isp">Not used.</param> /// <returns></returns> Path CreatePath(ItemState <Path> isp) { var path = default(Path); if (PathTemplate != null) { path = PathTemplate.LoadContent() as Path; } else if (Theme?.PathTemplate != null) { path = Theme.PathTemplate.LoadContent() as Path; } return(path); }
public void LoadLevel(GameObject levelToLoad) { ClearLevel(); GameObject level = Instantiate <GameObject>( levelToLoad, transform.position, Quaternion.identity); level.transform.parent = transform; PathTemplate pathTemplate = level.GetComponentInChildren <PathTemplate>(); LoadPoints(pathTemplate); SpawnTank(GetPointAtPos(pathTemplate.startingPoint.position)); ui.shotCounter.SetCount(0); }
public void ParseName_Valid(string templateText, string name, string[] expectedResourceIds, string expectedServiceName) { var template = new PathTemplate(templateText); var resourceName = template.ParseName(name); for (int i = 0; i < expectedResourceIds.Length; i++) { Assert.Equal(resourceName[i], expectedResourceIds[i]); } Assert.Equal(expectedServiceName, resourceName.ServiceName); // Should round-trip... Assert.Equal(name, resourceName.ToString()); // And TryParse... ResourceName result; Assert.True(template.TryParseName(name, out result)); Assert.NotNull(result); }
/// <summary> /// Path factory for recycler. /// </summary> /// <param name="isp">Not used.</param> /// <returns></returns> Path CreatePath(ItemState <Path> isp) { var path = default(Path); if (PathTemplate != null) { path = PathTemplate.LoadContent() as Path; } else if (Theme?.PathTemplate != null) { path = Theme.PathTemplate.LoadContent() as Path; if (PathStyle != null) { BindTo(this, nameof(PathStyle), path, FrameworkElement.StyleProperty); } } return(path); }
/// <summary> /// Path factory for recycler. /// </summary> /// <param name="isp">Not used.</param> /// <returns></returns> Path CreatePath(ItemState <Path> isp) { var path = default(Path); if (PathTemplate != null) { path = PathTemplate.LoadContent() as Path; } else if (Theme?.PathTemplate != null) { path = Theme.PathTemplate.LoadContent() as Path; } if (path != null) { path.Style = Generator.NextStyle(); } return(path); }
public void ParseName_Valid(string templateText, string name, string[] expectedResourceIds, string expectedServiceName) { var template = new PathTemplate(templateText); var resourceName = template.ParseName(name); for (int i = 0; i < expectedResourceIds.Length; i++) { Assert.Equal(resourceName[i], expectedResourceIds[i]); } Assert.Equal(expectedServiceName, resourceName.ServiceName); // Should round-trip... Assert.Equal(name, resourceName.ToString()); // And TryParse... TemplatedResourceName result; Assert.True(template.TryParseName(name, out result)); Assert.NotNull(result); }
public HttpRequestMessage RewriteRequest(HttpRequestMessage request, IReadOnlyDictionary <string, string> routeValues) { var builder = new UriBuilder(request.RequestUri); builder.Host = HostTemplate.Rewrite(routeValues); builder.Path = PathTemplate.Rewrite(routeValues); if (Port == null) { builder.Port = -1; } else if (Port != "?") { builder.Port = int.Parse(Port); } request.RequestUri = builder.Uri; return(request); }
public void Expand_Valid(string templateText, string[] resourceIds, string expectedResult) { var template = new PathTemplate(templateText); var actual = template.Expand(resourceIds); Assert.Equal(expectedResult, actual); }
public void ExpandWithService_Invalid(string templateText, string serviceName, string[] resourceIds) { var template = new PathTemplate(templateText); Assert.Throws <ArgumentException>(() => template.ExpandWithService(serviceName, resourceIds)); }
public void ExpandWithService_Invalid(string templateText, string serviceName, string[] resourceIds) { var template = new PathTemplate(templateText); Assert.Throws<ArgumentException>(() => template.ExpandWithService(serviceName, resourceIds)); }
public void Expand_Invalid(string templateText, string[] resourceIds) { var template = new PathTemplate(templateText); Assert.Throws<ArgumentException>(() => template.Expand(resourceIds)); }
public void Expand_Invalid(string templateText, string[] resourceIds) { var template = new PathTemplate(templateText); Assert.Throws <ArgumentException>(() => template.Expand(resourceIds)); }