private void LoadTradesFromFile(DateCollection newCol) { FileLib.WFile f = new FileLib.WFile(GetFilePath(newCol.Date)); if (!f.Exists()) { return; } var strings = f.ReadAllLines(); strings.ForEach <string>((s) => { if (s.Empty()) { return; } var dataTrade = s.Split('\t'); var trade = new Trade(); trade.Number = dataTrade[0].ToLong(); trade.Price = dataTrade[2].ToDecimal(); trade.Volume = dataTrade[3].ToInt32(); trade.Direction = dataTrade[4] == "B" ? OrderDirection.Buy : OrderDirection.Sell; trade.SecCode = dataTrade[5]; newCol.Trades.Add(trade); }); }
/// <summary> Чтение коллекции из файла в сериализованном виде. </summary> /// <param name="filename"></param> public void ReadCollectionFromFile(string filename) { this.TimeLastWrite = DateTime.Now; FileLib.WFile file = new FileLib.WFile(filename); if (!file.Exists()) { return; } if (file.Size() == 0) { return; } MutexCollection.WaitOne(); using (Stream stream = File.Open(filename, FileMode.Open)) { try { var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); this.Collection = (List <CandleData>)binaryFormatter.Deserialize(stream); } catch (Exception e) { string er = e.ToString(); } } MutexCollection.ReleaseMutex(); }