Пример #1
0
 protected virtual void Dispose(bool disposing)
 {
     ReleaseUnmanagedResources();
     if (disposing)
     {
         _disk?.Dispose();
         _crypto?.Dispose();
     }
 }
Пример #2
0
        public void Dispose()
        {
            // dispose datafile and journal file
            _disk.Dispose();

            // dispose crypto
            if (_crypto != null)
            {
                _crypto.Dispose();
            }
        }
Пример #3
0
        public void Dispose()
        {
            // first, commit any possible dirty page
            this.Commit();

            // dispose datafile and journal file
            _disk.Dispose();

            // dispose crypto
            if (_crypto != null)
            {
                _crypto.Dispose();
            }
        }
Пример #4
0
        public void Dispose()
        {
            // if there is any open transaction, rollback
            if (_transactions.Count > 0)
            {
                this.Rollback();
            }

            // dispose datafile and journal file
            _disk.Dispose();

            // dispose crypto
            if (_crypto != null)
            {
                _crypto.Dispose();
            }
        }
Пример #5
0
        /// <summary>
        /// Initialize LiteEngine using custom disk service implementation and full engine options
        /// </summary>
        public LiteEngine(IDiskService disk, string password = null, TimeSpan?timeout = null, int cacheSize = 5000, Logger log = null)
        {
            if (disk == null)
            {
                throw new ArgumentNullException("disk");
            }

            _timeout   = timeout ?? TimeSpan.FromMinutes(1);
            _cacheSize = cacheSize;
            _disk      = disk;
            _log       = log ?? new Logger();

            // initialize datafile (create) and set log instance
            _disk.Initialize(_log, password);

            // read header page
            var header = BasePage.ReadPage(_disk.ReadPage(0)) as HeaderPage;

            // hash password with sha1 or keep as empty byte[20]
            var sha1 = password == null ? new byte[20] : AesEncryption.HashSHA1(password);

            // compare header password with user password even if not passed password (datafile can have password)
            if (sha1.BinaryCompareTo(header.Password) != 0)
            {
                // explicit dispose
                _disk.Dispose();
                throw LiteException.DatabaseWrongPassword();
            }

            // initialize AES encryptor
            if (password != null)
            {
                _crypto = new AesEncryption(password, header.Salt);
            }

            // initialize all services
            this.InitializeServices();

            // try recovery data only if journal are enabled
            if (_disk.IsJournalEnabled)
            {
                // try recovery if has journal file
                _trans.Recovery();
            }
        }
Пример #6
0
        /// <summary>
        /// Initialize LiteEngine using custom disk service implementation and full engine options
        /// </summary>
        public LiteEngine(IDiskService disk, string password = null, TimeSpan? timeout = null, bool autocommit = true, int cacheSize = 5000, Logger log = null)
        {
            _timeout = timeout ?? TimeSpan.FromMinutes(1);
            _cacheSize = cacheSize;
            _autocommit = autocommit;
            _disk = disk;
            _log = log ?? new Logger();
            _locker = new Locker(_timeout);

            // initialize datafile (create) and set log instance
            _disk.Initialize(_log, password);

            // read header page
            var header = BasePage.ReadPage(_disk.ReadPage(0)) as HeaderPage;

            // hash password with sha1 or keep as empty byte[20]
            var sha1 = password == null ? new byte[20] : AesEncryption.HashSHA1(password);

            // compare header password with user password even if not passed password (datafile can have password)
            if (sha1.BinaryCompareTo(header.Password) != 0)
            {
                // explicit dispose
                _disk.Dispose();
                throw LiteException.DatabaseWrongPassword();
            }

            // initialize AES encryptor
            if (password != null)
            {
                _crypto = new AesEncryption(password, header.Salt);
            }

            // initialize all services
            this.InitializeServices();

            if (_disk.IsJournalEnabled)
            {
                // try recovery if has journal file
                _trans.Recovery();
            }
        }
Пример #7
0
 public void Dispose()
 {
     _disk.Dispose();
 }