示例#1
0
        private List<StockData> ParseCsvData(string csvData)
        {
            Print("Parsing");
            var result = new List<StockData>();

            using (var reader = new StringReader(csvData))
            {
                using (var fields = new CsvReader(reader, true))
                {
                    while (fields.ReadNextRecord())
                    {
                        try
                        {
                            int i = 0;
                            var x = new StockData();

                            x.Date = DateTime.ParseExact(fields[i++], "yyyy-MM-dd", null);
                            x.Open = double.Parse(fields[i++]);
                            x.High = double.Parse(fields[i++]);
                            x.Low = double.Parse(fields[i++]);
                            x.Close = double.Parse(fields[i++]);
                            x.Volume = double.Parse(fields[i++]);
                            x.AdjClose = double.Parse(fields[i++]);

                            result.Add(x);
                        } catch (Exception e)
                        {
                            Print(e.Message + e.StackTrace);
                        }
                    }
                }
            }

            Print("Parsing completed. {0} items downloaded", result.Count);
            return result;
        }