public ViewModelData GetPricesFromCSVFile(string fileName) { if (File.Exists(fileName)) { char[] comma = new char[] { ',' }; char[] slashN = new char[] { '\n' }; ViewModelData list = new ViewModelData(); string s = File.ReadAllText(fileName); string[] lines = s.Split(slashN); bool firstLine = true; string[] values; int count = lines.Count() - 2; GoogleData priceInfo; int index = 0; foreach (string line in lines) { if (index == 750) { } if (count != -1 && index >= 1250) { break; } if (!firstLine) { values = line.Split(comma); if (values.GetLength(0) > 5) { priceInfo = new GoogleData() { TimeStamp = DateTime.Parse(values[0], CultureInfo.InvariantCulture), Open = double.Parse(values[1]), High = double.Parse(values[2]), Low = double.Parse(values[3]), Last = double.Parse(values[4]), Volume = double.Parse(values[5]) }; list.Insert(index, priceInfo); index++; } } else { firstLine = false; } } return(list); } else { return(null); } }
public ViewModel() { _googleData = this.GetPricesFromCSVFile(@"..//..//Data//GOOG.csv"); }