예제 #1
0
 /// <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);
     }
 }
예제 #2
0
        /// <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
                            });
                        }
                    }
                }
            }
        }
예제 #3
0
        /// <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());
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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));
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        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()));
        }
예제 #11
0
        protected override BondScreenerInfoResult ConvertResult(Base.ConnectionInfo connInfo, System.IO.Stream stream, Base.SettingsBase settings)
        {
            BondScreenerInfoDownloadSettings set = (BondScreenerInfoDownloadSettings)settings;

            BondScreenerInfoData res = new BondScreenerInfoData();

            System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US");
            //XDocument doc = MyHelper.ParseXmlDocument(stream);
            XParseDocument doc = MyHelper.ParseXmlDocument(stream);

            XParseElement[] resultsNodes = XPath.GetElements("//results", doc);
            if (resultsNodes.Length > 0)
            {
                XParseElement resultNode = resultsNodes[0];
                if (MyHelper.EnumToArray(resultNode.Elements()).Length > 0)
                {
                    XParseElement tdNode     = null;// MyHelper.EnumToArray(resultNode.Elements())[0];
                    int           tableIndex = 0;
                    foreach (XParseElement tableNode in tdNode.Elements())
                    {
                        XParseElement[] tableEnm = MyHelper.EnumToArray(tableNode.Elements());
                        switch (tableIndex)
                        {
                        case 0:
                            XParseElement trNode = tableEnm[1];
                            //res.Title = MyHelper.EnumToArray<XElement>(MyHelper.EnumToArray<XElement>(trNode.Elements())[0].Elements())[0].Value;
                            DateTime d;
                            //if (System.DateTime.TryParseExact(trNode.LastNode.FirstNode.Value.Replace("As of ", ""), "dd-MMM-yyyy", convCulture, System.Globalization.DateTimeStyles.None, out d)) res.AsOf = d;

                            break;

                        case 3:
                            XParseElement innerTableNode = null;    //tableNode.FirstNode.FirstNode.FirstNode;
                            int           innerIndex     = 0;
                            foreach (XParseElement innerTrNode in innerTableNode.Elements())
                            {
                                switch (innerIndex)
                                {
                                case 0:
                                    double t;
                                    //if (double.TryParse(innerTrNode.LastNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t)) res.Price = t;
                                    break;

                                case 1:
                                    //if (double.TryParse(innerTrNode.LastNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t)) res.CouponInPercent = t;
                                    break;

                                case 2:
                                    //if (System.DateTime.TryParseExact(innerTrNode.LastNode.Value, "dd-MMM-yyyy", convCulture, System.Globalization.DateTimeStyles.None, out d)) res.Maturity = d;
                                    break;

                                case 3:
                                    //if (double.TryParse(innerTrNode.LastNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t)) res.YieldToMaturityInPercent = t;
                                    break;

                                case 4:
                                    //if (double.TryParse(innerTrNode.LastNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t)) res.CurrentYieldInPercent = t;
                                    break;

                                case 5:
                                    //res.CouponPaymentFrequency = innerTrNode.LastNode.Value;
                                    break;

                                case 6:
                                    //if (System.DateTime.TryParseExact(innerTrNode.LastNode.Value, "dd-MMM-yyyy", convCulture, System.Globalization.DateTimeStyles.None, out d)) res.FirstCouponDate = d;
                                    break;

                                case 7:
                                    /* switch (innerTrNode.LastNode.Value)
                                     * {
                                     *  case "Treasury":
                                     *      res.Type = BondType.Treasury;
                                     *      break;
                                     *  case "Treasury Zero":
                                     *      res.Type = BondType.TreasuryZeroCoupon;
                                     *      break;
                                     *  case "Corporate":
                                     *      res.Type = BondType.Corporate;
                                     *      break;
                                     *  case "Municipal":
                                     *      res.Type = BondType.Municipal;
                                     *      break;
                                     * }
                                     */
                                    break;

                                case 8:
                                    //res.Callable = Convert.ToBoolean((innerTrNode.LastNode.Value == "Yes" ? true : false));
                                    break;
                                }
                                innerIndex += 1;
                            }


                            break;

                        case 7:
                            innerTableNode = null;     // tableNode.FirstNode.FirstNode.FirstNode;
                            innerIndex     = 0;
                            foreach (XParseElement innerTrNode in innerTableNode.Elements())
                            {
                                switch (innerIndex)
                                {
                                case 0:
                                    int n;
                                    //if (int.TryParse(innerTrNode.LastNode.Value, System.Globalization.NumberStyles.Any, convCulture, out n)) res.AvailableQuantity = n;
                                    break;

                                case 1:
                                    //if (int.TryParse(innerTrNode.LastNode.Value, System.Globalization.NumberStyles.Any, convCulture, out n)) res.MinimumTradeQuantity = n;
                                    break;

                                case 2:
                                    //if (System.DateTime.TryParseExact(innerTrNode.LastNode.Value, "dd-MMM-yyyy", convCulture, System.Globalization.DateTimeStyles.None, out d)) res.DatedDate = d;
                                    break;

                                case 3:
                                    //if (System.DateTime.TryParseExact(innerTrNode.LastNode.Value, "dd-MMM-yyyy", convCulture, System.Globalization.DateTimeStyles.None, out d)) res.SettlementDate = d;
                                    break;
                                }
                                innerIndex += 1;
                            }

                            break;
                        }
                        tableIndex += 1;
                    }
                    res.Issue       = new Link(set.Data.Issue.Title, set.Data.Issue.Url);
                    res.FitchRating = set.Data.FitchRating;
                }
            }
            return(new BondScreenerInfoResult(res));
        }
