Exemplo n.º 1
0
 internal RegionFinder()
 {
     _regionEndpointProviderV3 = new RegionEndpointProviderV3();
     _regionEndpoints          = BuildRegionEndpoints();
     _root   = BuildRoot();
     _logger = Logger.GetLogger(typeof(RegionFinder));
 }
Exemplo n.º 2
0
        private EndpointSegment FindExactRegion(IList <string> segments, int segmentIndex, EndpointSegment currentEndpointSegment)
        {
            // Return null if there doesn't exist a matching region
            if (segmentIndex < 0)
            {
                return(null);
            }

            var segment = segments[segmentIndex];

            // Move down in the tree, if there exists a child node
            var nextEndpointSegment = currentEndpointSegment.Children.FirstOrDefault(endpointSegment => endpointSegment.Value.Equals(segment));

            if (nextEndpointSegment != null)
            {
                currentEndpointSegment = nextEndpointSegment;
            }

            // Return the value of node if exception is configured with return value
            if (currentEndpointSegment.UseThisValue)
            {
                return(currentEndpointSegment);
            }

            // Check for the region
            var valueToCheck   = string.Empty;
            var dashedSegments = segment.Split('-');

            for (var dashedSegmentIndex = dashedSegments.Length - 1; dashedSegmentIndex >= 0; dashedSegmentIndex--)
            {
                valueToCheck = string.IsNullOrEmpty(valueToCheck) ? dashedSegments[dashedSegmentIndex] : $"{dashedSegments[dashedSegmentIndex]}-{valueToCheck}";
                if (_regionEndpoints.ContainsKey(valueToCheck))
                {
                    return(new EndpointSegment()
                    {
                        RegionEndpoint = _regionEndpoints[valueToCheck],
                        UseThisValue = true
                    });
                }
            }

            return(FindExactRegion(segments, segmentIndex - 1, currentEndpointSegment));
        }