protected IEnumerable <Currency> ParseCurrent(string path) { var source = VSHost.ResolvePath(path); using (var reader = XmlReader.Create(source, s_Settings)) { var root = XElement.Load(reader, LoadOptions.None); var list = root.Element("CcyTbl").Elements("CcyNtry"); foreach (var item in list) { // Currency Alphabetic Code. var codeElement = item.Element("Ccy"); if (codeElement == null) { if (Debug) { Warning("Found a currency without a universal currency: " + item.Element("CtryNm").Value); } continue; } var code = codeElement.Value; // Currency Numeric Code. // NB: Int16.Parse should never fail. var numericCode = Int16.Parse(item.Element("CcyNbr").Value); // Currency English Name. var englishNameElement = item.Element("CcyNm"); var englishName = englishNameElement.Value .Replace("\"", "\"\""); // Fund Currency. bool isFund = false; var isFundAttr = englishNameElement.Attribute("IsFund"); if (isFundAttr != null) { isFund = isFundAttr.Value == "true"; } // Country English Name. var englishRegionName = item.Element("CtryNm").Value .Replace("’", "'") .Replace("\"", "\"\"") .Replace("\n", String.Empty); // Minor Units. var minorUnitsValue = item.Element("CcyMnrUnts").Value; short?minorUnits = null; if (minorUnitsValue != "N.A.") { // NB: ParseTo should never fail. minorUnits = Int16.Parse(minorUnitsValue); } yield return(new Currency { Code = code, EnglishName = englishName, EnglishRegionName = englishRegionName, IsFund = isFund, MinorUnits = minorUnits, NumericCode = numericCode, }); } } }
protected IEnumerable <Currency> ParseLegacy(string path) { var source = VSHost.ResolvePath(path); using (var reader = XmlReader.Create(source, s_Settings)) { var root = XElement.Load(reader, LoadOptions.None); var list = root.Element("HstrcCcyTbl").Elements("HstrcCcyNtry"); foreach (var item in list) { // Currency Alphabetic Code var code = item.Element("Ccy").Value; // Currency Numeric Code // NB: ParseTo should never fail. var numericCodeElement = item.Element("CcyNbr"); short numericCode; if (numericCodeElement == null) { if (Debug) { Warning("Found a legacy currency without a numeric code: " + item.Element("CtryNm").Value); } numericCode = (short)0; } else { numericCode = Int16.Parse(numericCodeElement.Value); } // Currency English Name var englishNameElement = item.Element("CcyNm"); var englishName = englishNameElement.Value .Replace("\"", "\"\""); // Fund Currency bool isFund = false; var isFundAttr = englishNameElement.Attribute("IsFund"); if (isFundAttr != null) { // NB: There are whitespace-only values, there are interpreted to be the same as no attibrute. isFund = isFundAttr.Value == "true"; } // Country English Name var englishRegionName = item.Element("CtryNm").Value .Replace("’", "'") .Replace("\"", "\"\"") .Replace("\n", String.Empty); yield return(new Currency { Code = code, EnglishName = englishName, EnglishRegionName = englishRegionName, IsFund = isFund, IsLegacy = true, NumericCode = numericCode, }); } } }