예제 #12
0
        /// <summary>
        /// Tries to read a QuoteOption from XML
        /// </summary>
        /// <param name="node">The XML node of QuoteOption</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 QuoteOptionsData ToQuoteOption(XParseElement node, System.Globalization.CultureInfo culture = null)
        {
            if (node != null && node.Name.LocalName.ToLower() == "option")
            {
                System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
                if (culture != null)
                {
                    ci = culture;
                }
                string symbol = string.Empty;
                string t      = string.Empty;
                foreach (XParseAttribute att in node.Attributes())
                {
                    switch (att.Name.LocalName)
                    {
                    case FinanceHelper.NameOptionSymbol:
                        symbol = att.Value;
                        break;

                    case "type":
                        t = att.Value;
                        break;
                    }
                }
                QuoteOptionType type = QuoteOptionType.Call;
                if (t.ToLower() == "p")
                {
                    type = QuoteOptionType.Put;
                }
                double strikePrice = 0;
                double lastPrice   = 0;
                double change      = 0;
                double bid         = 0;
                double ask         = 0;
                int    volume      = 0;
                int    openInt     = 0;
                foreach (XParseElement propertyNode in node.Elements())
                {
                    switch (propertyNode.Name.LocalName)
                    {
                    case FinanceHelper.NameOptionStrikePrice:
                        double.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Currency, ci, out strikePrice);
                        break;

                    case FinanceHelper.NameOptionLastPrice:
                        double.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Currency, ci, out lastPrice);
                        break;

                    case FinanceHelper.NameOptionChange:
                        double.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Currency, ci, out change);
                        break;

                    case FinanceHelper.NameOptionChangeDir:
                        if (propertyNode.Value == "Down")
                        {
                            change *= -1;
                        }
                        break;

                    case FinanceHelper.NameOptionBid:
                        double.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Currency, ci, out bid);
                        break;

                    case FinanceHelper.NameOptionAsk:
                        double.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Currency, ci, out ask);
                        break;

                    case FinanceHelper.NameOptionVolume:
                        int.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Integer, ci, out volume);
                        break;

                    case FinanceHelper.NameOptionOpenInterest:
                        int.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Integer, ci, out openInt);
                        break;
                    }
                }
                return(new QuoteOptionsData(symbol, type, strikePrice, lastPrice, change, bid, ask, volume, openInt));
            }
            else
            {
                return(null);
            }
        }
예제 #13
0
        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);
            }
        }
예제 #14
0
파일: XML.cs 프로젝트: Bulletz4mysa/NBTrade
        public static FeedItem ToFeedItem(XParseElement item)
        {
            if (item.Name.LocalName == "item")
            {
                FeedItem rssItem = new FeedItem();
                foreach (XParseElement itemNode in item.Elements())
                {
                    try
                    {
                        switch (itemNode.Name.LocalName.ToLower())
                        {
                        case "title":
                            rssItem.Title = itemNode.Value;
                            break;

                        case "link":
                            rssItem.Link = new Uri(itemNode.Value);
                            break;

                        case "description":
                            rssItem.Description = itemNode.Value;
                            break;

                        case "author":
                            rssItem.Author = itemNode.Value;
                            break;

                        case "category":
                            rssItem.Category      = new Category();
                            rssItem.Category.Name = itemNode.Value;
                            if (MyHelper.EnumToArray(itemNode.Attributes()).Length == 1)
                            {
                                rssItem.Category.Domain = new Uri(itemNode.Attribute(XParseName.Get("domain")).Value);
                            }
                            break;

                        case "comments":
                            rssItem.Comments = new Uri(itemNode.Value);
                            break;

                        case "enclosure":
                            rssItem.Enclosure     = new Enclosure();
                            rssItem.Enclosure.Url = new Uri(itemNode.Attribute(XParseName.Get("url")).Value);
                            long l;
                            if (long.TryParse(itemNode.Attribute(XParseName.Get("length")).Value, out l))
                            {
                                rssItem.Enclosure.Length = l;
                            }
                            rssItem.Enclosure.Type = itemNode.Attribute(XParseName.Get("type")).Value;
                            break;

                        case "guid":
                            rssItem.GUID    = new GUID();
                            rssItem.GUID.ID = itemNode.Value;
                            if (MyHelper.EnumToArray(itemNode.Attributes()).Length == 1)
                            {
                                rssItem.GUID.IsPermaLink = Convert.ToBoolean(itemNode.Attribute(XParseName.Get("isPermaLink")).Value);
                            }
                            break;

                        case "pubdate":
                            rssItem.PublishDate = RFC822DateFromString(itemNode.Value);
                            break;

                        case "insertdate":
                            rssItem.InsertDate = RFC822DateFromString(itemNode.Value);
                            break;

                        case "source":
                            rssItem.Source       = new Source();
                            rssItem.Source.Title = itemNode.Value;
                            rssItem.Source.Url   = new Uri(itemNode.Attribute(XParseName.Get("url")).Value);
                            break;

                        default:
                            break;
                            //Debug.WriteLine(itemNode.Name.LocalName)
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                return(rssItem);
            }
            return(null);
        }
예제 #15
0
        /// <summary>
        /// Tries to read a HistQuoteData from XML
        /// </summary>
        /// <param name="node">The XML node of HistQuoteData</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 historic quote data or Nothing</returns>
        /// <remarks></remarks>
        public static HistQuotesData ToHistQuoteData(XParseElement node, System.Globalization.CultureInfo culture = null)
        {
            if (node != null && node.Name.LocalName.ToLower() == "histquote" && MyHelper.EnumToArray(node.Elements()).Length > 0)
            {
                System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
                if (culture != null)
                {
                    ci = culture;
                }
                XParseElement[] elm = MyHelper.EnumToArray(node.Elements());
                HistQuotesData  qd  = new HistQuotesData();
                foreach (XParseElement cNode in node.Elements())
                {
                    switch (cNode.Name.LocalName)
                    {
                    case FinanceHelper.NameHistQuoteDate:
                        System.DateTime t1;
                        if (System.DateTime.TryParse(elm[0].Value, out t1))
                        {
                            qd.TradingDate = t1;
                        }
                        break;

                    case FinanceHelper.NameHistQuoteOpen:
                        double t2;
                        if (double.TryParse(elm[1].Value, System.Globalization.NumberStyles.Currency, ci, out t2))
                        {
                            qd.Open = t2;
                        }
                        break;

                    case FinanceHelper.NameHistQuoteHigh:
                        double t3;
                        if (double.TryParse(elm[2].Value, System.Globalization.NumberStyles.Currency, ci, out t3))
                        {
                            qd.High = t3;
                        }
                        break;

                    case FinanceHelper.NameHistQuoteLow:
                        double t4;
                        if (double.TryParse(elm[3].Value, System.Globalization.NumberStyles.Currency, ci, out t4))
                        {
                            qd.Low = t4;
                        }
                        break;

                    case FinanceHelper.NameHistQuoteClose:
                        double t5;
                        if (double.TryParse(elm[4].Value, System.Globalization.NumberStyles.Currency, ci, out t5))
                        {
                            qd.Close = t5;
                        }
                        break;

                    case FinanceHelper.NameHistQuoteAdjClose:
                        double t6;
                        if (double.TryParse(elm[6].Value, System.Globalization.NumberStyles.Currency, ci, out t6))
                        {
                            qd.CloseAdjusted = t6;
                        }
                        break;

                    case FinanceHelper.NameHistQuoteVolume:
                        long t7;
                        if (long.TryParse(elm[5].Value, System.Globalization.NumberStyles.Integer, ci, out t7))
                        {
                            qd.Volume = t7;
                        }
                        break;
                    }
                }
                return(qd);
            }
            else
            {
                return(null);
            }
        }
예제 #16
0
        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);
        }
예제 #17
0
        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);
            }
        }
