Exemple #1
0
        public void Initialize(LoggerWrap log, string password)
        {
            // get log instance to disk
            _log = log;

            // if is read only, journal must be disabled
            if (_options.FileMode == FileMode.ReadOnly)
            {
                _options.Journal = false;
            }

            // open/create file using read only/exclusive options
            _stream = CreateFileStream(_filename,
                                       _options.FileMode == FileMode.ReadOnly ? System.IO.FileMode.Open : System.IO.FileMode.OpenOrCreate,
                                       _options.FileMode == FileMode.ReadOnly ? FileAccess.Read : FileAccess.ReadWrite,
                                       _options.FileMode == FileMode.Exclusive ? FileShare.None : FileShare.ReadWrite);

            // if file is new, initialize
            if (_stream.Length == 0)
            {
                _log.Write(LoggerWrap.DISK, "initialize new datafile");

                // set datafile initial size
                _stream.SetLength(_options.InitialSize);

                // create datafile
                LiteEngine.CreateDatabase(_stream, password);
            }
        }
Exemple #2
0
 public PageService(IDiskService disk, AesEncryption crypto, CacheService cache, LoggerWrap log)
 {
     _disk   = disk;
     _crypto = crypto;
     _cache  = cache;
     _log    = log;
 }
Exemple #3
0
 internal LockService(IDiskService disk, CacheService cache, TimeSpan timeout, LoggerWrap log)
 {
     _disk    = disk;
     _cache   = cache;
     _log     = log;
     _timeout = timeout;
     _state   = LockState.Unlocked;
 }
Exemple #4
0
 public CollectionService(PageService pager, IndexService indexer, DataService data, TransactionService trans, LoggerWrap log)
 {
     _pager   = pager;
     _indexer = indexer;
     _data    = data;
     _trans   = trans;
     _log     = log;
 }
Exemple #5
0
 public LiteCollection(string name, LazyLoad <LiteEngine> engine, BsonMapper mapper, LoggerWrap log)
 {
     _name     = name ?? mapper.ResolveCollectionName(typeof(T));
     _engine   = engine;
     _mapper   = mapper;
     _log      = log;
     _visitor  = new QueryVisitor <T>(mapper);
     _includes = new List <Action <BsonDocument> >();
 }
 internal TransactionService(IDiskService disk, AesEncryption crypto, PageService pager, LockService locker, CacheService cache, int cacheSize, LoggerWrap log)
 {
     _disk      = disk;
     _crypto    = crypto;
     _cache     = cache;
     _locker    = locker;
     _pager     = pager;
     _cacheSize = cacheSize;
     _log       = log;
 }
Exemple #7
0
        public void Initialize(LoggerWrap log, string password)
        {
            // get log instance to disk
            _log = log;

            // if stream are empty, create header page and save to stream
            if (_stream.Length == 0)
            {
                _log.Write(LoggerWrap.DISK, "initialize new datafile");

                // create datafile
                LiteEngine.CreateDatabase(_stream, password);
            }
        }
Exemple #8
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, LoggerWrap log = null)
        {
            if (disk == null)
            {
                throw new ArgumentNullException("disk");
            }

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

            try
            {
                // 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)
                {
                    throw LiteException.DatabaseWrongPassword();
                }

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

                // initialize all services
                this.InitializeServices();

                // try recovery if has journal file
                _trans.Recovery();
            }
            catch (Exception)
            {
                // explicit dispose
                this.Dispose();
                throw;
            }
        }
Exemple #9
0
 public CacheService(IDiskService disk, LoggerWrap log)
 {
     _disk = disk;
     _log  = log;
 }
Exemple #10
0
        /// <summary>
        /// Starts LiteDB database using a custom IDiskService with all parameters available
        /// </summary>
        /// <param name="diskService">Custom implementation of persist data layer</param>
        /// <param name="mapper">Instance of BsonMapper that map poco classes to document</param>
        /// <param name="password">Password to encrypt you datafile</param>
        /// <param name="timeout">Locker timeout for concurrent access</param>
        /// <param name="cacheSize">Max memory pages used before flush data in Journal file (when available)</param>
        /// <param name="log">Custom log implementation</param>
        public LiteDatabase(IDiskService diskService, BsonMapper mapper = null, string password = null, TimeSpan?timeout = null, int cacheSize = 5000, LoggerWrap log = null)
        {
            if (diskService == null)
            {
                throw new ArgumentNullException("diskService");
            }

            _mapper = mapper ?? BsonMapper.Global;

            _engine = new LazyLoad <LiteEngine>(() => new LiteEngine(diskService, password: password, timeout: timeout, cacheSize: cacheSize, log: _log));
        }
Exemple #11
0
 public IndexService(PageService pager, LoggerWrap log)
 {
     _pager = pager;
     _log   = log;
 }
Exemple #12
0
 public DataService(PageService pager, LoggerWrap log)
 {
     _pager = pager;
     _log   = log;
 }