protected override CompanyInfoResult ConvertResult(Base.ConnectionInfo connInfo, System.IO.Stream stream, Base.SettingsBase settings) { List <CompanyInfoData> companies = new List <CompanyInfoData>(); System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US"); XDocument doc = MyHelper.ParseXmlDocument(stream); XElement[] results = XPath.GetElements("//stock", doc); foreach (XElement node in results) { CompanyInfoData stk = new CompanyInfoData(); string name = MyHelper.GetXmlAttributeValue(node, FinanceHelper.NameCompanySymbol); if (name != string.Empty) { stk.SetID(name.ToUpper()); } foreach (XElement propertyNode in node.Elements()) { switch (propertyNode.Name.LocalName) { case FinanceHelper.NameCompanyCompanyName: stk.Name = propertyNode.Value; break; case FinanceHelper.NameCompanyStart: System.DateTime dte1 = default(System.DateTime); if (System.DateTime.TryParse(propertyNode.Value.Replace(FinanceHelper.NameCompanyNotAvailable, "1"), culture, System.Globalization.DateTimeStyles.AssumeUniversal, out dte1)) { stk.StartDate = dte1; } break; case FinanceHelper.NameCompanyEnd: string dateStr = string.Empty; if (propertyNode.Value.IndexOf(FinanceHelper.NameCompanyNotAvailable) > -1) { string[] dates = propertyNode.Value.Split('-'); if (dates.Length >= 3) { if (dates[0].IndexOf(FinanceHelper.NameCompanyNotAvailable) > -1) { dateStr += System.DateTime.Now.Year.ToString() + "-"; } else { dateStr += dates[0] + "-"; } if (dates[1].IndexOf(FinanceHelper.NameCompanyNotAvailable) > -1) { dateStr += System.DateTime.Now.Month.ToString() + "-"; } else { dateStr += dates[1] + "-"; } if (dates[2].IndexOf(FinanceHelper.NameCompanyNotAvailable) > -1) { dateStr += System.DateTime.Now.Day.ToString() + "-"; } else { dateStr += dates[2]; } if (dates.Length > 3) { dateStr += "-"; for (int i = 3; i <= dates.Length - 1; i++) { dateStr += dates[i] + "-"; } } } else { dateStr = propertyNode.Value.Replace(FinanceHelper.NameCompanyNotAvailable, System.DateTime.Now.Month.ToString()); } } System.DateTime dte2; if (System.DateTime.TryParse(dateStr, culture, System.Globalization.DateTimeStyles.AssumeUniversal, out dte2)) { stk.EndDate = dte2; } break; case FinanceHelper.NameCompanySector: stk.SectorName = propertyNode.Value; break; case FinanceHelper.NameCompanyIndustry: stk.IndustryName = propertyNode.Value; break; case FinanceHelper.NameCompanyFullTimeEmployees: int i2 = 0; if (int.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Any, culture, out i2)) { stk.FullTimeEmployees = i2; } break; } } companies.Add(stk); } return(new CompanyInfoResult(companies.ToArray())); }
protected override MarketResult ConvertResult(Base.ConnectionInfo connInfo, System.IO.Stream stream, Base.SettingsBase settings) { MarketDownloadSettings set = (MarketDownloadSettings)settings; if (set.Sectors != null) { List <SectorData> sectors = new List <SectorData>(); System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US"); XParseDocument doc = MyHelper.ParseXmlDocument(stream); XParseElement[] results = XPath.GetElements("//sector", doc); foreach (XParseElement node in results) { System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture; if (culture != null) { ci = culture; } SectorData sect = new SectorData(); string nameAtt = MyHelper.GetXmlAttributeValue(node, FinanceHelper.NameMarketName); if (nameAtt != string.Empty) { for (Sector s = 0; s <= Sector.Utilities; s++) { if (s.ToString().Replace("_", " ") == nameAtt) { sect.ID = s; break; // TODO: might not be correct. Was : Exit For } } } foreach (XParseElement industryNode in node.Elements()) { if (industryNode.Name.LocalName == "industry") { IndustryData ind = new IndustryData(); foreach (XParseAttribute att in industryNode.Attributes()) { if (att.Name.LocalName == FinanceHelper.NameIndustryID) { int i = 0; int.TryParse(att.Value, out i); if (i != 0) { ind.ID = (Industry)i; } } else if (att.Name.LocalName == FinanceHelper.NameMarketName) { ind.Name = att.Value; } } sect.Industries.Add(ind); } } sectors.Add(sect); } return(new SectorResult(sectors.ToArray())); } else if (set.Industries != null) { List <IndustryData> industries = new List <IndustryData>(); System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US"); XParseDocument doc = MyHelper.ParseXmlDocument(stream); XParseElement[] results = XPath.GetElements("//industry", doc); foreach (XParseElement node in results) { IndustryData ind = new IndustryData(); foreach (XParseAttribute att in node.Attributes()) { if (att.Name.LocalName == FinanceHelper.NameIndustryID) { int i = 0; int.TryParse(att.Value, out i); if (i != 0) { ind.ID = (Industry)i; } } else if (att.Name.LocalName == FinanceHelper.NameMarketName) { ind.Name = att.Value; } } foreach (XParseElement companyNode in node.Elements()) { if (companyNode.Name.LocalName == "company") { CompanyInfoData comp = new CompanyInfoData(); foreach (XParseAttribute att in companyNode.Attributes()) { if (att.Name.LocalName == FinanceHelper.NameCompanySymbol) { comp.SetID(att.Value); } else if (att.Name.LocalName == FinanceHelper.NameMarketName) { comp.Name = att.Value; } } ind.Companies.Add(comp); } } industries.Add(ind); } return(new IndustryResult(industries.ToArray())); } else { return(null); } }