예제 #18
0
        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));
        }
예제 #19
0
        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));
        }
예제 #20
0
        internal Portfolio ConvertHtmlDoc(XParseDocument doc)
        {
            if (doc != null)
            {
                List <IID>              lstIDs     = new List <IID>();
                PortfolioInfo           ownPf      = null;
                List <PortfolioInfo>    portfolios = new List <PortfolioInfo>();
                List <PortfolioDataRow> dt         = new List <PortfolioDataRow>();
                string selectedView = string.Empty;
                List <PortfolioColumnType> lstColumns     = new List <PortfolioColumnType>();
                List <PortfolioColumnType> lstViewColumns = new List <PortfolioColumnType>();
                List <string> views    = new List <string>();
                XParseElement mainNode = XPath.GetElement("//div[@id=\"yfi-main\"]", doc);
                if (mainNode != null)
                {
                    XParseElement portfoliosNode = XPath.GetElement("/div[@class=\"yfi_dropdown_select\"]/div[@class=\"bd\"]/form/div/select", mainNode);
                    if (portfoliosNode != null)
                    {
                        foreach (XParseElement childNode in portfoliosNode.Elements())
                        {
                            if (childNode.Name.LocalName == "option" && childNode.HasElements)
                            {
                                string id   = childNode.Attribute(XParseName.Get("value")).Value;
                                string name = childNode.Value;
                                portfolios.Add(new PortfolioInfo(name, id));
                                if (childNode.Attribute(XParseName.Get("selected")) != null && childNode.Attribute(XParseName.Get("selected")).Value == "selected")
                                {
                                    ownPf = portfolios[portfolios.Count - 1];
                                }
                            }
                        }
                    }

                    XParseElement[] viewNodes = XPath.GetElements("/div[@class=\"yfi_tablist\"]/div/ul/li", mainNode);
                    if (viewNodes.Length > 0)
                    {
                        foreach (XParseElement viewNode in viewNodes)
                        {
                            if (!viewNode.Value.Contains("Detailed") && !viewNode.Value.Contains("Add Custom View"))
                            {
                                views.Add(viewNode.Value);
                                if (XPath.GetElement("/strong", viewNode) != null)
                                {
                                    selectedView = viewNode.Value;
                                }
                            }
                        }
                    }

                    XParseElement tableNode = XPath.GetElement("/div[@class=\"yfi_module yfi-quotes-table\"]/div[2]/table", mainNode);
                    if (tableNode != null)
                    {
                        XParseElement[] columnCells = XPath.GetElements("/thead/tr/th", tableNode);

                        foreach (XParseElement thNode in columnCells)
                        {
                            XParseAttribute colNameAtt = thNode.Attribute(XParseName.Get("class"));
                            if (colNameAtt != null && colNameAtt.Value.StartsWith("col-"))
                            {
                                string colName = colNameAtt.Value.Split(' ')[0].Replace("col-", "");
                                Nullable <PortfolioColumnType> colType = this.GetColumnType(colName);

                                if (colType != null)
                                {
                                    int subColumnCount = Convert.ToInt32(thNode.Attribute(XParseName.Get("colspan")).Value);
                                    if (subColumnCount == 1)
                                    {
                                        lstColumns.Add(colType.Value);
                                        lstViewColumns.Add(colType.Value);
                                    }
                                    else
                                    {
                                        Nullable <PortfolioColumnType>[] addCT = new Nullable <PortfolioColumnType> [subColumnCount];
                                        switch (colType)
                                        {
                                        case PortfolioColumnType.change:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.change; addCT[1] = PortfolioColumnType.percent_change;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.change_and_percent);
                                            break;

                                        case PortfolioColumnType.time:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.time; addCT[1] = PortfolioColumnType.price;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.price_and_time);
                                            break;

                                        case PortfolioColumnType.day_low:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.day_low; addCT[1] = PortfolioColumnType.day_high;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.day_range);
                                            break;

                                        case PortfolioColumnType.day_value_change:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.day_value_change; addCT[1] = PortfolioColumnType.day_value_percent_change;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.day_value_change_and_percent);
                                            break;

                                        case PortfolioColumnType.fiftytwo_week_low:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.fiftytwo_week_low; addCT[1] = PortfolioColumnType.fiftytwo_week_high;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.fiftytwo_week_range);
                                            break;

                                        case PortfolioColumnType.pre_mkt_time:
                                            PortfolioColumnType t = PortfolioColumnType.pre_mkt_price_and_time;
                                            if (subColumnCount >= 2)
                                            {
                                                addCT[0] = PortfolioColumnType.pre_mkt_time; addCT[1] = PortfolioColumnType.pre_mkt_price;
                                            }
                                            if (subColumnCount == 4)
                                            {
                                                addCT[2] = PortfolioColumnType.after_mkt_time; addCT[3] = PortfolioColumnType.after_mkt_price; t = PortfolioColumnType.pre_after_mkt_price_and_time;
                                            }
                                            lstViewColumns.Add(t);
                                            break;

                                        case PortfolioColumnType.after_mkt_time:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.after_mkt_time; addCT[1] = PortfolioColumnType.after_mkt_price;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.pre_after_mkt_price_and_time);
                                            break;

                                        case PortfolioColumnType.pre_mkt_change:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.pre_mkt_change; addCT[1] = PortfolioColumnType.pre_mkt_percent_change;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.pre_mkt_change_and_percent);
                                            break;

                                        case PortfolioColumnType.after_mkt_change:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.after_mkt_change; addCT[1] = PortfolioColumnType.after_mkt_percent_change;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.after_mkt_change_and_percent);
                                            break;

                                        case PortfolioColumnType.holdings_gain:
                                            if (subColumnCount == 2)
                                            {
                                                addCT[0] = PortfolioColumnType.holdings_gain; addCT[1] = PortfolioColumnType.holdings_percent_gain;
                                            }
                                            lstViewColumns.Add(PortfolioColumnType.holdings_gain_and_percent);
                                            break;
                                        }

                                        for (int i = 0; i < addCT.Length; i++)
                                        {
                                            if (addCT[i] != null)
                                            {
                                                lstColumns.Add(addCT[i].Value);
                                            }
                                            else
                                            {
                                                System.Diagnostics.Debug.WriteLine(colName);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        XParseElement[] tableCells = XPath.GetElements("/tbody/tr", tableNode);
                        foreach (XParseElement trNode in tableCells)
                        {
                            XParseElement[] enm = MyHelper.EnumToArray(trNode.Elements());
                            if (enm.Length > 0)
                            {
                                PortfolioDataRow r = new PortfolioDataRow();
                                for (int i = 0; i < enm.Length; i++)
                                {
                                    XParseElement   tdNode     = enm[i];
                                    XParseAttribute colNameAtt = tdNode.Attribute(XParseName.Get("class"));
                                    if (colNameAtt != null && colNameAtt.Value.StartsWith("col-"))
                                    {
                                        XParseElement[] tdEnm   = MyHelper.EnumToArray(tdNode.Elements());
                                        string          colName = colNameAtt.Value.Split(' ')[0].Replace("col-", "");
                                        if (i < lstColumns.Count && lstColumns[i].ToString() == colName &&
                                            colName != "delete" &&
                                            (tdNode.Attribute(XParseName.Get("class")) != null && !tdNode.Attribute(XParseName.Get("class")).Value.StartsWith("col-delete")) &&
                                            tdEnm.Length > 0 && tdEnm[0].Name.LocalName == "span" && tdEnm[0].Attribute(XParseName.Get("class")) != null && tdEnm[0].Attribute(XParseName.Get("class")).Value == "wrapper")
                                        {
                                            string cellTxt = tdNode.Value;
                                            r[lstColumns[i]] = cellTxt;
                                            if (lstColumns[i] == PortfolioColumnType.symbol)
                                            {
                                                lstIDs.Add(new SimpleID(cellTxt));
                                            }
                                        }
                                    }
                                }
                                dt.Add(r);
                            }
                        }
                    }
                }

                return(new Portfolio(ownPf, lstIDs.ToArray(), dt.ToArray(), selectedView, views.ToArray(), lstColumns.ToArray(), lstViewColumns.ToArray(), portfolios.ToArray()));
            }
            else
            {
                return(null);
            }
        }
