Esempio n. 1
0
        public void LoadFromStream(Stream s)
        {
            _stream?.Dispose();
            _stream = null;
            _stream = new MemoryStream();
            s.CopyTo(_stream);
            // stream = s;
            _stream.Position = 0;
            Header           = new CheckPointHeader(_stream);
            Accounts         = new List <Account>();
            WorkSum          = 0;
            for (uint i = 0; i < Header.EndBlock - Header.StartBlock; i++)
            {
                try
                {
                    var b = this[i];
                    WorkSum += b.CompactTarget;
                    Accounts.AddRange(b.Accounts);
                }
                catch (Exception e)
                {
#if !NETCOREAPP
                    Log.Error(e.Message, e);
#endif
                }
            }
#if !NETCOREAPP
            Log.Info(WorkSum);
#endif
        }
Esempio n. 2
0
 public CheckPoint SaveChunk(uint startBlock, uint endBlock)
 {
     lock (LoadLock)
     {
         var list   = new List <CheckPointBlock>();
         var header = new CheckPointHeader
         {
             StartBlock = startBlock,
             EndBlock   = endBlock,
             BlockCount = endBlock - startBlock + 1
         };
         for (var i = startBlock; i <= endBlock; i++)
         {
             list.Add(this[i]);
         }
         var ms = new MemoryStream();
         header.Offsets = new uint[list.Count + 1];
         header.SaveToStream(ms);
         long headerSize = ms.Position;
         ms.Position = 0;
         using (var bw = new BinaryWriter(ms, Encoding.Default, true))
         {
             uint i = 0;
             foreach (var b in list)
             {
                 header.Offsets[i] = (uint)(ms.Position + headerSize);
                 b.SaveToStream(ms);
                 i++;
             }
         }
         var memoryStream = new MemoryStream();
         header.SaveToStream(memoryStream);
         ms.Position = 0;
         ms.CopyTo(memoryStream);
         memoryStream.Write(header.Hash, 0, header.Hash.Length);
         if (_stream != null)
         {
             _stream.Dispose();
             _stream = null;
         }
         memoryStream.Position = 0;
         var checkPoint = new CheckPoint(memoryStream);
         ms.Dispose();
         memoryStream.Dispose();
         GC.Collect();
         return(checkPoint);
     }
 }
Esempio n. 3
0
        public void LoadFromFile(string filename)
        {
            FileStream fs = File.Open(filename, FileMode.Open, FileAccess.ReadWrite);

            _stream?.Dispose();
            _stream = null;
            _stream = fs;
            Accounts.Clear();
            Accounts = null;
            GC.Collect();
            Header   = new CheckPointHeader(_stream);
            Accounts = new List <Account>();
            WorkSum  = 0;
            for (uint i = 0; i < Header.EndBlock - Header.StartBlock; i++)
            {
                WorkSum += this[i].CompactTarget;
                foreach (Account a in this[i].Accounts)
                {
                    Accounts.Add(a);
                    // Accounts.AddRange(b.Accounts);
                }
            }
        }