using System.Collections.Generic;
public static Dictionary<string, string> RegionByCountryMap = new Dictionary<string, string>( StringComparer.OrdinalIgnoreCase )
public static Dictionary<string, string[]> RegionByProxyMap = new Dictionary<string, string[]>( StringComparer.OrdinalIgnoreCase )
"il", "md", "de", "ch", "cz", "it", "tr", "fn", "ge", "me", "bg", "gr",
"ro", "se", "fr", "es", "lv", "az", "mc", "ua", "al", "at", "cy", "dk",
"ee", "hu", "lt", "no", "pl", "pt", "si", "na", "sc"
"th", "tn", "my", "id", "sg", "uz", "kz", "am", "kg", "tj", "af", "ae",
"in", "jo", "kh", "mv", "vn"
public static Dictionary<string, string[]> RegionCodeByTopLevelDomainsMap = new Dictionary<string, string[]>( StringComparer.OrdinalIgnoreCase )
public static Dictionary<string, string> RegionCodeByDefaultTopLevelDomainMap = new Dictionary<string, string>( StringComparer.OrdinalIgnoreCase )
public static string GetHost( string env, string countryCode, string regionCode )
if ( env == "qa" && regionCode == "ru" )
if ( env == "qa2" && regionCode == "asia" )
if ( !RegionCodeByDefaultTopLevelDomainMap.TryGetValue( regionCode, out topLevelDomain ) )
string secondLevelDomain = "tlintegration";
string thirdLevelDomain = "ibe";
if ( RegionByCountryMap.ContainsKey( countryCode ) )
string countryRegion = RegionByCountryMap[ countryCode ];
string proxy = RegionByProxyMap.First( code => code.Value.Contains( countryRegion ) ).Key;
List<string> allowedRegionCodes = RegionCodeByTopLevelDomainsMap
.Where( code => code.Value.Contains( proxy ) )
.Select( pair => pair.Key )
if ( allowedRegionCodes.Contains( regionCode ) )
thirdLevelDomain = countryRegion + "-" + thirdLevelDomain;
return $"{thirdLevelDomain}.{secondLevelDomain}.{topLevelDomain}";
private static List<List<string>> TestCases = new List<List<string>>
new List<string> { "qa", "RUS", "ru", "www.qatl.ru" },
new List<string> { "qa2", "RUS", "asia", "www.qatl2.ru" },
new List<string> { "prod", "USA", "asia", "us-ibe.tlintegration.us" },
new List<string> { "prod", "USA", "ru", "ibe.tlintegration.ru" },
new List<string> { "prod", "ABH", "asia", "ibe.tlintegration.eu" },
new List<string> { "prod", "ABH", "ru", "ab-ibe.tlintegration.ru" },
public static void Main()
foreach ( List<string> testCase in TestCases )
string host = RegionMapper.GetHost(testCase[0], testCase[1], testCase[2]);
if ( host != testCase[3] )
Console.WriteLine($"{testCase[0]}, {testCase[1]}, {testCase[2]}, → {host}, expected: {testCase[3]}");