예제 #21
0
파일: XML.cs 프로젝트: Bulletz4mysa/NBTrade
        public static Feed ToFeed(XParseElement channel)
        {
            if (channel.Name.LocalName.ToLower() == "channel")
            {
                Feed feed = new Feed();
                foreach (XParseElement prpNode in channel.Elements())
                {
                    try
                    {
                        switch (prpNode.Name.LocalName.ToLower())
                        {
                        case "category":
                            feed.Category      = new Category();
                            feed.Category.Name = prpNode.Value;
                            if (MyHelper.EnumToArray(prpNode.Attributes()).Length == 1)
                            {
                                feed.Category.Domain = new Uri(prpNode.Attribute(XParseName.Get("domain")).Value);
                            }
                            break;

                        case "cloud":
                            feed.Cloud = new Cloud();
                            foreach (XParseAttribute att in prpNode.Attributes())
                            {
                                switch (att.Name.LocalName.ToLower())
                                {
                                case "domain":
                                    feed.Cloud.Domain = new Uri(att.Value);
                                    break;

                                case "path":
                                    feed.Cloud.Path = att.Value;
                                    break;

                                case "registerprocedure":
                                    feed.Cloud.RegisterProcedure = att.Value;
                                    break;

                                case "protocol":
                                    feed.Cloud.Protocol = att.Value;
                                    break;

                                case "port":
                                    int n;
                                    if (int.TryParse(att.Value, out n))
                                    {
                                        feed.Cloud.Port = n;
                                    }
                                    break;
                                }
                            }

                            break;

                        case "copyright":
                            feed.Copyright = prpNode.Value;
                            break;

                        case "description":
                            feed.Description = prpNode.Value;
                            break;

                        case "docs":
                            feed.Documentation = new Uri(prpNode.Value);
                            break;

                        case "generator":
                            feed.Generator = prpNode.Value;
                            break;

                        case "link":
                            feed.Link = new Uri(prpNode.Value);
                            break;

                        case "language":
                            feed.Language = new System.Globalization.CultureInfo(prpNode.Value);
                            break;

                        case "lastbuilddate":
                            feed.LastBuildDate = RFC822DateFromString(prpNode.Value);
                            break;

                        case "managingeditor":
                            feed.ManagingEditor = Rss2MailToMailAddress(prpNode.Value);
                            break;

                        case "name":
                            feed.Name = prpNode.Value;
                            break;

                        case "image":
                            feed.Image = new Image();
                            foreach (XParseElement nodeChild in prpNode.Elements())
                            {
                                switch (nodeChild.Name.LocalName.ToLower())
                                {
                                case "url":
                                    feed.Image.URL = new Uri(nodeChild.Value);
                                    break;

                                case "link":
                                    feed.Image.Link = new Uri(nodeChild.Value);
                                    break;

                                case "title":
                                    feed.Image.Title = nodeChild.Value;
                                    break;

                                case "description":
                                    feed.Image.Description = nodeChild.Value;
                                    break;

                                case "width":
                                    int n;
                                    if (int.TryParse(nodeChild.Value, out n))
                                    {
                                        feed.Image.Width = n;
                                    }
                                    break;

                                case "height":
                                    if (int.TryParse(nodeChild.Value, out n))
                                    {
                                        feed.Image.Height = n;
                                    }
                                    break;
                                }
                            }

                            break;

                        case "item":
                            FeedItem rssItem = ToFeedItem(prpNode);
                            if (rssItem != null)
                            {
                                feed.Items.Add(rssItem);
                            }
                            break;

                        case "pubdate":
                            feed.PublishDate = RFC822DateFromString(prpNode.Value);
                            break;

                        case "rating":
                            feed.Rating = prpNode.Value;
                            break;

                        case "skiphours":
                            List <int> lst1 = new List <int>();
                            foreach (XParseElement nodeChild in prpNode.Elements())
                            {
                                if (nodeChild.Name.LocalName.ToLower() == "hour")
                                {
                                    int @int = 0;
                                    if (int.TryParse(nodeChild.Value, out @int))
                                    {
                                        lst1.Add(@int);
                                    }
                                }
                            }

                            feed.Skiphours = lst1.ToArray();
                            break;

                        case "skipdays":
                            List <DayOfWeek> lst2 = new List <DayOfWeek>();
                            foreach (XParseElement nodeChild in prpNode.Elements())
                            {
                                if (nodeChild.Name.LocalName.ToLower() == "day")
                                {
                                    for (int i = 0; i <= (int)DayOfWeek.Saturday; i++)
                                    {
                                        if (((DayOfWeek)i).ToString().ToUpper() == nodeChild.Value.ToUpper())
                                        {
                                            lst2.Add((DayOfWeek)i);
                                            break;     // TODO: might not be correct. Was : Exit For
                                        }
                                    }
                                }
                            }

                            feed.Skipdays = lst2.ToArray();
                            break;

                        case "textinput":
                            feed.TextInput = new TextInputBox();
                            foreach (XParseElement nodeChild in prpNode.Elements())
                            {
                                switch (nodeChild.Name.LocalName.ToLower())
                                {
                                case "name":
                                    feed.TextInput.Name = nodeChild.Value;
                                    break;

                                case "link":
                                    feed.TextInput.Link = new Uri(nodeChild.Value);
                                    break;

                                case "title":
                                    feed.TextInput.Title = nodeChild.Value;
                                    break;

                                case "description":
                                    feed.TextInput.Description = nodeChild.Value;
                                    break;
                                }
                            }


                            break;

                        case "title":
                            feed.Title = prpNode.Value;
                            break;

                        case "ttl":
                            feed.Ttl = Convert.ToInt32(prpNode.Value);

                            break;

                        case "webmaster":
                            feed.Webmaster = Rss2MailToMailAddress(prpNode.Value);
                            break;

                        default:
                            break;
                            //Debug.WriteLine(node.Name)
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
                return(feed);
            }
            else
            {
                return(null);
            }
        }
예제 #22
0
        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);
            }
        }
