/// <summary> /// Tries to read a QuoteData from XML /// </summary> /// <param name="node">The XML node of a QuoteData</param> /// <param name="culture">The used culture for formating dates and numbers. If parameter value is null/Nothing, default Culture will be used.</param> /// <returns>The converted quote data or Nothing</returns> /// <remarks></remarks> public static QuotesData ToQuoteData(XParseElement node, System.Globalization.CultureInfo culture = null) { if (node != null && node.Name.LocalName.ToLower() == "quote") { System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture; if (culture != null) { ci = culture; } QuotesData quote = new QuotesData(); foreach (XParseElement propertyNode in node.Elements()) { foreach (QuoteProperty qp in Enum.GetValues(typeof(QuoteProperty))) { if (propertyNode.Name.LocalName == qp.ToString()) { quote[qp] = MyHelper.StringToObject(propertyNode.Value, ci); break; // TODO: might not be correct. Was : Exit For } } } return(quote); } else { return(null); } }
protected override TickerEarningDate ConvertResult(string contentStr, string ticker = "") { XParseDocument doc = MyHelper.ParseXmlDocument(contentStr); #if DEBUG Console.WriteLine(contentStr); #endif XParseElement resultNode = XPath.GetElement("//results/td/strong", doc); if (resultNode == null) { resultNode = XPath.GetElement("//results/td/b", doc); } if (resultNode == null) { return new TickerEarningDate { Ticker = ticker } } ; var dateStr = resultNode.Value; var date = MyHelper.ConvertEarningDate(dateStr); return(new TickerEarningDate { Ticker = ticker, EarningDate = date }); } }
private static void ParseTable(List <NasdaqEarningForecastData> yearly, XParseElement sourceNode, string symbol, string xPath) { var resultNode = sourceNode; if (!(string.IsNullOrWhiteSpace(xPath) || string.IsNullOrEmpty(xPath))) { resultNode = XPath.GetElement(xPath, sourceNode); } int cnt = 0; float tempVal; if (resultNode != null) { foreach (XParseElement node in resultNode.Elements()) { if (node.Name.LocalName == "tr") { cnt++; if (cnt > 1) // skip row header { XParseElement tempNode = null; var data = new NasdaqEarningForecastData(); data.SetID(symbol); tempNode = XPath.GetElement("/td[1]", node); if (tempNode != null) { data.FiscalEnd = HttpUtility.HtmlDecode(tempNode.Value); } tempNode = XPath.GetElement("/td[2]", node); float.TryParse(tempNode.Value, out tempVal); data.ConsensusEpsForecast = tempVal; tempNode = XPath.GetElement("/td[3]", node); float.TryParse(tempNode.Value, out tempVal); data.HighEpsForecast = tempVal; tempNode = XPath.GetElement("/td[4]", node); float.TryParse(tempNode.Value, out tempVal); data.LowEpsForecast = tempVal; tempNode = XPath.GetElement("/td[5]", node); float.TryParse(tempNode.Value, out tempVal); data.NumberOfEstimate = (int)tempVal; tempNode = XPath.GetElement("/td[6]", node); float.TryParse(tempNode.Value, out tempVal); data.NumOfRevisionUp = (int)tempVal; tempNode = XPath.GetElement("/td[7]", node); float.TryParse(tempNode.Value, out tempVal); data.NumOfrevisionDown = (int)tempVal; yearly.Add(data); } } } } }
private void ParseTable(ValuationDataPointAggregate aggregate, XParseElement sourceNode, string ticker, string xPath) { var resultNode = sourceNode; if (!(string.IsNullOrWhiteSpace(xPath) || string.IsNullOrEmpty(xPath))) { resultNode = XPath.GetElement(xPath, sourceNode); } int rowNum = 0; float tempVal; XPathAttribute xpath; object value; XParseElement targetNode, description; ValuationDataPoint data; string extractVal; if (resultNode != null) { foreach (XParseElement row in resultNode.Elements()) { if (row.Name.LocalName == "tr") { rowNum++; if (rowNum > 1 && rowNum <= 3) // skip row header { description = XPath.GetElement("/td[1]/font[1]/b", row); if (description != null) { if (description.Value.Contains("Sector")) { data = new ValuationDataPoint(); data.Context = ContextType.Sector; FillDataPoint(data, row); aggregate.Sector = data; } else if (description.Value.Contains("Industry")) { data = new ValuationDataPoint(); data.Context = ContextType.Industry; FillDataPoint(data, row); aggregate.Industry = data; } } } else if (rowNum > 3) { description = XPath.GetElement("/td[1]/font/a[2]", row); if (description != null && description.Value == ticker) { data = new ValuationDataPoint(); data.Context = ContextType.Equity; FillDataPoint(data, row); aggregate.Self = data; break; } } } } } }
public static string GetXmlAttributeValue(XParseElement node, string attName) { if (node != null) { XParseAttribute att = node.Attribute(XParseName.Get(attName)); if (att != null) { return(att.Value); } } return(string.Empty); }
/// <summary> /// Loads default market information from market.xml /// </summary> /// <remarks></remarks> public static void FillCountriesWithIndices() { XParseDocument xmlDoc = MyHelper.ParseXmlDocument(Properties.Resources.market); XParseElement[] countryNodes = XPath.GetElements("//Resources/Countries/Country", xmlDoc); foreach (XParseElement countryNode in countryNodes) { CountryInfo ctr = null; string ctrIDStr = MyHelper.GetXmlAttributeValue(countryNode, "ID"); foreach (CountryInfo defaultCtr in DefaultCountries) { if (defaultCtr.ID.ToString() == ctrIDStr) { ctr = defaultCtr; break; } } if (ctr != null) { ctr.Indices.Clear(); XParseElement indicesNode = XPath.GetElement("Indices", countryNode); foreach (XParseElement indexNode in indicesNode.Elements()) { if (indexNode.Name.LocalName == "Index") { string name = MyHelper.GetXmlAttributeValue(indexNode, "Name"); string id = MyHelper.GetXmlAttributeValue(indexNode, "ID"); string seStr = MyHelper.GetXmlAttributeValue(indexNode, "StockExchange"); StockExchange se = null; foreach (StockExchange defaultExc in mStockExchanges) { if (defaultExc.ID == seStr) { se = defaultExc; break; } } ctr.Indices.Add(new YIndexID(id) { Name = name, StockExchange = se }); } } } } }
private static void ParseTable(List <SPYValuationDataPoint> metricsHistory, XParseElement sourceNode, string symbol, string xPath) { var resultNode = sourceNode; if (!(string.IsNullOrWhiteSpace(xPath) || string.IsNullOrEmpty(xPath))) { resultNode = XPath.GetElement(xPath, sourceNode); } int cnt = 0; XParseElement targetNode; XPathAttribute xpath; object value; if (resultNode != null) { foreach (XParseElement node in resultNode.Elements()) { if (node.Name.LocalName == "tr") { cnt++; if (cnt > 1) // skip row header { var data = new SPYValuationDataPoint(); foreach (var property in data.GetType().GetProperties()) { xpath = property.GetCustomAttributes(typeof(XPathAttribute), false).FirstOrDefault() as XPathAttribute; if (xpath == null) { continue; } targetNode = XPath.GetElement(xpath.Path, node); var val = targetNode.Value; if (val.Contains("estimate")) { val = MyHelper.ExtractPattern(val, @"(\d*\.\d*).*"); } value = Convert.ChangeType(val, property.PropertyType); property.SetValue(data, value); } metricsHistory.Add(data); } } } } }
protected override PerformanceDataAggregate ConvertResult(string content, string ticker = "") { var aggregate = new PerformanceDataAggregate(ticker); XParseDocument resultNode; var mySetting = Setting as MorningStarValuationSetting; resultNode = MyHelper.GetResultTable(content, 1, "<table class=\"r_table3"); XParseElement tbody = XPath.GetElement("//table/tbody[1]", resultNode); ParseTable(aggregate.StockPerformance, tbody, "Stock"); ParseTable(aggregate.Industryformance, tbody, "Industry"); ParseTable(aggregate.SP500formance, tbody, "SP500"); return(aggregate); }
public U[] GetResult <U> (XParseElement[] rows) where U : new() { List <U> dataList = new List <U>(60); // T aggregate = new T(dataList.ToArray()); XParseElement targetNode = null; XPathAttribute xpath; object value; int rowCount = 0; foreach (XParseElement row in rows) { try { if (rowCount++ == 0) { continue; } U data = new U(); foreach (var property in data.GetType().GetProperties()) { xpath = property.GetCustomAttributes(typeof(XPathAttribute), false).FirstOrDefault() as XPathAttribute; if (xpath == null) { continue; } targetNode = XPath.GetElement(xpath.Path, row); var val = string.IsNullOrWhiteSpace(targetNode.Value) ? "0": targetNode.Value; var conv = TypeDescriptor.GetConverter(property.PropertyType); value = conv.ConvertFromString(val); property.SetValue(data, value); } dataList.Add(data); } catch (Exception ex) { Console.WriteLine(rowCount + ex.Message); } } return(dataList.ToArray()); }
/// <summary> /// Loads as list of default countries from market.xml /// </summary> /// <returns></returns> /// <remarks></remarks> public static CountryInfo[] GetDefaultCountries() { List <CountryInfo> countries = new List <CountryInfo>(); XParseDocument xmlDoc = MyHelper.ParseXmlDocument(Properties.Resources.market); XParseElement[] cntNodes = XPath.GetElements("//Resources/Countries/Country", xmlDoc); System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US"); foreach (XParseElement cntNode in cntNodes) { for (Country cnt = 0; cnt <= Country.VN; cnt++) { if (cnt.ToString() == MyHelper.GetXmlAttributeValue(cntNode, "ID")) { CurrencyInfo cntCur = null; string curID = MyHelper.GetXmlAttributeValue(cntNode, "Currency"); foreach (CurrencyInfo cur in DefaultCurrencies) { if (cur.ID.ToString() == curID) { cntCur = cur; break; } } XParseElement dstNodes = XPath.GetElement("DaylightSavingTimes", cntNode); List <DaylightSavingTime> dstList = new List <DaylightSavingTime>(); foreach (XParseElement dstNode in dstNodes.Elements()) { if (dstNode.Name.LocalName == "DST") { DateTime dstStart = Convert.ToDateTime(MyHelper.GetXmlAttributeValue(dstNode, "Start"), convCulture); DateTime dstEnd = Convert.ToDateTime(MyHelper.GetXmlAttributeValue(dstNode, "End"), convCulture); dstList.Add(new DaylightSavingTime(dstStart, dstEnd)); } } countries.Add(new CountryInfo(cnt, MyHelper.GetXmlAttributeValue(cntNode, "Name"), cntCur, dstList.ToArray())); break; } } } return(countries.ToArray()); }
private SearchData ToSearchResult(XParseElement node) { if (node != null && node.Name.LocalName.ToLower() == "result") { string title = string.Empty; string @abstract = string.Empty; Uri url = null; Uri clickUrl = null; foreach (XParseElement prpNode in node.Elements()) { switch (prpNode.Name.LocalName.ToLower()) { case "title": title = prpNode.Value; break; case "abstract": @abstract = prpNode.Value; break; case "url": if (prpNode.Value.Trim() != string.Empty) { url = new Uri(prpNode.Value); } break; case "clickurl": if (prpNode.Value.Trim() != string.Empty) { clickUrl = new Uri(prpNode.Value); } break; } } return(new SearchData(title, @abstract, url, clickUrl)); } else { return(null); } }
private NewsSearchResult ToBossNewsSearchResult(XParseElement node) { SearchData result = this.ToSearchResult(node); if (result != null) { DateTime crwDate = default(DateTime); Language language = Language.en; string source = string.Empty; Uri sourceUrl = null; foreach (XParseElement prpNode in node.Elements()) { switch (prpNode.Name.LocalName) { case "date": crwDate = new DateTime(1970, 1, 1).AddSeconds(Convert.ToInt32(prpNode.Value)); break; case "language": language = this.StringToLanguage(prpNode.Value); break; case "source": source = prpNode.Value; break; case "sourceurl": if (prpNode.Value.Trim() != string.Empty) { sourceUrl = new Uri(prpNode.Value, UriKind.Absolute); } break; } } return(new NewsSearchResult(result, source, sourceUrl, crwDate, language)); } else { return(null); } }
protected override PositionChangeDataPointAggregate ConvertResult(string contentStr, string ticker = "") { string startPattern = "<table class=\"tableFile\" summary=\"Document Format Files\">"; string endPattern = "</table>"; int startIndex = contentStr.IndexOfOccurence(startPattern, 1); int endIndex = contentStr.IndexOf(endPattern, startIndex); string normalizeContent = contentStr.Substring(startIndex, endIndex - startIndex + endPattern.Length); XParseDocument doc = MyHelper.ParseXmlDocument(normalizeContent); XParseElement resultNode = XPath.GetElement("//table/tr[3]/td[3]/a", doc); var xmlLink = resultNode.Attribute("href").Value; var xmlResult = ParseForm4(GetSecPath(xmlLink)); var aggregate = new PositionChangeDataPointAggregate(xmlResult); aggregate.PopulatePoints(); Console.WriteLine(xmlResult); ////*[@id="formDiv"]/div/table/tbody/tr[3]/td[3]/a return(aggregate); }
private SpellingSearchData ToBossSpellingSearchResult(XParseElement node) { if (node != null && node.Name.LocalName.ToLower() == "result") { string suggestion = string.Empty; foreach (XParseElement prpNode in node.Elements()) { if (prpNode.Name.LocalName == "suggestion") { suggestion = prpNode.Value; } } return(new SpellingSearchData(suggestion)); } else { return(null); } }
private Coordinates GetCoordinates(XParseElement node) { double lat = 0; double lng = 0; foreach (XParseElement coordNode in node.Elements()) { switch (coordNode.Name.LocalName.ToLower()) { case "latitude": double.TryParse(coordNode.Value, System.Globalization.NumberStyles.Any, new System.Globalization.CultureInfo("en-US"), out lat); break; case "longitude": double.TryParse(coordNode.Value, System.Globalization.NumberStyles.Any, new System.Globalization.CultureInfo("en-US"), out lng); break; } } return(new Coordinates(lng, lat)); }
private static void FillDataPoint(ValuationDataPoint data, XParseElement node) { XPathAttribute xpath; object value; XParseElement targetNode; string extractVal; string temp; foreach (var property in data.GetType().GetProperties()) { xpath = GetXPathFromAttribute(property, data.Context.ToString()); if (xpath == null) { continue; } targetNode = XPath.GetElement(xpath.Path, node); if (xpath.Source != string.Empty) { temp = targetNode.Attribute(new XParseName(xpath.Source)).Value; } else { temp = targetNode.Value; } if (temp == "NA") { continue; } extractVal = (xpath.RegexExpression != string.Empty) ? MyHelper.ExtractPattern(temp, xpath.RegexExpression).Replace("\r\n", " ") : temp; value = Convert.ChangeType(extractVal, property.PropertyType); property.SetValue(data, value); } }
private static void ParseTable(List <EarningHistoryData> earningHistory, XParseElement sourceNode, string symbol, string xPath) { var resultNode = sourceNode; if (!(string.IsNullOrWhiteSpace(xPath) || string.IsNullOrEmpty(xPath))) { resultNode = XPath.GetElement(xPath, sourceNode); } int cnt = 0; XParseElement targetNode; XPathAttribute xpath; object value; if (resultNode != null) { foreach (XParseElement node in resultNode.Elements()) { if (node.Name.LocalName == "tr") { cnt++; if (cnt > 1) // skip row header { var data = new EarningHistoryData(); foreach (var property in data.GetType().GetProperties()) { xpath = property.GetCustomAttributes(typeof(XPathAttribute), false).FirstOrDefault() as XPathAttribute; if (xpath == null) { continue; } targetNode = XPath.GetElement(xpath.Path, node); value = Convert.ChangeType(targetNode.Value, property.PropertyType); property.SetValue(data, value); } earningHistory.Add(data); } } } } }
private static void ParseTable(PerformanceData perfData, XParseElement resultNode, string name) { XParseElement targetNode; XPathAttribute xpath; object value; if (resultNode != null) { var data = perfData; foreach (var property in data.GetType().GetProperties()) { xpath = property.GetCustomAttributes(typeof(XPathAttribute), false).Where(attr => ((XPathAttribute)attr).Name == name).FirstOrDefault() as XPathAttribute; targetNode = XPath.GetElement(xpath.Path, resultNode); var val = targetNode.Value; value = Convert.ChangeType(val, property.PropertyType); property.SetValue(data, value); } } }
private DetailedStreetDescription GetStreetContainer(XParseElement node) { DetailedStreetDescription res = null; if (node.Name.LocalName == "street" | node.Name.LocalName == "xstreet" & node.HasElements) { res = new DetailedStreetDescription(); foreach (XParseElement subNode in node.Elements()) { switch (subNode.Name.LocalName) { case "stfull": res.FullName = subNode.Value; break; case "stpredir": res.PrefixDirectional = subNode.Value; break; case "stprefix": res.PrefixType = subNode.Value; break; case "stbody": res.Body = subNode.Value; break; case "stsuffix": res.Suffix = subNode.Value; break; case "stsufdir": res.SuffixDirectional = subNode.Value; break; } } } return(res); }
private WebSearchData ToBossWebSearchResult(XParseElement node) { SearchData result = this.ToSearchResult(node); if (result != null) { string dispUrl = string.Empty; System.DateTime crwDate = default(System.DateTime); Language language = Language.en; string smFeed = string.Empty; foreach (XParseElement prpNode in node.Elements()) { switch (prpNode.Name.LocalName) { case "dispurl": dispUrl = prpNode.Value; break; case "date": System.DateTime.TryParse(prpNode.Value, new System.Globalization.CultureInfo("en-US"), System.Globalization.DateTimeStyles.AssumeUniversal, out crwDate); break; case "language": language = this.StringToLanguage(prpNode.Value); break; case "smfeed": smFeed = prpNode.ToString(); break; } } return(new WebSearchData(result, dispUrl, crwDate, language, smFeed)); } else { return(null); } }
internal PortfolioInfoResult ConvertHtml(XParseDocument doc) { XParseElement resultsNode = XPath.GetElement("//div[@id=\"yfi-main\"]/div/div[2]/form/div/table/tbody", doc); List <PortfolioInfo> lst = new List <PortfolioInfo>(); if (resultsNode != null) { foreach (XParseElement trNode in resultsNode.Elements()) { XParseElement a = XPath.GetElement("/td[2]/a", trNode); if (a != null) { string name = a.Value; XParseAttribute att = a.Attribute(XParseName.Get("href")); if (att != null) { string id = att.Value.Split(';')[0].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[1]; lst.Add(new PortfolioInfo(name, id)); } } } } return(new PortfolioInfoResult(lst.ToArray())); }
protected override AlphabeticIDIndexResult ConvertResult(Base.ConnectionInfo connInfo, System.IO.Stream stream, Base.SettingsBase settings) { AlphabeticIDIndexSettings s = (AlphabeticIDIndexSettings)settings; System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US"); XParseDocument doc = MyHelper.ParseXmlDocument(stream); XParseElement[] resultsNodes = null; switch (s.Type) { case AlphabeticalIndexDownloadType.TopIndex: resultsNodes = XPath.GetElements("//results", doc); List <AlphabeticalTopIndex> lstTopIndex = new List <AlphabeticalTopIndex>(); if (resultsNodes.Length > 0) { XParseElement resultNode = resultsNodes[0]; foreach (XParseElement tdNode in resultNode.Elements()) { foreach (XParseElement aNode in tdNode.Elements()) { if (aNode.Name.LocalName == "a") { string att = MyHelper.GetXmlAttributeValue(aNode, "href"); if (att != string.Empty) { lstTopIndex.Add(new AlphabeticalTopIndex(aNode.Value, "http://biz.yahoo.com" + att)); } } } } } return(new AlphabeticIDIndexResult(lstTopIndex.ToArray())); case AlphabeticalIndexDownloadType.Index: resultsNodes = XPath.GetElements("//results", doc); List <AlphabeticalIndex> lstIndex = new List <AlphabeticalIndex>(); if (resultsNodes.Length > 0) { XParseElement resultNode = resultsNodes[0]; foreach (XParseElement tdNode in resultNode.Elements()) { foreach (XParseElement tableNode in tdNode.Elements()) { if (tableNode.Name.LocalName == "table") { XParseElement[] chdLst = MyHelper.EnumToArray(MyHelper.EnumToArray(tableNode.Elements())[0].Elements()); if (chdLst.Length >= 3) { lstIndex.Add(new AlphabeticalIndex(chdLst[1].Value, s.TopIndex.URL)); if (chdLst.Length > 3) { for (int i = 3; i <= chdLst.Length - 1; i++) { XParseElement tdTbNode = chdLst[i]; XParseElement[] enm = MyHelper.EnumToArray(tdTbNode.Elements()); if (enm.Length > 0 && enm[0].Name.LocalName == "a") { string name = enm[0].Value.Replace("\n", "").Replace(" ", "").Trim(); string url = string.Empty; string att = MyHelper.GetXmlAttributeValue(enm[0], "href"); if (att != string.Empty) { url = "http://biz.yahoo.com" + att.Trim(); } if (url != string.Empty & name != string.Empty) { lstIndex.Add(new AlphabeticalIndex(name, url)); } } } } } } } } } s.TopIndex.SetIndices(lstIndex.ToArray()); return(new AlphabeticIDIndexResult(s.TopIndex.SubIndices)); default: return(null); } }
protected override TrefisCompanyCoveredInfoAggregate ConvertResult(string contentStr, string ticker = "") { List <TrefisCompanyCoveredInfoData> companies = new List <TrefisCompanyCoveredInfoData>(100); var normalizeContent = contentStr.Replace("\r\n", "").Replace("\t", ""); XParseDocument doc = MyHelper.ParseXmlDocument(normalizeContent); int startIndex = normalizeContent.IndexOf("initCompanies(") + "initCompanies(".Length; int endIndex = normalizeContent.IndexOf(");});</script>"); var jsonStr = normalizeContent.Substring(startIndex, endIndex - startIndex); // jsonStr = MyHelper.ExtractPattern(normalizeContent, @".*initCompanies\((?<content>.*)\);\}\);</script>"); // var serializer = new DataContractJsonSerializer(typeof(TrefisCompanyCoveredInfoData));// JavaScriptSerializer(); List <TrefisCompanyCoveredInfoData> dataList = MyHelper.FromJson <List <TrefisCompanyCoveredInfoData> >(jsonStr); //serializer..Deserialize<List<TrefisCompanyCoveredInfoData>>(scriptContent); //XDocument xdoc = XDocument.Parse(normalizeContent); //XElement tempElement = null; //var rows = xdoc.XPathSelectElements("//tbody[@class=\"cmpTblBody\")]/tr"); //foreach (var row in rows) //{ // var data = new TrefisCompanyCoveredInfoData(); // tempElement = row.Document.XPathSelectElement("/td[1]/a"); // data.CompanyName = tempElement.Value; // data.Ticker = this.Setting.GetTickerFromUrl(tempElement.Attribute(XName.Get("href")).Value); // tempElement = row.Document.XPathSelectElement("/td[2]/a"); // data.TrefisTarget = double.Parse(tempElement.Value, NumberStyles.Currency); // tempElement = row.Document.XPathSelectElement("/td[3]"); // data.PriceGap = float.Parse(tempElement.Value); // tempElement = row.Document.XPathSelectElement("/td[4]"); // data.Sector = tempElement.Value; // tempElement = row.Document.XPathSelectElement("/td[5]"); // data.Industry = tempElement.Value; // tempElement = row.Document.XPathSelectElement("/td[6]"); // data.Bearishness = float.Parse(tempElement.Value); // companies.Add(data); //} var culture = MyHelper.DefaultCulture; XParseElement[] results = XPath.GetElements("//tbody[@class=\"cmpTblBody\")]/tr", doc); XParseElement tempNode = null; foreach (XParseElement row in results) { tempNode = XPath.GetElement("/td[1]/a", row); var data = dataList.Where(company => company.CompanyName == HttpUtility.HtmlDecode(tempNode.Value)).FirstOrDefault(); tempNode = XPath.GetElement("/td[4]", row); data.Sector = tempNode.Value; tempNode = XPath.GetElement("/td[5]", row); data.Industry = tempNode.Value; } return(new TrefisCompanyCoveredInfoAggregate(dataList.ToArray())); }
private GeoPlanet.PlacesData ToPlace(XParseElement node) { if (node != null && node.Name.LocalName.ToLower() == "place") { GeoPlanet.PlacesData p = new GeoPlanet.PlacesData(); foreach (XParseElement prpNode in node.Elements()) { switch (prpNode.Name.LocalName.ToLower()) { case "woeid": long l; if (long.TryParse(prpNode.Value, out l)) { p.WOEID = l; } break; case "placetypename": string code = MyHelper.GetXmlAttributeValue(prpNode, "code"); if (code != string.Empty) { p.Type = (PlaceType)Convert.ToInt32(code); } break; case "name": p.Name = prpNode.Value; break; case "country": GeoPlanet.AdminArea ctr = new GeoPlanet.AdminArea(); ctr.Code = MyHelper.GetXmlAttributeValue(prpNode, "code"); ctr.Name = prpNode.Value; break; case "admin1": if (prpNode.Value != string.Empty) { GeoPlanet.FederalAdminArea admin1 = new GeoPlanet.FederalAdminArea(); admin1.Code = MyHelper.GetXmlAttributeValue(prpNode, "code"); admin1.Name = prpNode.Value; string type = MyHelper.GetXmlAttributeValue(prpNode, "type").ToLower(); if (type != string.Empty) { for (GeoPlanet.FederalAdminAreaType i = 0; i <= MaasOne.Geo.GeoPlanet.FederalAdminAreaType.State; i++) { if (i.ToString().ToLower() == type) { admin1.AdminType = i; break; // TODO: might not be correct. Was : Exit For } } } p.FederalAdmin = admin1; } break; case "admin2": if (prpNode.Value != string.Empty) { GeoPlanet.RegionalAdminArea admin2 = new GeoPlanet.RegionalAdminArea(); admin2.Code = MyHelper.GetXmlAttributeValue(prpNode, "code"); admin2.Name = prpNode.Value; string type = MyHelper.GetXmlAttributeValue(prpNode, "type").ToLower(); if (type != string.Empty) { for (GeoPlanet.RegionalAdminAreaType i = 0; i <= MaasOne.Geo.GeoPlanet.RegionalAdminAreaType.Province; i++) { if (i.ToString().ToLower() == type) { admin2.AdminType = i; break; // TODO: might not be correct. Was : Exit For } } } p.RegionalAdmin = admin2; } break; case "admin3": if (prpNode.Value != string.Empty) { p.LocalAdmin = new GeoPlanet.LocalAdminArea(); p.LocalAdmin.Code = MyHelper.GetXmlAttributeValue(prpNode, "code"); p.LocalAdmin.Name = prpNode.Value; string type = MyHelper.GetXmlAttributeValue(prpNode, "type").ToLower(); if (type != string.Empty) { for (GeoPlanet.LocalAdminAreaType i = 0; i <= MaasOne.Geo.GeoPlanet.LocalAdminAreaType.Ward; i++) { if (i.ToString().ToLower() == type) { p.LocalAdmin.AdminType = i; break; // TODO: might not be correct. Was : Exit For } } } } break; case "locality1": if (prpNode.Value != string.Empty) { p.Locality1 = new GeoPlanet.Locality(); p.Locality1.Type = MyHelper.GetXmlAttributeValue(prpNode, "type").ToLower(); p.Locality1.Name = prpNode.Value; } break; case "locality2": if (prpNode.Value != string.Empty) { p.Locality2 = new GeoPlanet.Locality(); p.Locality2.Type = MyHelper.GetXmlAttributeValue(prpNode, "type").ToLower(); p.Locality2.Name = prpNode.Value; } break; case "postal": if (prpNode.Value != string.Empty) { p.PostalCode = prpNode.Value; } break; case "centroid": p.Center = GetCoordinates(prpNode); break; case "boundingbox": CoordinatesRectangle b = new CoordinatesRectangle(); foreach (XParseElement directionNode in prpNode.Elements()) { switch (directionNode.Name.LocalName.ToLower()) { case "southwest": b.SouthWest = GetCoordinates(directionNode); break; case "northeast": b.NorthEast = GetCoordinates(directionNode); break; } } p.BoundingBox = b; break; case "arearank": int i1 = 0; int.TryParse(prpNode.Value, out i1); p.AreaInSquareKilometers = GetAreaRank(i1); break; case "poprank": int.TryParse(prpNode.Value, out i1); p.PopulationCount = GetPopRank(i1); break; } } return(p); } else { return(null); } }
protected override IDSearchResult ConvertResult(Base.ConnectionInfo connInfo, System.IO.Stream stream, Base.SettingsBase settings) { IDSearchResult result = null; List <IDSearchData> lst = new List <IDSearchData>(); if (stream != null) { if (settings is IDInstantSearchDownloadSettings) { #region Instant string resultStr = MyHelper.StreamToString(stream, ((IDInstantSearchDownloadSettings)settings).TextEncoding); MatchCollection results = Regex.Matches(resultStr, "{\"symbol\":.*?}"); foreach (Match res in results) { string[] prp = res.Value.Replace("{", "").Replace("}", "").Split(','); if (prp.Length > 0) { string name = string.Empty; string id = string.Empty; string category = string.Empty; string exchange = string.Empty; string type = string.Empty; foreach (string p in prp) { string[] kvp = p.Replace("\"", "").Split(':'); if (kvp.Length == 2) { switch (kvp[0]) { case "symbol": id = kvp[1].Trim(); break; case "name": name = kvp[1].Trim(); break; case "exch": exchange = kvp[1].Trim(); break; case "type": switch (kvp[1].Trim()) { case "S": type = "Stock"; break; case "I": type = "Index"; break; case "F": type = "Future"; break; case "E": type = "ETF"; break; case "M": type = "Fund"; break; } break; } } } lst.Add(new IDSearchData(name, id, type, exchange, string.Empty, null)); } } Dictionary <SecurityType, int> dict = new Dictionary <SecurityType, int>(); dict.Add(SecurityType.Any, lst.Count); return(new IDSearchResult(lst.ToArray(), 0, lst.Count, lst.Count, dict)); #endregion } else if (settings is IDQuerySearchDownloadSettings) { #region Query IDQuerySearchDownloadSettings sett = (IDQuerySearchDownloadSettings)settings; int pageingFrom = sett.ResultsIndex, pagingTo = sett.ResultsIndex + 20, overall = 0; Dictionary <SecurityType, int> resultsCount = new Dictionary <SecurityType, int>(); System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US"); XParseDocument doc = MyHelper.ParseXmlDocument(stream); XParseElement resultNode = XPath.GetElement("//div[@id=\"yfi_sym_lookup\"]", doc); if (resultNode != null) { XParseElement navigationNode = XPath.GetElement("ul[1]", resultNode); if (navigationNode != null) { string s; int t; s = XPath.GetElement("li[1]/a/em", navigationNode).Value; if (int.TryParse(s.Substring(s.LastIndexOf("(") + 1).Replace(")", "").Trim(), out t)) { resultsCount.Add(SecurityType.Any, t); } s = XPath.GetElement("li[2]/a/em", navigationNode).Value; if (int.TryParse(s.Substring(s.LastIndexOf("(") + 1).Replace(")", "").Trim(), out t)) { resultsCount.Add(SecurityType.Stock, t); } s = XPath.GetElement("li[3]/a/em", navigationNode).Value; if (int.TryParse(s.Substring(s.LastIndexOf("(") + 1).Replace(")", "").Trim(), out t)) { resultsCount.Add(SecurityType.Fund, t); } s = XPath.GetElement("li[4]/a/em", navigationNode).Value; if (int.TryParse(s.Substring(s.LastIndexOf("(") + 1).Replace(")", "").Trim(), out t)) { resultsCount.Add(SecurityType.ETF, t); } s = XPath.GetElement("li[5]/a/em", navigationNode).Value; if (int.TryParse(s.Substring(s.LastIndexOf("(") + 1).Replace(")", "").Trim(), out t)) { resultsCount.Add(SecurityType.Index, t); } s = XPath.GetElement("li[6]/a/em", navigationNode).Value; if (int.TryParse(s.Substring(s.LastIndexOf("(") + 1).Replace(")", "").Trim(), out t)) { resultsCount.Add(SecurityType.Future, t); } if (MyHelper.EnumToArray(navigationNode.Elements()).Length == 7) { resultsCount.Add(SecurityType.Warrant, 0); s = XPath.GetElement("li[7]/a/em", navigationNode).Value; if (int.TryParse(s.Substring(s.LastIndexOf("(") + 1).Replace(")", "").Trim(), out t)) { resultsCount.Add(SecurityType.Currency, t); } } else if (MyHelper.EnumToArray(navigationNode.Elements()).Length == 8) { s = XPath.GetElement("li[7]/a/em", navigationNode).Value; if (int.TryParse(s.Substring(s.LastIndexOf("(") + 1).Replace(")", "").Trim(), out t)) { resultsCount.Add(SecurityType.Warrant, t); } s = XPath.GetElement("li[8]/a/em", navigationNode).Value; if (int.TryParse(s.Substring(s.LastIndexOf("(") + 1).Replace(")", "").Trim(), out t)) { resultsCount.Add(SecurityType.Currency, t); } } } XParseElement contentNode = XPath.GetElement("div[1]", resultNode); if (contentNode != null) { XParseElement tableNode = XPath.GetElement("/div[1]/table", contentNode); XParseElement tableHeadNode = XPath.GetElement("/thead/tr", tableNode); XParseElement tableBodyNode = XPath.GetElement("/tbody", tableNode); List <string> tableColumnNames = new List <string>(); tableColumnNames.Add("symbol"); tableColumnNames.Add("name"); bool hasISIN = XPath.GetElement("/th[3]", tableHeadNode).Value.ToLower().Contains("isin"); if (hasISIN) { tableColumnNames.Add("isin"); } else { tableColumnNames.Add("lasttrade"); } int l = MyHelper.EnumToArray(tableHeadNode.Elements()).Length; for (int i = 3; i < l; i++) { if (hasISIN) { switch (i) { case 3: tableColumnNames.Add("lasttrade"); break; case 4: tableColumnNames.Add("type"); break; case 5: tableColumnNames.Add("exchange"); break; } } else { string name = MyHelper.GetEnumItemAt(tableHeadNode.Elements(), i).Value.ToLower(); if (name.Contains("type")) { tableColumnNames.Add("type"); } else if (name.Contains("industry")) { tableColumnNames.Add("industry"); } else if (name.Contains("exchange")) { tableColumnNames.Add("exchange"); } } } foreach (XParseElement rowNode in tableBodyNode.Elements()) { IEnumerable <XParseElement> enm = rowNode.Elements(); if (MyHelper.EnumToArray(enm).Length >= tableColumnNames.Count) { string name = string.Empty, id = string.Empty, type = string.Empty, industry = string.Empty, exchange = string.Empty; ISIN isin = null; for (int i = 0; i < tableColumnNames.Count; i++) { switch (tableColumnNames[i]) { case "symbol": id = MyHelper.GetEnumItemAt(enm, i).Value.Trim(); break; case "name": name = MyHelper.GetEnumItemAt(enm, i).Value.Trim(); break; case "isin": if (MyHelper.GetEnumItemAt(enm, i).Value.Trim() != string.Empty) { try { isin = new ISIN(MyHelper.GetEnumItemAt(enm, i).Value.Trim()); } catch { } } break; case "lasttrade": break; case "type": type = MyHelper.GetEnumItemAt(enm, i).Value.Trim(); break; case "industry": industry = MyHelper.GetEnumItemAt(enm, i).Value.Trim(); break; case "exchange": exchange = MyHelper.GetEnumItemAt(enm, i).Value.Trim(); break; } } lst.Add(new IDSearchData(name, id, type, exchange, industry, isin)); } } overall = lst.Count; XParseElement paginationNode = XPath.GetElement("//div[@id=\"pagination\"]", doc); if (paginationNode != null) { PaginationScanner scn = new PaginationScanner(); scn.SetPagination(paginationNode.Value, out pageingFrom, out pagingTo, out overall); } } } result = new IDSearchResult(lst.ToArray(), pageingFrom, pagingTo, overall, resultsCount); #endregion } else if (settings is IDAlphabeticSearchDownloadSettings) { #region Alphabet XParseDocument doc = MyHelper.ParseXmlDocument(stream); XParseElement[] resultsNodes = XPath.GetElements("//results", doc); if (resultsNodes.Length > 0) { XParseElement resultNode = resultsNodes[0]; foreach (XParseElement trNode in resultNode.Elements()) { XParseElement[] enm = MyHelper.EnumToArray(trNode.Elements()); if (trNode.Name.LocalName == "tr" && enm.Length >= 2) { string name = string.Empty; foreach (XParseElement subNode in enm[0].Elements()) { name += subNode.Value.Trim() + " "; } name = name.TrimEnd(); string id = enm[1].Value.Trim(); lst.Add(new IDSearchData(name, id, "stock", "", null, null)); } } } result = new IDSearchResult(lst.ToArray(), -1, -1, -1, new Dictionary <SecurityType, int>()); #endregion } } if (result == null) { result = new IDSearchResult(lst.ToArray(), -1, -1, -1, new Dictionary <SecurityType, int>()); } return(result); }
protected override CompanyProfileResult ConvertResult(Base.ConnectionInfo connInfo, System.IO.Stream stream, Base.SettingsBase settings) { CompanyProfileData res = null; System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US"); if (stream != null) { XParseDocument doc = MyHelper.ParseXmlDocument(stream); XParseElement resultNode = XPath.GetElement("//table[@id=\"yfncsumtab\"]/tr[2]", doc); if (resultNode != null) { res = new CompanyProfileData(); res.SetID(FinanceHelper.CleanIndexID(((CompanyProfileDownloadSettings)settings).ID.ToUpper())); XParseElement nameNode = XPath.GetElement("td[1]/b[1]", resultNode); if (nameNode != null) { res.CompanyName = nameNode.Value; } XParseElement addressNode = XPath.GetElement("td[1]", resultNode); if (addressNode != null) { System.Text.StringBuilder formattedAddress = new System.Text.StringBuilder(); try { string addNodeStr = addressNode.ToString(); if (addNodeStr != string.Empty) { addNodeStr = addNodeStr.Substring(addNodeStr.IndexOf("/>") + 2); string[] rawAddress = addNodeStr.Substring(0, addNodeStr.IndexOf("Website")).Split(new string[] { "<b>", "<br />", "</b>", "\r", "\n", " - ", "</a>" }, StringSplitOptions.RemoveEmptyEntries); if (rawAddress.Length >= 7) { foreach (string line in rawAddress) { string l = line.Trim(); if (l != string.Empty && !l.StartsWith("<a") && l != "Map") { formattedAddress.AppendLine(l); } } } } } catch (Exception ex) { } res.Address = formattedAddress.ToString().TrimEnd(); } XParseElement indicesNode = XPath.GetElement("td[1]/table[2]/tr/td/table/tr/td[2]", resultNode); if (indicesNode != null) { List <KeyValuePair <string, string> > lstIndices = new List <KeyValuePair <string, string> >(); foreach (XParseElement indexLink in indicesNode.Elements()) { if (indexLink.Name.LocalName == "a") { string indexID = Uri.UnescapeDataString(MyHelper.GetXmlAttributeValue(indexLink, "href").ToUpper().Replace("HTTP://FINANCE.YAHOO.COM/Q?S=", "").Replace("&D=T", "")); string name = string.Empty; foreach (string p in indexLink.Value.Split(new string[] { "\r\n" }, StringSplitOptions.None)) { name += p.Trim() + " "; } lstIndices.Add(new KeyValuePair <string, string>(indexID, name.TrimEnd())); } } res.Details.IndexMembership = lstIndices.ToArray(); } XParseElement sectorsNode = XPath.GetElement("td[1]/table[2]/tr/td/table/tr[2]/td[2]", resultNode); if (sectorsNode != null) { foreach (XParseElement sectorLink in sectorsNode.Elements()) { if (sectorLink.Name.LocalName == "a") { foreach (Sector sect in Enum.GetValues(typeof(Sector))) { string name = string.Empty; foreach (string p in sectorLink.Value.Split(new string[] { "\r\n" }, StringSplitOptions.None)) { name += p.Trim() + " "; } name = name.TrimEnd(); if (sect.ToString().Replace("_", " ") == name) { res.Details.Sector = sect; break; } } } } } XParseElement industryNode = XPath.GetElement("td[1]/table[2]/tr/td/table/tr[3]/td[2]", resultNode); if (industryNode != null) { foreach (XParseElement industryLink in industryNode.Elements()) { if (industryLink.Name.LocalName == "a") { int indIndex = 0; if (int.TryParse(MyHelper.GetXmlAttributeValue(industryLink, "href").Replace("http://biz.yahoo.com/ic/", "").Replace(".html", ""), out indIndex)) { res.Details.Industry = (Industry)indIndex; } } } } XParseElement employeesNode = XPath.GetElement("td[1]/table[2]/tr/td/table/tr[4]/td[2]", resultNode); if (employeesNode != null) { int fte; if (int.TryParse(employeesNode.Value.Trim(), System.Globalization.NumberStyles.Any, convCulture, out fte)) { res.Details.FullTimeEmployees = fte; } } XParseElement summaryNode = XPath.GetElement("td[1]/p[1]", resultNode); if (summaryNode != null) { System.Text.StringBuilder summaryText = new System.Text.StringBuilder(); foreach (string line in summaryNode.Value.Split(new string[] { "\r\n" }, StringSplitOptions.None)) { summaryText.Append(line.Trim() + " "); } res.BusinessSummary = summaryText.ToString().TrimEnd(); } XParseElement websitesNodes = XPath.GetElement("td[1]/table[5]/tr/td", resultNode); if (websitesNodes != null) { List <Uri> lstWebsites = new List <Uri>(); foreach (XParseElement linkNode in websitesNodes.Elements()) { if (linkNode.Name.LocalName == "a") { lstWebsites.Add(new Uri(MyHelper.GetXmlAttributeValue(linkNode, "href"))); } } res.CompanyWebsites = lstWebsites.ToArray(); } XParseElement governanceNode = null; XParseElement governanceHeader = XPath.GetElement("td[3]/table[1]/tr/th/span", resultNode); if (governanceHeader != null && governanceHeader.Value.Contains("Governance")) { governanceNode = XPath.GetElement("td[3]/table[2]/tr/td", resultNode); } if (governanceNode != null) { System.Text.StringBuilder governanceText = new System.Text.StringBuilder(); foreach (string line in governanceNode.Value.Split(new string[] { "\r\n" }, StringSplitOptions.None)) { governanceText.Append(line.Trim() + " "); } res.CorporateGovernance = governanceText.ToString().TrimEnd(); } XParseElement executivesNode = null; XParseElement executivesHeader = XPath.GetElement("td[3]/table[3]/tr/th/span", resultNode); if (executivesHeader != null && executivesHeader.Value.Contains("Executives")) { executivesNode = XPath.GetElement("td[3]/table[4]/tr/td/table", resultNode); } else { executivesNode = XPath.GetElement("td[3]/table[2]/tr/td/table", resultNode); } if (executivesNode != null) { List <ExecutivePersonInfo> lst = new List <ExecutivePersonInfo>(); bool isFirst = true; foreach (XParseElement row in executivesNode.Elements()) { if (!isFirst) { if (row.Name.LocalName == "tr") { XParseElement[] enm = MyHelper.EnumToArray(row.Elements()); if (enm.Length >= 3) { ExecutivePersonInfo exec = new ExecutivePersonInfo(); string name = string.Empty; foreach (string l in MyHelper.EnumToArray(enm[0].Elements())[0].Value.Split(new string[] { "\r\n" }, StringSplitOptions.None)) { name += l.Trim() + " "; } exec.Name = name.TrimEnd(); string position = string.Empty; var enm2 = MyHelper.EnumToArray(enm[0].Elements()); foreach (string l in enm2[enm2.Length - 1].Value.Split(new string[] { "\r\n" }, StringSplitOptions.None)) { position += l.Trim() + " "; } exec.Position = position.Trim(); string payStr = enm[1].Value.Replace("\r\n", "").Trim(); if (!payStr.Contains("N/A")) { exec.Pay = FinanceHelper.GetMillionValue(payStr) * 1000000; } string exercisedStr = enm[2].Value.Replace("\r\n", "").Trim(); if (!exercisedStr.Contains("N/A")) { double d = FinanceHelper.GetMillionValue(exercisedStr); exec.Exercised = (int)(d * 1000000); } lst.Add(exec); } } } else { isFirst = false; } } res.KeyExecutives = lst.ToArray(); } if (res.BusinessSummary.StartsWith("There is no ")) { res = null; } } } return(new CompanyProfileResult(res)); }
protected override PlaceFinderResult ConvertResult(Base.ConnectionInfo connInfo, System.IO.Stream stream, Base.SettingsBase settings) { List <PlaceFinderData> results = new List <PlaceFinderData>(); System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US"); PlaceFinderError errorCode = PlaceFinderError.NoError; AddressQualitiy bestQuality = AddressQualitiy.NotAnAddress; XParseDocument doc = MyHelper.ParseXmlDocument(stream); XParseElement[] resultSet = XPath.GetElements("//ResultSet", doc); if (resultSet.Length == 1) { XParseElement resultSetNode = resultSet[0]; foreach (XParseElement resultSetElementNode in resultSetNode.Elements()) { switch (resultSetElementNode.Name.LocalName) { case "Error": errorCode = (PlaceFinderError)Convert.ToInt32(resultSetElementNode.Value.Replace("NN", "")); break; case "ErrorMessage": if (errorCode > PlaceFinderError.NoError) { connInfo = this.GetConnectionInfo(new System.Net.WebException("An internal Yahoo! error occured. Look at InnerException for more details.", new PlaceFinderException(errorCode, resultSetElementNode.Value)), connInfo); break; } break; case "Locale": string[] codes = resultSetElementNode.Value.Split(new string[] { "_", "-" }, StringSplitOptions.None); Language language = Language.en; Country country = Country.US; foreach (Language lang in Enum.GetValues(typeof(Language))) { if (lang.ToString() == codes[0]) { language = lang; break; // TODO: might not be correct. Was : Exit For } } foreach (Country cnt in Enum.GetValues(typeof(Country))) { if (cnt.ToString() == codes[1]) { country = cnt; break; // TODO: might not be correct. Was : Exit For } } break; case "Quality": bestQuality = (AddressQualitiy)Convert.ToInt32(resultSetElementNode.Value); break; case "Result": PlaceFinderData res = new PlaceFinderData(); double lat = 0; double lon = 0; double latOff = 0; double lonOff = 0; foreach (XParseElement resultItemNode in resultSetElementNode.Elements()) { switch (resultItemNode.Name.LocalName) { case "quality": res.Quality = (AddressQualitiy)Convert.ToInt32(resultItemNode.Value); break; case "latitude": double.TryParse(resultItemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out lat); break; case "longitude": double.TryParse(resultItemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out lon); break; case "offsetlat": double.TryParse(resultItemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out latOff); break; case "offsetlon": double.TryParse(resultItemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out lonOff); break; case "radius": int t; if (int.TryParse(resultItemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t)) { res.Radius = t; } break; case "boundingbox": double n = 0; double s = 0; double e = 0; double w = 0; foreach (XParseElement bbItemNode in resultItemNode.Elements()) { switch (bbItemNode.Name.LocalName) { case "north": double.TryParse(resultItemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out n); break; case "south": double.TryParse(resultItemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out s); break; case "east": double.TryParse(resultItemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out e); break; case "west": double.TryParse(resultItemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out w); break; } } Coordinates ne = new Coordinates(e, n); Coordinates sw = new Coordinates(w, s); res.BoundingBox = new CoordinatesRectangle(sw, ne); break; case "name": res.PoiAoiName = resultItemNode.Value; break; case "line1": if (res.DefaultAddress == null) { res.DefaultAddress = new Address(); } res.DefaultAddress.StreetAddressOrIntersection = resultItemNode.Value; break; case "line2": if (res.DefaultAddress == null) { res.DefaultAddress = new Address(); } res.DefaultAddress.CityOrStateOrZipCode = resultItemNode.Value; break; case ("line3"): if (res.DefaultAddress == null) { res.DefaultAddress = new Address(); } res.DefaultAddress.PostalCode = resultItemNode.Value; break; case "line4": if (res.DefaultAddress == null) { res.DefaultAddress = new Address(); } res.DefaultAddress.Country = resultItemNode.Value; break; case "cross": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.CrossStreets = resultItemNode.Value; break; case "house": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.House = resultItemNode.Value; break; case "street": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } if (resultItemNode.HasElements) { res.ExtendedAddress.Street = this.GetStreetContainer(resultItemNode); } else { res.ExtendedAddress.Street = new SimpleStreetDescription { FullName = resultItemNode.Value }; } break; case "xstreet": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } if (resultItemNode.HasElements) { res.ExtendedAddress.CrossStreet = this.GetStreetContainer(resultItemNode); } else { res.ExtendedAddress.CrossStreet = new SimpleStreetDescription { FullName = resultItemNode.Value }; } break; case "unittype": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.UnitType = resultItemNode.Value; break; case "unit": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.Unit = resultItemNode.Value; break; case "postal": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.PostalCode = resultItemNode.Value; break; case "neighborhood": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.Neighborhoods = resultItemNode.Value.Split('/'); break; case "city": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.City = resultItemNode.Value; break; case "county": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.County = resultItemNode.Value; break; case "state": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.State = resultItemNode.Value; break; case "country": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.Country = resultItemNode.Value; break; case "level4": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.Neighborhoods = resultItemNode.Value.Split('/'); break; case "level3": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.City = resultItemNode.Value; break; case "level2": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.County = resultItemNode.Value; break; case "level1": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.State = resultItemNode.Value; break; case "level0": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.Country = resultItemNode.Value; break; case "countycode": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.CountyCode = resultItemNode.Value; break; case "statecode": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.StateCode = resultItemNode.Value; break; case "countrycode": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.CountryCode = resultItemNode.Value; break; case "level2code": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.CountyCode = resultItemNode.Value; break; case "level1code": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.StateCode = resultItemNode.Value; break; case "level0code": if (res.ExtendedAddress == null) { res.ExtendedAddress = new ExtendedAddress(); } res.ExtendedAddress.CountryCode = resultItemNode.Value; break; case "timezone": res.TimeZone = resultItemNode.Value; break; case "areacode": res.TelephoneAreaCode = resultItemNode.Value; break; case "uzip": res.UniqueZipCode = resultItemNode.Value; break; case "hash": res.Hash = resultItemNode.Value; break; case "woeid": long l; if (long.TryParse(resultItemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out l)) { res.WOEID = l; } break; case "woetype": int tInt = 0; if (int.TryParse(resultItemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out tInt)) { res.WOEType = (PlaceType)tInt; } break; } } res.Position = new Coordinates(lon, lat); res.PositionOffSet = new CoordinatesOffSet { Latitude = latOff, LongitudeOffSet = lonOff }; results.Add(res); break; } } } return(new PlaceFinderResult(results.ToArray(), bestQuality, (PlaceFinderDownloadSettings)settings)); }
protected override CompanyStatisticsAggregate ConvertResult(string contentStr, string ticker = "") { CompanyStatisticsData result = null; XParseDocument doc = MyHelper.ParseXmlDocument(contentStr); XParseElement resultNode = XPath.GetElement("//table[@id=\"yfncsumtab\"]/tr[2]", doc); if (resultNode != null) { XParseElement tempNode = null; XParseElement vmNode = XPath.GetElement("/td[1]/table[2]/tr/td/table", resultNode); double[] vmValues = new double[9]; if (vmNode != null) { tempNode = XPath.GetElement("/tr[1]/td[2]/span", vmNode); if (tempNode != null) { vmValues[0] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[2]/td[2]", vmNode); if (tempNode != null) { vmValues[1] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[3]/td[2]", vmNode); if (tempNode != null) { vmValues[2] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[4]/td[2]", vmNode); if (tempNode != null) { vmValues[3] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[5]/td[2]", vmNode); if (tempNode != null) { vmValues[4] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[6]/td[2]", vmNode); if (tempNode != null) { vmValues[5] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[7]/td[2]", vmNode); if (tempNode != null) { vmValues[6] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[8]/td[2]", vmNode); if (tempNode != null) { vmValues[7] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[9]/td[2]", vmNode); if (tempNode != null) { vmValues[8] = FinanceHelper.ParseToDouble(tempNode.Value); } } CompanyValuationMeasures vm = new CompanyValuationMeasures(vmValues); XParseElement fyNode = XPath.GetElement("/td[1]/table[4]/tr/td/table", resultNode); XParseElement profitNode = XPath.GetElement("/td[1]/table[5]/tr/td/table", resultNode); XParseElement meNode = XPath.GetElement("/td[1]/table[6]/tr/td/table", resultNode); XParseElement isNode = XPath.GetElement("/td[1]/table[7]/tr/td/table", resultNode); XParseElement bsNode = XPath.GetElement("/td[1]/table[8]/tr/td/table", resultNode); XParseElement cfsNode = XPath.GetElement("/td[1]/table[9]/tr/td/table", resultNode); DateTime fiscalYEnds = new DateTime(); DateTime mostRecQutr = new DateTime(); double[] fhValues = new double[20]; if (fyNode != null) { tempNode = XPath.GetElement("/tr[2]/td[2]", fyNode); if (tempNode != null) { fiscalYEnds = FinanceHelper.ParseToDateTime(tempNode.Value); } tempNode = XPath.GetElement("/tr[3]/td[2]", fyNode); if (tempNode != null) { mostRecQutr = FinanceHelper.ParseToDateTime(tempNode.Value); } } if (profitNode != null) { tempNode = XPath.GetElement("/tr[2]/td[2]", profitNode); if (tempNode != null) { fhValues[0] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[3]/td[2]", profitNode); if (tempNode != null) { fhValues[1] = FinanceHelper.ParseToDouble(tempNode.Value); } } if (meNode != null) { tempNode = XPath.GetElement("/tr[2]/td[2]", meNode); if (tempNode != null) { fhValues[2] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[3]/td[2]", meNode); if (tempNode != null) { fhValues[3] = FinanceHelper.ParseToDouble(tempNode.Value); } } if (isNode != null) { tempNode = XPath.GetElement("/tr[2]/td[2]", isNode); if (tempNode != null) { fhValues[4] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[3]/td[2]", isNode); if (tempNode != null) { fhValues[5] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[4]/td[2]", isNode); if (tempNode != null) { fhValues[6] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[5]/td[2]", isNode); if (tempNode != null) { fhValues[7] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[6]/td[2]", isNode); if (tempNode != null) { fhValues[8] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[7]/td[2]", isNode); if (tempNode != null) { fhValues[9] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[8]/td[2]", isNode); if (tempNode != null) { fhValues[10] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[9]/td[2]", isNode); if (tempNode != null) { fhValues[11] = FinanceHelper.ParseToDouble(tempNode.Value); } } if (bsNode != null) { tempNode = XPath.GetElement("/tr[2]/td[2]", bsNode); if (tempNode != null) { fhValues[12] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[3]/td[2]", bsNode); if (tempNode != null) { fhValues[13] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[4]/td[2]", bsNode); if (tempNode != null) { fhValues[14] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[5]/td[2]", bsNode); if (tempNode != null) { fhValues[15] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[6]/td[2]", bsNode); if (tempNode != null) { fhValues[16] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[7]/td[2]", bsNode); if (tempNode != null) { fhValues[17] = FinanceHelper.ParseToDouble(tempNode.Value); } } if (cfsNode != null) { tempNode = XPath.GetElement("/tr[2]/td[2]", cfsNode); if (tempNode != null) { fhValues[18] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[3]/td[2]", cfsNode); if (tempNode != null) { fhValues[19] = FinanceHelper.GetMillionValue(tempNode.Value); } } CompanyFinancialHighlights fh = new CompanyFinancialHighlights(fiscalYEnds, mostRecQutr, fhValues); XParseElement sphNode = XPath.GetElement("/td[3]/table[2]/tr/td/table", resultNode); XParseElement stNode = XPath.GetElement("/td[3]/table[3]/tr/td/table", resultNode); XParseElement dsNode = XPath.GetElement("/td[3]/table[4]/tr/td/table", resultNode); double[] ctiValues = new double[23]; DateTime exDivDate = new DateTime(); DateTime divDate = new DateTime(); DateTime splitDate = new DateTime(); SharesSplitFactor sf = null; if (sphNode != null) { tempNode = XPath.GetElement("/tr[2]/td[2]", sphNode); if (tempNode != null) { ctiValues[0] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[3]/td[2]", sphNode); if (tempNode != null) { ctiValues[1] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[4]/td[2]", sphNode); if (tempNode != null) { ctiValues[2] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[5]/td[2]", sphNode); if (tempNode != null) { ctiValues[3] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[6]/td[2]", sphNode); if (tempNode != null) { ctiValues[4] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[7]/td[2]", sphNode); if (tempNode != null) { ctiValues[5] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[8]/td[2]", sphNode); if (tempNode != null) { ctiValues[6] = FinanceHelper.ParseToDouble(tempNode.Value); } } if (stNode != null) { tempNode = XPath.GetElement("/tr[2]/td[2]", stNode); if (tempNode != null) { ctiValues[7] = FinanceHelper.ParseToDouble(tempNode.Value) / 1000; } tempNode = XPath.GetElement("/tr[3]/td[2]", stNode); if (tempNode != null) { ctiValues[8] = FinanceHelper.ParseToDouble(tempNode.Value) / 1000; } tempNode = XPath.GetElement("/tr[4]/td[2]", stNode); if (tempNode != null) { ctiValues[9] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[5]/td[2]", stNode); if (tempNode != null) { ctiValues[10] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[6]/td[2]", stNode); if (tempNode != null) { ctiValues[11] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[7]/td[2]", stNode); if (tempNode != null) { ctiValues[12] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[8]/td[2]", stNode); if (tempNode != null) { ctiValues[13] = FinanceHelper.GetMillionValue(tempNode.Value); } tempNode = XPath.GetElement("/tr[9]/td[2]", stNode); if (tempNode != null) { ctiValues[14] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[10]/td[2]", stNode); if (tempNode != null) { ctiValues[15] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[11]/td[2]", stNode); if (tempNode != null) { ctiValues[16] = FinanceHelper.GetMillionValue(tempNode.Value); } } if (dsNode != null) { tempNode = XPath.GetElement("/tr[2]/td[2]", dsNode); if (tempNode != null) { ctiValues[17] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[3]/td[2]", dsNode); if (tempNode != null) { ctiValues[18] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[4]/td[2]", dsNode); if (tempNode != null) { ctiValues[19] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[5]/td[2]", dsNode); if (tempNode != null) { ctiValues[20] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[6]/td[2]", dsNode); if (tempNode != null) { ctiValues[21] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[7]/td[2]", dsNode); if (tempNode != null) { ctiValues[22] = FinanceHelper.ParseToDouble(tempNode.Value); } tempNode = XPath.GetElement("/tr[8]/td[2]", dsNode); if (tempNode != null) { divDate = FinanceHelper.ParseToDateTime(tempNode.Value); } tempNode = XPath.GetElement("/tr[9]/td[2]", dsNode); if (tempNode != null) { exDivDate = FinanceHelper.ParseToDateTime(tempNode.Value); } tempNode = XPath.GetElement("/tr[10]/td[2]", dsNode); if (tempNode != null) { string[] txt = tempNode.Value.Split(':'); int from, to; if (int.TryParse(txt[0], out to) && int.TryParse(txt[1], out from)) { sf = new SharesSplitFactor(to, from); } } tempNode = XPath.GetElement("/tr[11]/td[2]", dsNode); if (tempNode != null) { splitDate = FinanceHelper.ParseToDateTime(tempNode.Value); } } CompanyTradingInfo cti = new CompanyTradingInfo(ctiValues, divDate, exDivDate, splitDate, sf); result = new CompanyStatisticsData(ticker, vm, fh, cti); } return(new CompanyStatisticsAggregate(result)); }
protected override SearchResult ConvertResult(Base.ConnectionInfo connInfo, System.IO.Stream stream, Base.SettingsBase settings) { List <SearchDataContainer> containers = new List <SearchDataContainer>(); List <SearchData> lst = new List <SearchData>(); XParseDocument xmlDoc = MyHelper.ParseXmlDocument(stream); if (xmlDoc != null) { XParseElement bossResponseNode = XPath.GetElement("bossresponse", xmlDoc); if (bossResponseNode != null) { int respCode = Convert.ToInt32(MyHelper.GetXmlAttributeValue(bossResponseNode, "responsecode")); if (respCode == 200) { foreach (XParseElement containerNode in bossResponseNode.Elements()) { List <SearchData> results = new List <SearchData>(); int start = Convert.ToInt32(MyHelper.GetXmlAttributeValue(containerNode, "start")); int count = Convert.ToInt32(MyHelper.GetXmlAttributeValue(containerNode, "count")); long totalResults = Convert.ToInt64(MyHelper.GetXmlAttributeValue(containerNode, "totalresults")); XParseElement resultsNode = MyHelper.EnumToArray(containerNode.Elements())[0]; if (resultsNode.Name.LocalName == "results") { foreach (XParseElement resultNode in resultsNode.Elements()) { if (resultNode.Name.LocalName == "result") { SearchData res = null; switch (containerNode.Name.LocalName) { case "web": case "limitedweb": res = this.ToBossWebSearchResult(resultNode); break; case "images": res = this.ToBossImageSearchResult(resultNode); break; case "news": res = this.ToBossNewsSearchResult(resultNode); break; case "spelling": res = this.ToBossSpellingSearchResult(resultNode); break; } if (res != null) { results.Add(res); } } } } switch (containerNode.Name.LocalName) { case "web": case "limitedweb": List <WebSearchData> webResults = new List <WebSearchData>(); foreach (SearchData res in results) { if (res is WebSearchData) { webResults.Add((WebSearchData)res); } } containers.Add(new WebSearchDataContainer(webResults.ToArray(), start, count, totalResults)); break; case "images": List <ImageSearchData> imgResults = new List <ImageSearchData>(); foreach (SearchData res in results) { if (res is ImageSearchData) { imgResults.Add((ImageSearchData)res); } } containers.Add(new ImageSearchDataContainer(imgResults.ToArray(), start, count, totalResults)); break; case "news": List <NewsSearchResult> newsResults = new List <NewsSearchResult>(); foreach (SearchData res in results) { if (res is NewsSearchResult) { newsResults.Add((NewsSearchResult)res); } } containers.Add(new NewsSearchDataContainer(newsResults.ToArray(), start, count, totalResults)); break; case "spelling": List <SpellingSearchData> splResults = new List <SpellingSearchData>(); foreach (SearchData res in results) { if (res is SpellingSearchData) { splResults.Add((SpellingSearchData)res); } } containers.Add(new SpellingSearchDataContainer(splResults.ToArray(), start, count, totalResults)); break; } } } } } return(new SearchResult(containers.ToArray(), (SearchDownloadSettings)settings)); }
private ImageSearchData ToBossImageSearchResult(XParseElement node) { SearchData result = this.ToSearchResult(node); if (result != null) { Uri refererUrl = null; Uri refererClickUrl = null; Uri tmbUrl = null; ImageFileType fileFormat = default(ImageFileType); long size = 0; int height = 0; int width = 0; int tmbHeight = 0; int tmbWidth = 0; System.Globalization.CultureInfo convCult = new System.Globalization.CultureInfo("en-US"); foreach (XParseElement prpNode in node.Elements()) { switch (prpNode.Name.LocalName) { case "refererurl": refererUrl = new Uri(prpNode.Value); break; case "refererclickurl": refererClickUrl = new Uri(prpNode.Value); break; case "size": double srcSize = 0; if (prpNode.Value.EndsWith("Bytes")) { double.TryParse(prpNode.Value.Replace("Bytes", ""), System.Globalization.NumberStyles.Any, convCult, out srcSize); } else if (prpNode.Value.EndsWith("KB")) { double.TryParse(prpNode.Value.Replace("KB", ""), System.Globalization.NumberStyles.Any, convCult, out srcSize); srcSize *= 1024; } else if (prpNode.Value.EndsWith("MB")) { double.TryParse(prpNode.Value.Replace("MB", ""), System.Globalization.NumberStyles.Any, convCult, out srcSize); srcSize *= Math.Pow(1024, 2); } size = Convert.ToInt64(srcSize); break; case "format": switch (prpNode.Value.ToLower()) { case "bmp": fileFormat = ImageFileType.Bmp; break; case "gif": fileFormat = ImageFileType.Gif; break; case "jpg": fileFormat = ImageFileType.Jpeg; break; case "jpeg": fileFormat = ImageFileType.Jpeg; break; case "png": fileFormat = ImageFileType.Png; break; default: fileFormat = ImageFileType.Any; break; } break; case "height": int.TryParse(prpNode.Value, out height); break; case "width": int.TryParse(prpNode.Value, out width); break; case "thumbnailurl": if (prpNode.Value != string.Empty) { tmbUrl = new Uri(prpNode.Value); } break; case "thumbnailwidth": int.TryParse(prpNode.Value, out tmbWidth); break; case "thumbnailheight": int.TryParse(prpNode.Value, out tmbHeight); break; } } return(new ImageSearchData(result, refererUrl, refererClickUrl, size, fileFormat, height, width, tmbUrl, tmbHeight, tmbWidth)); } else { return(null); } }