Beispiel #1
0
        public Task Load(ConcurrentChain chain)
        {
            Guard.Assert(chain.Tip == chain.Genesis);

            return(_Session.Do(() =>
            {
                ChainedBlock tip = null;
                bool first = true;
                foreach (var row in _Session.Transaction.SelectForward <int, BlockHeader>("Chain"))
                {
                    if (tip != null && row.Value.HashPrevBlock != tip.HashBlock)
                    {
                        break;
                    }
                    tip = new ChainedBlock(row.Value, null, tip);

                    if (first)
                    {
                        first = false;
                        Guard.Assert(tip.HashBlock == chain.Genesis.HashBlock);                         // can't swap networks
                    }
                }
                if (tip == null)
                {
                    return;
                }
                _Locator = tip.GetLocator();
                chain.SetTip(tip);
            }));
        }
Beispiel #2
0
        protected override Task <byte[]> GetBytes(string key)
        {
            Guard.NotEmpty(key, nameof(key));

            return(_Session.Do(() =>
            {
                var row = _Session.Transaction.Select <string, byte[]>(_Name, key);
                if (row == null || !row.Exists)
                {
                    return null;
                }
                return row.Value;
            }));
        }
Beispiel #3
0
        public DBreezeNoSqlRepository(string name, string folder)
        {
            Guard.NotEmpty(name, nameof(name));
            Guard.NotEmpty(folder, nameof(folder));

            _Name    = name;
            _Session = new DBreezeSingleThreadSession(name, folder);
            _Session.Do(() =>
            {
                _Session.Transaction.ValuesLazyLoadingIsOn = false;
            });
        }