예제 #23
0
        protected override FuturesResult ConvertResult(Base.ConnectionInfo connInfo, System.IO.Stream stream, Base.SettingsBase settings)
        {
            FutureData[] result = null;
            if (stream != null)
            {
                System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US");
                XParseDocument doc        = MyHelper.ParseXmlDocument(stream);
                XParseElement  resultNode = XPath.GetElement("//table[@id=\"yfncsumtab\"]/table/tr/td/table[2]/tr/td/table", doc);

                if (resultNode != null)
                {
                    System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
                    List <FutureData> lst = new List <FutureData>();
                    int cnt = 0;
                    foreach (XParseElement node in resultNode.Elements())
                    {
                        if (node.Name.LocalName == "tr")
                        {
                            cnt++;
                            if (cnt > 1)
                            {
                                try
                                {
                                    FutureData data = new FutureData();
                                    double     d; XParseElement tempNode = null;

                                    tempNode = XPath.GetElement("/td[1]", node);
                                    if (tempNode != null)
                                    {
                                        data.SetID(tempNode.Value);
                                    }

                                    tempNode = XPath.GetElement("/td[2]", node);
                                    if (tempNode != null)
                                    {
                                        data.Name = tempNode.Value;
                                    }

                                    tempNode = XPath.GetElement("/td[3]/b", node);
                                    if (tempNode != null && double.TryParse(tempNode.Value, System.Globalization.NumberStyles.Any, ci, out d))
                                    {
                                        data.LastTradePriceOnly = d;
                                    }

                                    tempNode = XPath.GetElement("/td[3]/nobr/small", node);
                                    if (tempNode != null)
                                    {
                                        data.LastTradeTime = tempNode.Value;
                                    }

                                    tempNode = XPath.GetElement("/td[4]/b[1]", node);
                                    if (tempNode != null && double.TryParse(tempNode.Value, System.Globalization.NumberStyles.Any, ci, out d))
                                    {
                                        data.Change = d;
                                    }

                                    tempNode = XPath.GetElement("/td[4]/b[2]", node);
                                    if (tempNode != null && double.TryParse(tempNode.Value.Replace("(", "").Replace(")", "").Replace("%", ""), System.Globalization.NumberStyles.Any, ci, out d))
                                    {
                                        data.ChangeInPercent = d;
                                    }

                                    lst.Add(data);
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                        }
                    }
                    result = lst.ToArray();
                }
            }
            return(new FuturesResult(((FuturesChainDownloadSettings)settings).ID, result));
        }
예제 #24
0
        protected override BondScreenerResult ConvertResult(ConnectionInfo connInfo, System.IO.Stream stream, SettingsBase settings)
        {
            List <BondScreenerData> results = new List <BondScreenerData>();

            System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US");
            XParseDocument doc = MyHelper.ParseXmlDocument(stream);

            XParseElement[] resultsNodes = XPath.GetElements("//results", doc);
            if (resultsNodes.Length == 1)
            {
                XParseElement resultsNode = resultsNodes[0];
                foreach (XParseElement trNode in resultsNode.Elements())
                {
                    XParseAttribute classAtt = trNode.Attribute(XParseName.Get("class"));
                    if (classAtt != null)
                    {
                        if (classAtt.Value == "yfnc_tabledata1")
                        {
                            BondScreenerData res = new BondScreenerData();
                            int index            = 0;
                            foreach (XParseElement tdNode in trNode.Elements())
                            {
                                switch (index)
                                {
                                case 0:
                                    XParseElement fontNode = null;    //tdNode.FirstNode;
                                    switch (fontNode.Value)
                                    {
                                    case "Treas":
                                        res.Type = BondType.Treasury;
                                        break;

                                    case "Zero":
                                        res.Type = BondType.TreasuryZeroCoupon;
                                        break;

                                    case "Corp":
                                        res.Type = BondType.Corporate;
                                        break;

                                    case "Muni":
                                        res.Type = BondType.Municipal;
                                        break;
                                    }
                                    break;

                                case 1:
                                    XParseElement aNode = null;     // tdNode.FirstNode.FirstNode;
                                    fontNode = null;
                                    //fontNode = tdNode.LastNode.FirstNode;
                                    res.Issue = new Link(fontNode.Value.Replace("\n", ""), new Uri("http://reports.finance.yahoo.com" + aNode.Attribute(XParseName.Get("href")).Value));
                                    break;

                                case 2:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode.FirstNode;
                                    double t;
                                    if (double.TryParse(fontNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t))
                                    {
                                        res.Price = t;
                                    }
                                    break;

                                case 3:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode.FirstNode;
                                    if (double.TryParse(fontNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t))
                                    {
                                        res.CouponInPercent = t;
                                    }
                                    break;

                                case 4:
                                    XParseElement nobrNode = null;    // tdNode.FirstNode.FirstNode.FirstNode;
                                    DateTime      d;
                                    if (System.DateTime.TryParseExact(nobrNode.Value, "dd-MMM-yyyy", convCulture, System.Globalization.DateTimeStyles.None, out d))
                                    {
                                        res.Maturity = d;
                                    }
                                    break;

                                case 5:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode.FirstNode;
                                    if (double.TryParse(fontNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t))
                                    {
                                        res.YieldToMaturityInPercent = t;
                                    }
                                    break;

                                case 6:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode.FirstNode;
                                    if (double.TryParse(fontNode.Value, System.Globalization.NumberStyles.Any, convCulture, out t))
                                    {
                                        res.CurrentYieldInPercent = t;
                                    }
                                    break;

                                case 7:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode;
                                    foreach (Rating r in Enum.GetValues(typeof(Rating)))
                                    {
                                        if (r.ToString() == fontNode.Value)
                                        {
                                            res.FitchRating = r;
                                            break;     // TODO: might not be correct. Was : Exit For
                                        }
                                    }

                                    break;

                                case 8:
                                    fontNode = null;
                                    //fontNode = tdNode.FirstNode;
                                    res.Callable = Convert.ToBoolean((fontNode.Value == "Yes" ? true : false));
                                    break;
                                }
                                index += 1;
                            }
                            results.Add(res);
                        }
                    }
                }
            }
            return(new BondScreenerResult(results.ToArray()));
        }
예제 #25
0
        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));
        }
