/// <summary> /// Starts LiteDB database using a connection string for filesystem database /// </summary> public LiteDatabase(string connectionString) { var conn = new ConnectionString(connectionString); var version = conn.GetValue <ushort>("version", 0); var encrypted = !StringExtensions.IsNullOrWhiteSpace(conn.GetValue <string>("password", null)); _engine = new LazyLoad <DbEngine>( () => new DbEngine(encrypted ? new EncryptedDiskService(conn, _log) : new FileDiskService(conn, _log), _log), () => this.InitializeMapper(), () => this.UpdateDbVersion(version)); }
public FileDiskService(ConnectionString conn, Logger log) { _filename = conn.GetValue("filename", ""); var journalEnabled = conn.GetValue("journal", true); _timeout = conn.GetValue("timeout", new TimeSpan(0, 1, 0)); _readonly = conn.GetValue("readonly", false); _initialSize = conn.GetFileSize("initial size", 0); _limitSize = conn.GetFileSize("limit size", 0); var level = conn.GetValue <byte?>("log", null); // simple validations if (_filename.IsNullOrWhiteSpace()) { throw new ArgumentNullException("filename"); } if (_initialSize > 0 && _initialSize < BasePage.GetSizeOfPages(10)) { throw new ArgumentException("initial size too low"); } if (_limitSize > 0 && _limitSize < BasePage.GetSizeOfPages(10)) { throw new ArgumentException("limit size too low"); } if (_initialSize > 0 && _limitSize > 0 && _initialSize > _limitSize) { throw new ArgumentException("limit size less than initial size"); } // setup log + log-level _log = log; if (level.HasValue) { _log.Level = level.Value; } _journalEnabled = _readonly ? false : journalEnabled; // readonly? no journal _journalFilename = Path.Combine(Path.GetDirectoryName(_filename), Path.GetFileNameWithoutExtension(_filename) + "-journal" + Path.GetExtension(_filename)); _tempFilename = Path.Combine(Path.GetDirectoryName(_filename), Path.GetFileNameWithoutExtension(_filename) + "-temp" + Path.GetExtension(_filename)); }
public EncryptedDiskService(ConnectionString conn, Logger log) : base(conn, log) { // initialize AES with passoword var password = conn.GetValue <string>("password", null); // hash password to store in header to check _password = SimpleAES.HashSHA1(password); _crypto = new SimpleAES(password); }
public EncryptedDiskService(ConnectionString conn, Logger log) : base(conn, log) { // initialize AES with passoword var password = conn.GetValue <string>("password", null); // hash password to store in header to check if password is correct _crypto = LitePlatform.Platform.GetEncryption(password); _password = _crypto.HashSHA1(password); }
/// <summary> /// Starts LiteDB database using a connection string for filesystem database /// </summary> public LiteDatabase(string connectionString, BsonMapper mapper = null) { LitePlatform.ThrowIfNotInitialized(); var conn = new ConnectionString(connectionString); _mapper = mapper ?? BsonMapper.Global; var encrypted = !StringExtensions.IsNullOrWhiteSpace(conn.GetValue <string>("password", null)); _engine = new LazyLoad <DbEngine>(() => new DbEngine(encrypted ? new EncryptedDiskService(conn, _log) : new FileDiskService(conn, _log), _log)); }