public SortedList<DateTime, InfomaxDataRow> LoadData( String targetCode, String path, InfomaxDataRow.Type targetType) { SortedList<DateTime, InfomaxDataRow> data = new SortedList<DateTime, InfomaxDataRow>(); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader sr = new StreamReader(fs); while (!sr.EndOfStream) { String line = sr.ReadLine(); StringPacket sp = new StringPacket(line); sp.Decode(); // skip sp.Decode(); // skip InfomaxDataRow.Type type = InfomaxDataRow.Type.Unknown; String strType = sp.Decode(); if (strType.CompareTo("CurPrice") == 0) { type = InfomaxDataRow.Type.CurPrice; } else if (strType.CompareTo("BidPrice") == 0) { type = InfomaxDataRow.Type.BidPrice1; } else if (strType.CompareTo("AskPrice") == 0) { type = InfomaxDataRow.Type.AskPrice1; } double value = sp.DecodeDouble(); DateTime dt = DateTime.ParseExact(sp.Decode(), "yyyyMMdd HH:mm:ss.fff", null); if (type == targetType) { InfomaxDataRow row = new InfomaxDataRow(); row.RowType = type; row.Value = value; row.CurDateTime = dt; data.Add(dt, row); } } sr.Close(); fs.Close(); return data; }
public SortedList<DateTime, InfomaxDataRow> LoadData( String targetCode, String path, InfomaxDataRow.Type targetType) { SortedList<DateTime, InfomaxDataRow> data = new SortedList<DateTime, InfomaxDataRow>(); FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader sr = new StreamReader(fs); while (!sr.EndOfStream) { String line = sr.ReadLine(); StringPacket sp = new StringPacket(line); String code = sp.Decode(); if (code.CompareTo(targetCode) == 0) { InfomaxDataRow.Type type = InfomaxDataRow.ConvertStringToType(sp.Decode()); double value = sp.DecodeDouble(); DateTime dt = DateTime.ParseExact(sp.Decode(), "yyyyMMdd HH:mm:ss.fff", null); if (type == targetType) { InfomaxDataRow row = new InfomaxDataRow(); row.RowType = type; row.Value = value; row.CurDateTime = dt; data.Add(dt, row); } } } sr.Close(); fs.Close(); return data; }