예제 #26
0
        private WeatherFeed ToWeatherFeed(XParseElement channelNode)
        {
            System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US");

            if (channelNode != null)
            {
                RSS.Feed defaultFeed = RSS.ImportExport.XML.ToFeed(channelNode);
                if (defaultFeed != null)
                {
                    defaultFeed.Items.Clear();
                    WeatherFeed feed = new WeatherFeed();
                    feed.CopyValues(defaultFeed);

                    foreach (XParseElement prpNode in channelNode.Elements())
                    {
                        if (prpNode.Name.NamespaceName.ToLower() == "yweather")
                        {
                            switch (prpNode.Name.LocalName.ToLower())
                            {
                            case "location":
                                feed.Location = new LocationInfo();
                                foreach (XParseAttribute att in prpNode.Attributes())
                                {
                                    switch (att.Name.LocalName)
                                    {
                                    case "city":
                                        feed.Location.City = att.Value;
                                        break;

                                    case "region":
                                        feed.Location.Region = att.Value;
                                        break;

                                    case "country":
                                        feed.Location.Country = att.Value;
                                        break;
                                    }
                                }

                                break;

                            case "units":
                                foreach (XParseAttribute att in prpNode.Attributes())
                                {
                                    switch (att.Name.LocalName)
                                    {
                                    case "temperature":
                                        if (att.Value.ToLower() == "f")
                                        {
                                            feed.TemperatureUnit = DegreesUnit.Fahrenheit;
                                        }
                                        else
                                        {
                                            feed.TemperatureUnit = DegreesUnit.Celsius;
                                        }
                                        break;

                                    case "distance":
                                        if (att.Value.ToLower() == "mi")
                                        {
                                            feed.DistanceUnit = DistanceUnit.Miles;
                                        }
                                        else
                                        {
                                            feed.DistanceUnit = DistanceUnit.Kilometer;
                                        }
                                        break;

                                    case "pressure":
                                        if (att.Value.ToLower() == "in")
                                        {
                                            feed.PressureUnit = PressureUnit.PoundsPerSquareInch;
                                        }
                                        else
                                        {
                                            feed.PressureUnit = PressureUnit.Milibars;
                                        }
                                        break;

                                    case "speed":
                                        if (att.Value.ToLower() == "mph")
                                        {
                                            feed.SpeedUnit = DistanceUnit.Miles;
                                        }
                                        else
                                        {
                                            feed.SpeedUnit = DistanceUnit.Kilometer;
                                        }
                                        break;
                                    }
                                }

                                break;

                            case "wind":
                                feed.Wind = new WindInfo();
                                foreach (XParseAttribute att in prpNode.Attributes())
                                {
                                    switch (att.Name.LocalName)
                                    {
                                    case "chill":
                                        int n;
                                        if (int.TryParse(att.Value, out n))
                                        {
                                            feed.Wind.Chill = n;
                                        }
                                        break;

                                    case "direction":
                                        if (int.TryParse(att.Value, out n))
                                        {
                                            feed.Wind.Direction = n;
                                        }
                                        break;

                                    case "speed":
                                        double t;
                                        if (double.TryParse(att.Value, System.Globalization.NumberStyles.Any, convCulture, out t))
                                        {
                                            feed.Wind.Speed = t;
                                        }
                                        break;
                                    }
                                }

                                break;

                            case "atmosphere":
                                feed.Atmosphere = new AtmosphereInfo();
                                foreach (XParseAttribute att in prpNode.Attributes())
                                {
                                    switch (att.Name.LocalName)
                                    {
                                    case "humidity":
                                        int n;
                                        if (int.TryParse(att.Value, out n))
                                        {
                                            feed.Atmosphere.HumidityInPercent = n;
                                        }
                                        break;

                                    case "visibility":
                                        double t;
                                        if (double.TryParse(att.Value, System.Globalization.NumberStyles.Any, convCulture, out t))
                                        {
                                            feed.Atmosphere.VisibilityDistance = t;
                                        }
                                        break;

                                    case "pressure":
                                        if (double.TryParse(att.Value, System.Globalization.NumberStyles.Any, convCulture, out t))
                                        {
                                            feed.Atmosphere.Pressure = t;
                                        }
                                        break;

                                    case "rising":
                                        if (att.Value == "0")
                                        {
                                            feed.Atmosphere.StateOfBarometricPressure = PressureState.Steady;
                                        }
                                        else if (att.Value == "1")
                                        {
                                            feed.Atmosphere.StateOfBarometricPressure = PressureState.Rising;
                                        }
                                        else if (att.Value == "2")
                                        {
                                            feed.Atmosphere.StateOfBarometricPressure = PressureState.Falling;
                                        }
                                        break;
                                    }
                                }

                                break;

                            case "astronomy":
                                feed.Astronomy = new AstronomyInfo();
                                foreach (XParseAttribute att in prpNode.Attributes())
                                {
                                    switch (att.Name.LocalName)
                                    {
                                    case "sunrise":
                                        DateTime d;
                                        if (System.DateTime.TryParse(att.Value, convCulture, System.Globalization.DateTimeStyles.AssumeUniversal, out d))
                                        {
                                            feed.Astronomy.Sunrise = d;
                                        }
                                        break;

                                    case "sunset":
                                        if (System.DateTime.TryParse(att.Value, convCulture, System.Globalization.DateTimeStyles.AssumeUniversal, out d))
                                        {
                                            feed.Astronomy.Sunset = d;
                                        }
                                        break;
                                    }
                                }

                                break;
                            }
                        }
                        else if (prpNode.Name.LocalName.ToLower() == "item")
                        {
                            RSS.FeedItem defaultItem = RSS.ImportExport.XML.ToFeedItem(prpNode);
                            if (defaultItem != null)
                            {
                                WeatherFeedItem newItem = new WeatherFeedItem();
                                newItem.CopyValues(defaultItem);

                                foreach (XParseElement itemNode in prpNode.Elements())
                                {
                                    if (itemNode.Name.NamespaceName == "yweather")
                                    {
                                        switch (itemNode.Name.LocalName.ToLower())
                                        {
                                        case "condition":
                                            newItem.ActualCondition = new ActualCondition();
                                            foreach (XParseAttribute att in itemNode.Attributes())
                                            {
                                                switch (att.Name.LocalName.ToLower())
                                                {
                                                case "text":
                                                    newItem.ActualCondition.Description = att.Value;
                                                    break;

                                                case "code":
                                                    int i = 0;
                                                    if (int.TryParse(att.Value, out i) && (i <= Convert.ToInt32(ConditionType.Isolated_Thundershowers) | i == Convert.ToInt32(ConditionType.Not_Available)))
                                                    {
                                                        newItem.ActualCondition.Type = (ConditionType)i;
                                                    }
                                                    break;

                                                case "temp":
                                                    int n;
                                                    if (int.TryParse(att.Value, out n))
                                                    {
                                                        newItem.ActualCondition.Temperature = n;
                                                    }
                                                    break;

                                                case "date":
                                                    //Wed, 17 Aug 2011 10:18 pm CEST

                                                    string dateStr = att.Value;
                                                    int    index   = Math.Max(dateStr.LastIndexOf("am"), dateStr.LastIndexOf("pm"));
                                                    if (index > 0)
                                                    {
                                                        System.DateTime d = default(System.DateTime);
                                                        if (System.DateTime.TryParseExact(att.Value.Substring(0, index + 2), "ddd, dd MMM yyyy hh:mm tt", convCulture, System.Globalization.DateTimeStyles.None, out d))
                                                        {
                                                            newItem.ActualCondition.ForecastDate = d;
                                                        }
                                                    }
                                                    break;
                                                }
                                            }

                                            break;

                                        case "forecast":
                                            Forecast cond = new Forecast();
                                            foreach (XParseAttribute att in itemNode.Attributes())
                                            {
                                                switch (att.Name.LocalName.ToLower())
                                                {
                                                case "text":
                                                    cond.Description = att.Value;
                                                    break;

                                                case "code":
                                                    int i = 0;
                                                    if (int.TryParse(att.Value, out i) && (i <= Convert.ToInt32(ConditionType.Isolated_Thundershowers) | i == Convert.ToInt32(ConditionType.Not_Available)))
                                                    {
                                                        cond.Type = (ConditionType)i;
                                                    }
                                                    break;

                                                case "day":
                                                    switch (att.Value.ToLower())
                                                    {
                                                    case "mon":
                                                        cond.Day = DayOfWeek.Monday;
                                                        break;

                                                    case "tue":
                                                        cond.Day = DayOfWeek.Tuesday;
                                                        break;

                                                    case "wed":
                                                        cond.Day = DayOfWeek.Wednesday;
                                                        break;

                                                    case "thu":
                                                        cond.Day = DayOfWeek.Thursday;
                                                        break;

                                                    case "fri":
                                                        cond.Day = DayOfWeek.Friday;
                                                        break;

                                                    case "sat":
                                                        cond.Day = DayOfWeek.Saturday;
                                                        break;

                                                    case "sun":
                                                        cond.Day = DayOfWeek.Sunday;
                                                        break;
                                                    }
                                                    break;

                                                case "date":
                                                    DateTime d;
                                                    if (System.DateTime.TryParse(att.Value, convCulture, System.Globalization.DateTimeStyles.AssumeUniversal, out d))
                                                    {
                                                        cond.ForecastDate = d;
                                                    }
                                                    break;

                                                case "low":
                                                    int n;
                                                    if (int.TryParse(att.Value, out n))
                                                    {
                                                        cond.LowTemperature = n;
                                                    }
                                                    break;

                                                case "high":
                                                    if (int.TryParse(att.Value, out n))
                                                    {
                                                        cond.HighTemperature = n;
                                                    }
                                                    break;
                                                }
                                            }

                                            newItem.ForecastConditions.Add(cond);
                                            break;
                                        }
                                    }
                                    else if (itemNode.Name.NamespaceName == "geo")
                                    {
                                        switch (itemNode.Name.LocalName.ToLower())
                                        {
                                        case "lat":
                                            double d = 0;
                                            if (double.TryParse(itemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out d))
                                            {
                                                newItem.Coordinates = new Geo.Coordinates(newItem.Coordinates.Longitude, d);
                                            }
                                            break;

                                        case ("long"):
                                            if (double.TryParse(itemNode.Value, System.Globalization.NumberStyles.Any, convCulture, out d))
                                            {
                                                newItem.Coordinates = new Geo.Coordinates(d, newItem.Coordinates.Latitude);
                                            }
                                            break;
                                        }
                                    }
                                }
                                feed.Items.Add(newItem);
                            }
                        }
                    }
                    return(feed);
                }
            }
            return(null);
        }