Example #1
0
        /// <summary>
        /// take csv data and push it into a List
        /// </summary>
        /// <param name="csvData">data from Google or Yahoo in CSV format</param>
        /// <returns></returns>
        public static List <StockItem> GetAllStockDetails(string csvData)
        {
            List <StockItem> parsedStockData = new List <StockItem>();

            using (StringReader reader = new StringReader(csvData))
            {
                string csvLine;

                //drop the first row because it is a header we don't need
                //reader.ReadLine();

                while ((csvLine = reader.ReadLine()) != null)
                {
                    string[] splitLine = csvLine.Split(',');

                    if (splitLine.Length >= 6)
                    {
                        StockItem newItem = new StockItem();

                        newItem.Symbol       = splitLine[0].Trim(new char[] { '"' });
                        newItem.CompanyName  = splitLine[1].Trim(new char[] { '"' });
                        newItem.CurrentPrice = splitLine[2].Trim(new char[] { '"' });
                        newItem.PercentageOfChangeFromLastDay = splitLine[3].Trim(new char[] { '"' });
                        newItem.FiftyTwoWeekHigh = splitLine[4].Trim(new char[] { '"' });
                        newItem.FiftyTwoWeekLow  = splitLine[5].Trim(new char[] { '"' });

                        parsedStockData.Add(newItem);

                        ////parse all values from the downloaded csv file
                        //double tempOpen;
                        //if (Double.TryParse(splitLine[1], out tempOpen))
                        //{
                        //    newItem.Symbol = tempOpen;
                        //}
                        //double tempHigh;
                        //if (Double.TryParse(splitLine[2], out tempHigh))
                        //{
                        //    newItem.high = tempHigh;
                        //}
                        //double tempLow;
                        //if (Double.TryParse(splitLine[3], out tempLow))
                        //{
                        //    newItem.low = tempLow;
                        //}
                        //double tempClose;
                        //if (Double.TryParse(splitLine[4], out tempClose))
                        //{
                        //    newItem.close = tempClose;
                        //}
                        //double tempVolume;
                        //if (Double.TryParse(splitLine[5], out tempVolume))
                        //{
                        //    newItem.volume = tempVolume;
                        //}

                        ////if we parse the date successfully, we add the
                        ////new StockDataItem to our result set
                        //DateTime tempDate;
                        //if (DateTime.TryParse(splitLine[0], out tempDate))
                        //{
                        //    parsedStockData.Add(tempDate, newItem);
                        //}
                    }
                }
            }

            return(parsedStockData);
        }