Пример #1
0
        public FileDiskService(string connectionString, Logger log)
        {
            var str = new ConnectionString(connectionString);

            _filename = str.GetValue <string>("filename", "");
            var journalEnabled = str.GetValue <bool>("journal", true);

            _timeout     = str.GetValue <TimeSpan>("timeout", new TimeSpan(0, 1, 0));
            _readonly    = str.GetValue <bool>("readonly", false);
            _password    = str.GetValue <string>("password", null);
            _initialSize = str.GetFileSize("initial size", 0);
            _limitSize   = str.GetFileSize("limit size", 0);
            var level = str.GetValue <byte?>("log", null);

            // simple validations
            if (string.IsNullOrWhiteSpace(_filename))
            {
                throw new ArgumentNullException("filename");
            }
            if (_initialSize > 0 && _initialSize < (BasePage.PAGE_SIZE * 10))
            {
                throw new ArgumentException("initial size too low");
            }
            if (_limitSize > 0 && _limitSize < (BasePage.PAGE_SIZE * 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));
        }
Пример #2
0
        public FileDiskService(ConnectionString conn, Logger log)
        {
            // setting all class variables
            _filename       = conn.GetValue <string>("filename", "");
            _journalEnabled = conn.GetValue <bool>("journal", true);
            _timeout        = conn.GetValue <TimeSpan>("timeout", new TimeSpan(0, 1, 0));
            _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;
            }

            _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));

            _fileHandler = LitePlatform.Platform.FileHandler;
        }