Exemplo n.º 1
0
        /// <summary>
        /// Takes a XDocument, parses it and returns a list of stock objects that corresponds to valid
        /// stock symbols
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static List <Stock> getValidStocks(XDocument doc)
        {
            List <Stock> stocks = new List <Stock>();

            foreach (var root in doc.Root.Elements("finance"))
            {
                try
                {
                    if (root.Element("last") != null && root.Element("last").Attribute("data").Value != null && root.Element("last").Attribute("data").Value.Equals("0.00") == false)
                    {
                        stocks.Add(Stock_quotes.createNewStock(root));
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show(root.Element("symbol").Attribute("data").Value + " is not a valid stock symbol");
                    }
                }
                catch (Exception er)
                {
                    //Error message
                }
            }

            return(stocks);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves a particular stock from the XDocument.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="symbol"></param>
        /// <param name="lookUpField"></param>
        /// <returns></returns>
        public static Stock getThisStock(XDocument doc, string symbol, string lookUpField)
        {
            Stock stock = null;

            foreach (var root in doc.Root.Elements("finance"))
            {
                if (root.Element(lookUpField).Attribute("data").Value.Equals(symbol))
                {
                    return(Stock_quotes.createNewStock(root));
                }
            }

            return(stock);
        }