2using System.Collections.Generic;
16 private static readonly SortedDictionary<string, string[]> countriesByCode =
new SortedDictionary<string, string[]>(StringComparer.InvariantCultureIgnoreCase);
17 private static readonly SortedDictionary<string, string[]> codesByCountry =
new SortedDictionary<string, string[]>(StringComparer.InvariantCultureIgnoreCase);
19 internal static void Load()
23 XmlDocument Doc =
new XmlDocument();
26 foreach (XmlNode N
in Doc.DocumentElement.ChildNodes)
28 if (N is XmlElement E && E.LocalName ==
"Entry")
33 if (!
string.IsNullOrEmpty(Code) && !
string.IsNullOrEmpty(Country))
35 Add(countriesByCode, Code, Country);
36 Add(codesByCountry, Country, Code);
47 private static void Add(SortedDictionary<
string,
string[]> List,
string Key,
string Value)
49 if (List.TryGetValue(Key, out
string[] Values))
51 int c = Values.Length;
52 Array.Resize(ref Values, c + 1);
57 List[Key] =
new string[] { Value };
67 string[] Result =
new string[countriesByCode.Count];
68 countriesByCode.Keys.CopyTo(Result, 0);
80 string[] Result =
new string[codesByCountry.Count];
81 codesByCountry.Keys.CopyTo(Result, 0);
95 return countriesByCode.TryGetValue(Code, out
Countries);
107 return codesByCountry.TryGetValue(Country, out
Codes);
123 int Best =
int.MaxValue;
126 foreach (
string Code2
in Codes)
136 return !
string.IsNullOrEmpty(Code);
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Static class managing the runtime environment of the IoT Gateway.
static string AppDataFolder
Application data folder.
Data in accordance with ISO 3166
static string[] Countries
Registered ISO-3166-1 Country codes
static bool TryGetShortestCode(string Country, out string Code)
Tries to get the shorted Phone Country Code associated with an ISO 3166-1 Country Code.
static bool TryGetCountries(string Code, out string[] Countries)
Tries to get the ISO 3166-1 Country Codes corresponding to a phone country code. String comparisons a...
static bool TryGetCodes(string Country, out string[] Codes)
Tries to get the Phone Country Codes from a ISO 3166-1 Country Code. String comparisons are case-inse...
static string[] Codes
Registered Phone Country Codes