private Candidate <TFilterData> InnerMatch(Message message) { Uri to = message.Headers.To; if (to == null) { return(null); } CandidateSet <TFilterData> cset = null; Candidate <TFilterData> candidate = null; if (this.TryMatchCandidateSet(to, true, out cset)) { candidate = this.GetSingleMatch(cset, message); } if (!this.TryMatchCandidateSet(to, false, out cset)) { return(candidate); } Candidate <TFilterData> singleMatch = this.GetSingleMatch(cset, message); if (singleMatch == null) { return(candidate); } if (candidate != null) { Collection <MessageFilter> filters = new Collection <MessageFilter> { candidate.filter, singleMatch.filter }; throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MultipleFilterMatchesException(System.ServiceModel.SR.GetString("FilterMultipleMatches"), null, filters)); } return(singleMatch); }
public virtual void Add(EndpointAddressMessageFilter filter, TFilterData data) { CandidateSet <TFilterData> set; if (filter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("filter"); } this.filters.Add(filter, data); byte[] mask = this.BuildMask(filter.HeaderLookup); Candidate <TFilterData> candidate = new Candidate <TFilterData>(filter, data, mask, filter.HeaderLookup); this.candidates.Add(filter, candidate); Uri key = filter.Address.Uri; if (filter.IncludeHostNameInComparison) { if (!this.toHostLookup.TryGetValue(key, out set)) { set = new CandidateSet <TFilterData>(); this.toHostLookup.Add(key, set); } } else if (!this.toNoHostLookup.TryGetValue(key, out set)) { set = new CandidateSet <TFilterData>(); this.toNoHostLookup.Add(key, set); } set.candidates.Add(candidate); this.IncrementQNameCount(set, filter.Address); }
public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates) { if (candidates.Count < 2) { return(Task.CompletedTask); } for (int i = 0; i < candidates.Count; ++i) { if (!candidates.IsValidCandidate(i)) { continue; } ref var state = ref candidates[i]; if (state.Endpoint.DisplayName == "GraphQL" && httpContext.WebSockets.IsWebSocketRequest) { candidates.SetValidity(i, false); } if (state.Endpoint.DisplayName == "GraphQL WebSockets" && !httpContext.WebSockets.IsWebSocketRequest) { candidates.SetValidity(i, false); } }
public void Add(PrefixEndpointAddressMessageFilter filter, TFilterData data) { if (filter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("filter"); } filters.Add(filter, data); // Create the candidate byte[] mask = BuildMask(filter.HeaderLookup); Candidate can = new Candidate(filter, data, mask, filter.HeaderLookup); candidates.Add(filter, can); Uri soapToAddress = filter.Address.Uri; CandidateSet cset; if (!TryMatchCandidateSet(soapToAddress, filter.IncludeHostNameInComparison, out cset)) { cset = new CandidateSet(); GetAddressTable(filter.IncludeHostNameInComparison).RegisterUri(soapToAddress, GetComparisonMode(filter.IncludeHostNameInComparison), cset); } cset.candidates.Add(can); IncrementQNameCount(cset, filter.Address); }
public async Task ApplyAsync_HasMatchNoEndpointFound() { // Arrange var policy = new DynamicControllerEndpointMatcherPolicy(SelectorCache, Comparer); var endpoints = new[] { DynamicEndpoint, }; var values = new RouteValueDictionary[] { null, }; var scores = new[] { 0, }; var candidates = new CandidateSet(endpoints, values, scores); Transform = (c, values, state) => { return(new ValueTask <RouteValueDictionary>(new RouteValueDictionary())); }; var httpContext = new DefaultHttpContext() { RequestServices = Services, }; // Act await policy.ApplyAsync(httpContext, candidates); // Assert Assert.Null(candidates[0].Endpoint); Assert.Null(candidates[0].Values); Assert.False(candidates.IsValidCandidate(0)); }
public async Task ApplyAsync_ThrowsForTransformerWithInvalidLifetime() { // Arrange var policy = new DynamicControllerEndpointMatcherPolicy(SelectorCache, Comparer); var endpoints = new[] { DynamicEndpoint, }; var values = new RouteValueDictionary[] { new RouteValueDictionary(new { slug = "test", }), }; var scores = new[] { 0, }; var candidates = new CandidateSet(endpoints, values, scores); Transform = (c, values, state) => { return(new ValueTask <RouteValueDictionary>(new RouteValueDictionary(new { controller = "Home", action = "Index", state }))); }; var httpContext = new DefaultHttpContext() { RequestServices = new ServiceCollection().AddScoped(sp => new CustomTransformer { State = "Invalid" }).BuildServiceProvider(), }; // Act & Assert await Assert.ThrowsAsync <InvalidOperationException>(() => policy.ApplyAsync(httpContext, candidates)); }
public async Task ApplyAsync_NoMatch() { // Arrange var policy = new DynamicControllerEndpointMatcherPolicy(SelectorCache, Comparer); var endpoints = new[] { DynamicEndpoint, }; var values = new RouteValueDictionary[] { null, }; var scores = new[] { 0, }; var candidates = new CandidateSet(endpoints, values, scores); candidates.SetValidity(0, false); Transform = (c, values, state) => { throw new InvalidOperationException(); }; var httpContext = new DefaultHttpContext() { RequestServices = Services, }; // Act await policy.ApplyAsync(httpContext, candidates); // Assert Assert.False(candidates.IsValidCandidate(0)); }
public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates) { if (!HttpMethods.IsPost(httpContext.Request.Method)) { return(Task.CompletedTask); } for (var i = 0; i < candidates.Count; i++) { if (!candidates.IsValidCandidate(i)) { continue; } var required = candidates[i].Endpoint.Metadata.GetMetadata <FormValueRequiredAttribute>(); if (required == null) { continue; } var value = httpContext.Request.Form[required.FormKey]; candidates.SetValidity(i, !string.IsNullOrEmpty(value)); } return(Task.CompletedTask); }
Candidate InnerMatch(Message message) { Uri to = message.Headers.To; if (to == null) { return(null); } CandidateSet cset = null; Candidate can = null; if (TryMatchCandidateSet(to, true /*includeHostNameInComparison*/, out cset)) { can = GetSingleMatch(cset, message); } if (TryMatchCandidateSet(to, false /*includeHostNameInComparison*/, out cset)) { Candidate c = GetSingleMatch(cset, message); if (c != null) { if (can != null) { Collection <MessageFilter> matches = new Collection <MessageFilter>(); matches.Add(can.filter); matches.Add(c.filter); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MultipleFilterMatchesException(SR.FilterMultipleMatches, null, matches)); } can = c; } } return(can); }
public async Task apply_should_have_candidate_for_matched_api_version() { // arrange var feature = new Mock <IApiVersioningFeature>(); var context = new EndpointSelectorContext(); var items = new object[] { new ActionDescriptor() { Properties = { [typeof(ApiVersionModel)] = new ApiVersionModel(new ApiVersion(1, 0)) }, }, }; var endpoint = new Endpoint(c => CompletedTask, new EndpointMetadataCollection(items), default); var candidates = new CandidateSet(new[] { endpoint }, new[] { new RouteValueDictionary() }, new[] { 0 }); var policy = new ApiVersionMatcherPolicy(NewDefaultOptions(), NewReporter(), NewLoggerFactory()); feature.SetupProperty(f => f.RequestedApiVersion, new ApiVersion(1, 0)); var httpContext = NewHttpContext(feature); // act await policy.ApplyAsync(httpContext, context, candidates); // assert candidates.IsValidCandidate(0).Should().BeTrue(); }
public void Create_CreatesCandidateSet() { // Arrange var count = 10; var endpoints = new RouteEndpoint[count]; for (var i = 0; i < endpoints.Length; i++) { endpoints[i] = CreateEndpoint($"/{i}"); } var builder = CreateDfaMatcherBuilder(); var candidates = builder.CreateCandidates(endpoints); // Act var candidateSet = new CandidateSet(candidates); // Assert for (var i = 0; i < candidateSet.Count; i++) { ref var state = ref candidateSet[i]; Assert.True(candidateSet.IsValidCandidate(i)); Assert.Same(endpoints[i], state.Endpoint); Assert.Equal(candidates[i].Score, state.Score); Assert.Null(state.Values); candidateSet.SetValidity(i, false); Assert.False(candidateSet.IsValidCandidate(i)); }
public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } if (candidates == null) { throw new ArgumentNullException(nameof(candidates)); } for (var i = 0; i < candidates.Count; i++) { ref var candidate = ref candidates[i]; var endpoint = candidate.Endpoint; var page = endpoint.Metadata.GetMetadata <PageActionDescriptor>(); if (page != null) { // We found an endpoint instance that has a PageActionDescriptor, but not a // CompiledPageActionDescriptor. Update the CandidateSet. var compiled = _loader.LoadAsync(page); if (compiled.IsCompletedSuccessfully) { candidates.ReplaceEndpoint(i, compiled.Result.Endpoint, candidate.Values); } else { // In the most common case, GetOrAddAsync will return a synchronous result. // Avoid going async since this is a fairly hot path. return(ApplyAsyncAwaited(candidates, compiled, i)); } } }
public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } if (candidates == null) { throw new ArgumentNullException(nameof(candidates)); } // There's no real benefit here from trying to avoid the async state machine. // We only execute on nodes that contain a dynamic policy, and thus always have // to await something. for (var i = 0; i < candidates.Count; i++) { if (!candidates.IsValidCandidate(i)) { continue; } var endpoint = candidates[i].Endpoint; var metadata = endpoint.Metadata.GetMetadata <DynamicControllerMetadata>(); if (metadata == null) { continue; } var matchedValues = candidates[i].Values; var endpoints = _selector.SelectEndpoints(metadata.Values); if (endpoints.Count == 0) { // If there's no match this is a configuration error. We can't really check // during startup that the action you configured exists. throw new InvalidOperationException( "Cannot find the fallback endpoint specified by route values: " + "{ " + string.Join(", ", metadata.Values.Select(kvp => $"{kvp.Key}: {kvp.Value}")) + " }."); } // We need to provide the route values associated with this endpoint, so that features // like URL generation work. var values = new RouteValueDictionary(metadata.Values); // Include values that were matched by the fallback route. foreach (var kvp in matchedValues) { values.TryAdd(kvp.Key, kvp.Value); } // Update the route values candidates.ReplaceEndpoint(i, endpoint, values); // Expand the list of endpoints candidates.ExpandEndpoint(i, endpoints, _comparer); } return(Task.CompletedTask); }
/// <inheritdoc /> public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } if (candidates == null) { throw new ArgumentNullException(nameof(candidates)); } if (IsRequestedApiVersionAmbiguous(httpContext, out var apiVersion)) { return(CompletedTask); } if (apiVersion == null && Options.AssumeDefaultVersionWhenUnspecified) { apiVersion = TrySelectApiVersion(httpContext, candidates); httpContext.Features.Get <IApiVersioningFeature>().RequestedApiVersion = apiVersion; } var(matched, hasCandidates) = MatchApiVersion(candidates, apiVersion); if (!matched && hasCandidates) { httpContext.SetEndpoint(ClientError(httpContext, candidates)); } return(CompletedTask); }
public async Task apply_should_use_400_endpoint_for_ambiguous_api_version() { // arrange var feature = new Mock <IApiVersioningFeature>(); var errorResponses = new Mock <IErrorResponseProvider>(); var result = new Mock <IActionResult>(); feature.SetupGet(f => f.RequestedApiVersion).Throws(new AmbiguousApiVersionException("Test", new[] { "1.0", "2.0" })); result.Setup(r => r.ExecuteResultAsync(It.IsAny <ActionContext>())).Returns(CompletedTask); errorResponses.Setup(er => er.CreateResponse(It.IsAny <ErrorResponseContext>())).Returns(result.Object); var options = Options.Create(new ApiVersioningOptions() { ErrorResponses = errorResponses.Object }); var policy = new ApiVersionMatcherPolicy(options, NewReporter(), NewLoggerFactory()); var httpContext = NewHttpContext(feature); var context = new EndpointSelectorContext(); var candidates = new CandidateSet(Empty <Endpoint>(), Empty <RouteValueDictionary>(), Empty <int>()); // act await policy.ApplyAsync(httpContext, context, candidates); await context.Endpoint.RequestDelegate(httpContext); // assert result.Verify(r => r.ExecuteResultAsync(It.IsAny <ActionContext>()), Once()); errorResponses.Verify(er => er.CreateResponse(It.Is <ErrorResponseContext>(c => c.StatusCode == 400 && c.ErrorCode == "AmbiguousApiVersion")), Once()); }
public async Task ApplyAsync_PrefersEndpointsWithODataRoutingMetadata() { // Arrange IEdmModel model = EdmCoreModel.Instance; IODataRoutingMetadata routingMetadata = new ODataRoutingMetadata("odata", model, new ODataPathTemplate()); Endpoint[] endpoints = new[] { CreateEndpoint("/", routingMetadata, new HttpMethodMetadata(new[] { "get" })), CreateEndpoint("/", routingMetadata, new HttpMethodMetadata(new[] { "post" })), CreateEndpoint("/", routingMetadata, new HttpMethodMetadata(new[] { "delete" })) }; CandidateSet candidateSet = CreateCandidateSet(endpoints); HttpContext httpContext = CreateHttpContext("POST"); HttpMethodMatcherPolicy httpMethodPolicy = new HttpMethodMatcherPolicy(); ODataRoutingMatcherPolicy policy = CreatePolicy(); // Act await httpMethodPolicy.ApplyAsync(httpContext, candidateSet); await policy.ApplyAsync(httpContext, candidateSet); // Assert Assert.False(candidateSet.IsValidCandidate(0)); Assert.True(candidateSet.IsValidCandidate(1)); Assert.False(candidateSet.IsValidCandidate(2)); }
public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } // The goal of this method is to perform the final matching: // Map between route values matched by the template and the ones we want to expose to the action for binding. // (tweaking the route values is fine here) // Invalidating the candidate if the key/function values are not valid/missing. // Perform overload resolution for functions by looking at the candidates and their metadata. for (var i = 0; i < candidates.Count; i++) { ref CandidateState candidate = ref candidates[i]; if (!candidates.IsValidCandidate(i)) { continue; } IODataRoutingMetadata metadata = candidate.Endpoint.Metadata.OfType <IODataRoutingMetadata>().FirstOrDefault(); if (metadata == null) { continue; } IHttpMethodMetadata httpMetadata = candidate.Endpoint.Metadata.GetMetadata <IHttpMethodMetadata>(); if (httpMetadata == null) { // Check the http method if (metadata.HttpMethods != null && !metadata.HttpMethods.Contains(httpContext.Request.Method)) { candidates.SetValidity(i, false); continue; } } ODataTemplateTranslateContext translatorContext = new ODataTemplateTranslateContext(httpContext, candidate.Values, metadata.Model); try { ODataPath odataPath = _translator.Translate(metadata.Template, translatorContext); if (odataPath != null) { IODataFeature odataFeature = httpContext.ODataFeature(); odataFeature.PrefixName = metadata.Prefix; odataFeature.Model = metadata.Model; odataFeature.Path = odataPath; } else { candidates.SetValidity(i, false); } } catch (Exception) { candidates.SetValidity(i, false); } }
public async Task ApplyAsync_CanReplaceFoundEndpoints() { // Arrange var policy = new DynamicControllerEndpointMatcherPolicy(SelectorCache, Comparer); var endpoints = new[] { DynamicEndpoint, }; var values = new RouteValueDictionary[] { new RouteValueDictionary(new { slug = "test", }), }; var scores = new[] { 0, }; var candidates = new CandidateSet(endpoints, values, scores); Transform = (c, values, state) => { return(new ValueTask <RouteValueDictionary>(new RouteValueDictionary(new { controller = "Home", action = "Index", state }))); }; Filter = (c, values, state, endpoints) => new ValueTask <IReadOnlyList <Endpoint> >(new[] { new Endpoint((ctx) => Task.CompletedTask, new EndpointMetadataCollection(Array.Empty <object>()), "ReplacedEndpoint") }); var httpContext = new DefaultHttpContext() { RequestServices = Services, }; // Act await policy.ApplyAsync(httpContext, candidates); // Assert Assert.Collection( candidates[0].Values.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("action", kvp.Key); Assert.Equal("Index", kvp.Value); }, kvp => { Assert.Equal("controller", kvp.Key); Assert.Equal("Home", kvp.Value); }, kvp => { Assert.Equal("slug", kvp.Key); Assert.Equal("test", kvp.Value); }, kvp => { Assert.Equal("state", kvp.Key); Assert.Same(State, kvp.Value); }); Assert.Equal("ReplacedEndpoint", candidates[0].Endpoint.DisplayName); Assert.True(candidates.IsValidCandidate(0)); }
private static CandidateSet CreateCandidateSet(HttpMethodMetadata[] httpMethodMetadata) { var candidateSet = new CandidateSet( httpMethodMetadata.Select(metadata => CreateEndpoint(metadata)).ToArray(), httpMethodMetadata.Select(metadata => new RouteValueDictionary()).ToArray(), new int[httpMethodMetadata.Length]); return(candidateSet); }
public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates) { for (var i = 0; i < candidates.Count; i++) { ref var candidate = ref candidates[i]; var newEndpoint = _negotiateEndpointCache.GetOrAdd(candidate.Endpoint, CreateNegotiateEndpoint); candidates.ReplaceEndpoint(i, newEndpoint, candidate.Values); }
public void CreateCandidateTest() { driver.Url = "https://teamevotingwebsite.azurewebsites.net/"; driver.FindElement(By.XPath("//a[@href='/Candidates/Index']")).Click(); driver.FindElement(By.XPath("//a[@href='/Candidates/Create']")).Click(); IWebElement firstName = driver.FindElement(By.Id("Candidate_FirstName")); firstName.SendKeys("TestFirstName"); IWebElement lastName = driver.FindElement(By.Id("Candidate_LastName")); lastName.SendKeys("TestLastName"); IWebElement age = driver.FindElement(By.Id("Candidate_Age")); age.Clear(); age.SendKeys("30"); SelectElement region = new SelectElement(driver.FindElement(By.Id("Region_Id"))); region.SelectByIndex(1); SelectElement faction = new SelectElement(driver.FindElement(By.Id("Faction_Id"))); faction.SelectByIndex(1); driver.FindElement(By.CssSelector(".btn.btn-default")).Click(); // create a new candidate using (TeamEVotingDBEntities teamEVotingDBEntities = new TeamEVotingDBEntities()) // check if creation was successful { List <CandidateSet> candidates = teamEVotingDBEntities.CandidateSet.ToList(); CandidateSet cs = candidates.Last(); StringAssert.Contains("TestFirstName", cs.Candidate_FirstName); StringAssert.Contains("TestLastName", cs.Candidate_LastName); Assert.AreEqual(30, cs.Candidate_Age); } IList <IWebElement> deleteButtons = driver.FindElements(By.CssSelector("[href^='/Candidates/Delete/']")); deleteButtons.Last().Click(); driver.FindElement(By.CssSelector(".btn.btn-default")).Click(); // delete the created candidate using (TeamEVotingDBEntities teamEVotingDBEntities = new TeamEVotingDBEntities()) // check if deletion was successful { List <CandidateSet> candidates = teamEVotingDBEntities.CandidateSet.ToList(); CandidateSet cs = candidates.Last(); StringAssert.DoesNotContain("TestFirstName", cs.Candidate_FirstName); StringAssert.DoesNotContain("TestLastName", cs.Candidate_LastName); Assert.AreNotEqual(30, cs.Candidate_Age); } }
public async Task ApplyAsync_HasMatchFindsEndpoint_WithRouteValues() { // Arrange var policy = new DynamicControllerEndpointMatcherPolicy(SelectorCache, Comparer); var endpoints = new[] { DynamicEndpoint, }; var values = new RouteValueDictionary[] { new RouteValueDictionary(new { slug = "test", }), }; var scores = new[] { 0, }; var candidates = new CandidateSet(endpoints, values, scores); Transform = (c, values, state) => { return(new ValueTask <RouteValueDictionary>(new RouteValueDictionary(new { controller = "Home", action = "Index", state }))); }; var httpContext = new DefaultHttpContext() { RequestServices = Services, }; // Act await policy.ApplyAsync(httpContext, candidates); // Assert Assert.Same(ControllerEndpoints[0], candidates[0].Endpoint); Assert.Collection( candidates[0].Values.OrderBy(kvp => kvp.Key), kvp => { Assert.Equal("action", kvp.Key); Assert.Equal("Index", kvp.Value); }, kvp => { Assert.Equal("controller", kvp.Key); Assert.Equal("Home", kvp.Value); }, kvp => { Assert.Equal("slug", kvp.Key); Assert.Equal("test", kvp.Value); }, kvp => { Assert.Equal("state", kvp.Key); Assert.Same(State, kvp.Value); }); Assert.True(candidates.IsValidCandidate(0)); }
public void RemoveCandidate(TItem candidate) { if (!IsSolved) { CandidateSet.Remove(candidate); if (IsSolved) { OnSolved(new ConstraintSolvedEventArgs <TOwner>(Owner)); } } }
// GET: Candidates/Create public ActionResult Create() { CandidateSet candidates = new CandidateSet(); using (TeamEVotingDBEntities teamEVotingDB = new TeamEVotingDBEntities()) { candidates.regions = teamEVotingDB.RegionSet.ToList(); candidates.factions = teamEVotingDB.FactionSet.ToList(); } return(View(candidates)); }
private static bool AllInvalid(CandidateSet candidates) { for (int i = 0; i < candidates.Count; i++) { if (candidates.IsValidCandidate(i)) { return(false); } } return(true); }
public ActionResult GroupCandidates() { CandidateSet candidate = new CandidateSet(); using (TeamEVotingDBEntities teamEVotingDBEntities = new TeamEVotingDBEntities()) { //kasutab Count, Sum, Min, Max, Average käske, LINQ = SQL var candidatesCount = teamEVotingDBEntities.CandidateSet.Count(); var factionsCount = teamEVotingDBEntities.FactionSet.Count(); var regionsCount = teamEVotingDBEntities.RegionSet.Count(); var sumCandidates = teamEVotingDBEntities.CandidateSet.Sum(x => x.Candidate_Age); var youngestCandidate = teamEVotingDBEntities.CandidateSet.Min(x => x.Candidate_Age); var oldestCandidate = teamEVotingDBEntities.CandidateSet.Max(x => x.Candidate_Age); var averageCandidateAge = teamEVotingDBEntities.CandidateSet.Average(x => x.Candidate_Age); ViewBag.candidatesCount = candidatesCount; ViewBag.factionsCount = factionsCount; ViewBag.regionsCount = regionsCount; ViewBag.sumCandidates = sumCandidates; ViewBag.youngestCandidate = youngestCandidate; ViewBag.oldestCandidate = oldestCandidate; ViewBag.averageCandidateAge = averageCandidateAge; var popularBrowser = teamEVotingDBEntities.VisitorInfo.GroupBy(x => x.VisitorBrowser).OrderByDescending(gp => gp.Count()).Take(1).Select(g => g.Key).ToList(); foreach (var item in popularBrowser) { ViewBag.popularBrowser = item; } var popularVisitingTime = teamEVotingDBEntities.VisitorInfo.GroupBy(t => t.Visited_DateTime).OrderByDescending(gp => gp.Count()).Take(1).Select(g => g.Key).ToList(); foreach (var item in popularVisitingTime) { var dateTime = item.Value; var hour = dateTime.Hour; var minute = dateTime.Minute; if (minute < 10) { ViewBag.popularTime = hour + ":0" + minute; } else { ViewBag.popularTime = hour + ":" + minute; } } } return(View()); }
public override Task SelectAsync(HttpContext httpContext, CandidateSet candidates) { for (var i = 0; i < candidates.Count; i++) { if (candidates[i].Endpoint.DisplayName != "/{**catch-all}" || candidates.Count == 1) { httpContext.SetEndpoint(candidates[i].Endpoint); } } return(Task.CompletedTask); }
public List <I_CandidateSet> Generate(I_Network network, I_AgentSet agent_set) { List <I_CandidateSet> canset_list = new List <I_CandidateSet>(); I_CandidateSet canset; foreach (var node in network.NodeList) { canset = new CandidateSet(node, agent_set.AgentList[node.NodeID]); canset_list.Add(canset); } return(canset_list); }
private static CandidateSet CreateCandidateSet(Endpoint[] endpoints) { var values = new RouteValueDictionary[endpoints.Length]; for (var i = 0; i < endpoints.Length; i++) { values[i] = new RouteValueDictionary(); } CandidateSet candidateSet = new CandidateSet(endpoints, values, new int[endpoints.Length]); return(candidateSet); }
Candidate GetSingleMatch(CandidateSet cset, Message message) { int candiCount = cset.candidates.Count; if (cset.qnames.Count == 0) { if (candiCount == 0) { return(null); } else if (candiCount == 1) { return(cset.candidates[0]); } else { Collection <MessageFilter> matches = new Collection <MessageFilter>(); for (int i = 0; i < candiCount; ++i) { matches.Add(cset.candidates[i].filter); } throw TraceUtility.ThrowHelperError(new MultipleFilterMatchesException(SR.FilterMultipleMatches, null, matches), message); } } EndpointAddressProcessor context = CreateProcessor(size); context.ProcessHeaders(message, cset.qnames, headerLookup); Candidate can = null; List <Candidate> candis = cset.candidates; for (int i = 0; i < candiCount; ++i) { if (context.TestMask(candis[i].mask)) { if (can != null) { Collection <MessageFilter> matches = new Collection <MessageFilter>(); matches.Add(can.filter); matches.Add(candis[i].filter); throw TraceUtility.ThrowHelperError(new MultipleFilterMatchesException(SR.FilterMultipleMatches, null, matches), message); } can = candis[i]; } } ReleaseProcessor(context); return(can); }