Пример #1
0
 /// <summary>
 /// Loads all files then saves them again ( so format is updates )
 /// </summary>
 private void Update1()
 {
     //get a
     var files = Directory.GetFiles(DataDir, "*.bin");
     IEnumerable <IGrouping <string, string> > filesGrouped;
     //if (files.Length > 0)
     {
         files        = files.Concat(Directory.GetFiles(DataDir, "*.bin2")).ToArray();
         filesGrouped = files.GroupBy(
             f =>
         {
             var info = HistoryChunkId.Parse(f);
             return(info.HistoryId.Key);
         }
             );
         foreach (var group in filesGrouped)
         {
             var info         = HistoryChunkId.Parse(group.First());
             var histMetadata = new SymbolHistoryMetaDataInternal(info.HistoryId);
             foreach (var fpath in group)
             {
                 var fdata = HistoryChunk.Load(fpath);
                 histMetadata.AddBars(fdata.Ticks);
                 if (Path.GetExtension(fpath) == ".bin")
                 {
                     File.Delete(fpath);
                 }
             }
             histMetadata.Save(DataDir);
         }
     }
 }
Пример #2
0
        private void Update2()
        {
            var data  = new Dictionary <string, SymbolHistoryMetaDataInternal>();
            var files = Directory.GetFiles(DataDir, "*.bin2");

            foreach (var filePath in files)
            {
                var fileInfo = HistoryChunkId.Parse(filePath);
                //-- get metaData --
                if (!data.ContainsKey(fileInfo.HistoryId.Key))
                {
                    data.Add(fileInfo.HistoryId.Key, new SymbolHistoryMetaDataInternal(fileInfo.HistoryId));
                }
                var symData = data[fileInfo.HistoryId.Key];

                symData.Chunks.Add(fileInfo);

                //update first and last tick time
                HistoryChunk fileData = HistoryChunk.Load(filePath);
                if (fileData.Ticks.Count > 0)
                {
                    symData.UpdateLastBar(fileData.Ticks.First());
                    symData.UpdateLastBar(fileData.Ticks.Last());
                }
            }
            //reinsert everything
            DbSymbolsMetaData.DeleteAll();
            Db.Checkpoint();
            var allData = data.Values.ToArray();

            foreach (var dat in allData)
            {
                DbSymbolsMetaData.Upsert(dat);
            }
            Db.Checkpoint();
        }