Exemplo n.º 1
0
 internal LockService(IDiskService disk, CacheService cache, TimeSpan timeout, Logger log)
 {
     _disk    = disk;
     _cache   = cache;
     _log     = log;
     _timeout = timeout;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="FileSystemType"/> class.
        /// </summary>
        /// <param name="fileSystemService">The application layer DiskService.</param>
        /// <param name="logger">The NLog logger instance.</param>
        public FileSystemType(IDiskService fileSystemService, ILogger logger)
        {
            this.Field(x => x.Name);
            this.Field(x => x.Type);
            this.Field(x => x.Total);

            this.Field <FileSystemStatusType>()
            .Name("Status")
            .ResolveAsync(async context =>
            {
                logger.Debug("File System status field");

                return(await fileSystemService.GetLastFileSystemStatusAsync(context.Source.Name));
            });

            this.Connection <FileSystemStatusType>()
            .Name("Statuses")
            .Bidirectional()
            .ResolveAsync(async context =>
            {
                logger.Debug("File System statuses connection");

                var pagingInput = context.GetPagingInput();
                var statuses    = await fileSystemService.GetFileSystemStatusesAsync(context.Source.Name, pagingInput);

                return(statuses.ToConnection());
            });
        }
Exemplo n.º 3
0
 /// <summary>
 /// Starts LiteDB database using full parameters
 /// </summary>
 public LiteDatabase(IDiskService diskService)
 {
     this.InitializeMapper();
     _engine = new Lazy <DbEngine>(
         () => new DbEngine(diskService, _log),
         false);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Starts LiteDB database using full parameters
 /// </summary>
 public LiteDatabase(IDiskService diskService, ushort version = 0)
 {
     _engine = new LazyLoad <DbEngine>(
         () => new DbEngine(diskService, _log),
         () => this.InitializeMapper(),
         () => this.UpdateDbVersion(version));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Starts LiteDB database using full parameters
 /// </summary>
 public LiteDatabase(IDiskService diskService)
 {
     this.InitializeMapper();
     _engine = new Lazy<DbEngine>(
         () => new DbEngine(diskService, _log),
         false);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Starts LiteDB database using a custom IDiskService
        /// </summary>
        public LiteDatabase(IDiskService diskService, BsonMapper mapper = null)
        {
            LitePlatform.ThrowIfNotInitialized();

            _mapper = mapper ?? BsonMapper.Global;
            _engine = new LazyLoad <DbEngine>(() => new DbEngine(diskService, _log));
        }
Exemplo n.º 7
0
 public LockService(IDiskService disk, TimeSpan timeout, Logger log)
 {
     _disk    = disk;
     _log     = log;
     _timeout = timeout;
     _state   = LockState.Unlocked;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Starts LiteDB database using full parameters
 /// </summary>
 public LiteDatabase(IDiskService diskService, ushort version = 0)
 {
     _engine = new LazyLoad<DbEngine>(
         () => new DbEngine(diskService, _log),
         () => this.InitializeMapper(),
         () => this.UpdateDbVersion(version));
 }
Exemplo n.º 9
0
        //private Logger _log;

        public PageService(IDiskService disk, AesEncryption crypto, CacheService cache, Logger log)
        {
            _disk   = disk;
            _crypto = crypto;
            _cache  = cache;
            //_log = log;
        }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DiskWorker"/> class.
 /// </summary>
 /// <param name="diskService">The application layer DiskService.</param>
 /// <param name="configuration">The IConfiguration instance.</param>
 /// <param name="logger">The NLog logger instance.</param>
 public DiskWorker(
     IDiskService diskService,
     IConfiguration configuration,
     ILogger logger)
     : base(diskService, configuration, logger)
 {
 }
Exemplo n.º 11
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, bool utcDate = false)
        {
            if (disk == null)
            {
                throw new ArgumentNullException("disk");
            }

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

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

                // lock disk (read mode) before read header
                var position = _disk.Lock(LockState.Read, _timeout);

                var buffer = _disk.ReadPage(0);

                _disk.Unlock(LockState.Read, position);

                // create header instance from array bytes
                var header = BasePage.ReadPage(buffer) 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();

                // if header are marked with recovery, do it now
                if (header.Recovery)
                {
                    _trans.Recovery();
                }
            }
            catch (Exception)
            {
                // explicit dispose
                this.Dispose();
                throw;
            }
        }
Exemplo n.º 12
0
 public RepositoryContext(string repositoryDirectory, string remoteRepositoryUrl, Credentials credentials, IGitService gitService, IDiskService diskService)
 {
     this.RepositoryDirectory = repositoryDirectory;
     this.RemoteRepositoryUrl = remoteRepositoryUrl;
     this.credentials         = credentials;
     this.gitService          = gitService;
     this.diskService         = diskService;
 }
 internal TransactionService(IDiskService disk, PageService pager, CacheService cache)
 {
     _disk  = disk;
     _pager = pager;
     _cache = cache;
     _cache.MarkAsDirtyAction  = page => _disk.WriteJournal(page.PageID, page.DiskData);
     _cache.DirtyRecicleAction = () => Save();
 }
Exemplo n.º 14
0
 internal TransactionService(IDiskService disk, AesEncryption crypto, PageService pager, int cacheSize, Logger log)
 {
     _disk = disk;
     _crypto = crypto;
     _pager = pager;
     _cacheSize = cacheSize;
     _log = log;
 }
Exemplo n.º 15
0
 internal LockService(IDiskService disk, CacheService cache, TimeSpan timeout, LoggerWrap log)
 {
     _disk    = disk;
     _cache   = cache;
     _log     = log;
     _timeout = timeout;
     _state   = LockState.Unlocked;
 }
Exemplo n.º 16
0
 internal TransactionService(IDiskService disk, PageService pager, CacheService cache)
 {
     _disk = disk;
     _pager = pager;
     _cache = cache;
     _cache.MarkAsDirtyAction = (page) => _disk.WriteJournal(page.PageID, page.DiskData);
     _cache.DirtyRecicleAction = () => this.Save();
 }
Exemplo n.º 17
0
 internal TransactionService(IDiskService disk, AesEncryption crypto, PageService pager, int cacheSize, Logger log)
 {
     _disk      = disk;
     _crypto    = crypto;
     _pager     = pager;
     _cacheSize = cacheSize;
     _log       = log;
 }
 protected SynchronizationService(IFileSystem fileSystem, UserDto user, SynchronizationCallbacks callbacks, IDiskService diskServiceClient)
 {
     _fileSystem = fileSystem;
     _user = user;
     _callbacks = callbacks;
     _lock = _fileSystem.GetReadWriteLock();
     _diskService = diskServiceClient;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Starts LiteDB database using full parameters
 /// </summary>
 public LiteDatabase(IDiskService diskService)
 {
     this.InitializeMapper();
     _engine = new LazyLoad <DbEngine>(
         () => new DbEngine(diskService, _log),
         () => this.InitializeMapper(),
         () => this.InitializeDbVersion());
 }
 public ConfigurationReader(
     IDiskService diskService,
     IFileValidator fileValidator,
     IStringValidator stringValidator)
 {
     _diskService     = diskService;
     _fileValidator   = fileValidator;
     _stringValidator = stringValidator;
 }
Exemplo n.º 21
0
 public EnvWriter(
     IDiskService diskService,
     IStringValidator stringValidator,
     IObjectValidator objectValidator)
 {
     _diskService     = diskService;
     _stringValidator = stringValidator;
     _objectValidator = objectValidator;
 }
Exemplo n.º 22
0
        public DiskBrowserViewModel(IDiskService diskService, UserDto user)
        {
            if (diskService == null) throw new ArgumentNullException("diskService");
            if (user == null) throw new ArgumentNullException("user");

            _disks = new ObservableCollection<DiskDto>(diskService.Disks(user));

            SelectItemCommand = new Command(SelectItem, o => SelectedDisk != null);
        }
Exemplo n.º 23
0
        public MasterRepository(IGitHubService gitHubService, IGitService gitService, IDiskService diskService, string dataPath)
        {
            this.RepositoryDataDirectory       = Path.Combine(dataPath, "repositories");
            this.TaskRepositoriesDataDirectory = Path.Combine(RepositoryDataDirectory, "tasks");
            this.MasterRepositoryDirectory     = Path.Combine(this.RepositoryDataDirectory, "master");

            this.gitHubService = gitHubService;
            this.gitService    = gitService;
            this.diskService   = diskService;
        }
Exemplo n.º 24
0
        public ProductService(IProductRepository productRepository, IDiskService diskServices, IUnitOfWork unitOfWork, ILogServices logService, IOptions <AppSettings> appSettings)
        {
            _productRepository = productRepository;

            _diskServices = diskServices;


            _unitOfWork  = unitOfWork;
            _logService  = logService;
            _appSettings = appSettings;
        }
Exemplo n.º 25
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, Logger 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));
        }
Exemplo n.º 26
0
 public ProfileReader(
     IDiskService diskService,
     IFileValidator fileValidator,
     IStringValidator stringValidator,
     IObjectValidator objectValidator)
 {
     _diskService     = diskService;
     _fileValidator   = fileValidator;
     _stringValidator = stringValidator;
     _objectValidator = objectValidator;
 }
Exemplo n.º 27
0
        public void Init()
        {
            _validatorsMock = new Mock <IValidators>();
            _fileSystemMock = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { ValidFilePath, new MockFileData(FileContent) },
            });

            _sut = new Environmentalist.Services.DiskService.DiskService(
                _fileSystemMock,
                _validatorsMock.Object);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Reduce disk size re-arranging unused spaces. Can change password. If temporary disk was not provided, use MemoryStream temp disk
        /// </summary>
        public long Shrink(string password = null, IDiskService temp = null)
        {
            var originalSize = _disk.FileLength;

            // if temp disk are not passed, use memory stream disk
            temp = temp ?? new StreamDiskService(new MemoryStream());

            using (_locker.Reserved())
                using (_locker.Exclusive())
                    using (var engine = new LiteEngine(temp, password))
                    {
                        // read all collection
                        foreach (var collectionName in this.GetCollectionNames())
                        {
                            // first create all user indexes (exclude _id index)
                            foreach (var index in this.GetIndexes(collectionName).Where(x => x.Field != "_id"))
                            {
                                engine.EnsureIndex(collectionName, index.Field, index.Unique);
                            }

                            // now copy documents
                            var docs = this.Find(collectionName, Query.All());

                            engine.InsertBulk(collectionName, docs);
                        }

                        // copy user version
                        engine.UserVersion = this.UserVersion;

                        // set current disk size to exact new disk usage
                        _disk.SetLength(temp.FileLength);

                        // read new header page to start copy
                        var header = BasePage.ReadPage(temp.ReadPage(0)) as HeaderPage;

                        // copy (as is) all pages from temp disk to original disk
                        for (uint i = 0; i <= header.LastPageID; i++)
                        {
                            var page = temp.ReadPage(i);

                            _disk.WritePage(i, page);
                        }

                        // create/destroy crypto class
                        _crypto = password == null ? null : new AesEncryption(password, header.Salt);

                        // initialize all services again (crypto can be changed)
                        this.InitializeServices();

                        // return how many bytes are reduced
                        return(originalSize - temp.FileLength);
                    }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Reduce disk size re-arranging unused spaces. Can change password. If temporary disk was not provided, use MemoryStream temp disk
        /// </summary>
        public long Shrink(string password = null, IDiskService temp = null)
        {
            var originalSize = _disk.FileLength;

            // if temp disk are not passed, use memory stream disk
            temp = temp ?? new StreamDiskService(new MemoryStream());

            using(_locker.Write())
            using (var engine = new LiteEngine(temp, password))
            {
                // read all collection
                foreach (var collectionName in this.GetCollectionNames())
                {
                    // first create all user indexes (exclude _id index)
                    foreach (var index in this.GetIndexes(collectionName).Where(x => x.Field != "_id"))
                    {
                        engine.EnsureIndex(collectionName, index.Field, index.Unique);
                    }

                    // copy all docs
                    engine.Insert(collectionName, this.Find(collectionName, Query.All()));
                }

                // copy user version
                engine.UserVersion = this.UserVersion;

                // set current disk size to exact new disk usage
                _disk.SetLength(temp.FileLength);

                // read new header page to start copy
                var header = BasePage.ReadPage(temp.ReadPage(0)) as HeaderPage;

                // copy (as is) all pages from temp disk to original disk
                for (uint i = 0; i <= header.LastPageID; i++)
                {
                    var page = temp.ReadPage(i);

                    _disk.WritePage(i, page);
                }

                // create/destroy crypto class
                _crypto = password == null ? null : new AesEncryption(password, header.Salt);

                // initialize all services again (crypto can be changed)
                this.InitializeServices();
            }

            // return how many bytes are reduced
            return originalSize - temp.FileLength;
        }
Exemplo n.º 30
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();

            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;
            }
        }
Exemplo n.º 31
0
        protected Database(IDiskService service, string password = null, BsonMapper mapper = null)
        {
            if (mapper == null)
            {
                mapper = new BsonMapper {
                    SerializeNullValues = true
                };
                mapper.UseCamelCase();
            }

            this.DiskService  = service;
            this.LiteDatabase = new LiteDatabase(this.DiskService, mapper, password);

            // ReSharper disable once VirtualMemberCallInConstructor
            this.Initialize();
        }
 public Pbkdf2Repository(
     IPbkdf2Service pbkdF2Service,
     IEnvironmentVariableReader environmentVariableReader,
     IFileSystem fileSystem,
     IDiskService diskService,
     IFileValidator fileValidator,
     IStringValidator stringValidator,
     IObjectValidator objectValidator)
 {
     _pbkdF2Service             = pbkdF2Service;
     _environmentVariableReader = environmentVariableReader;
     _fileSystem      = fileSystem;
     _diskService     = diskService;
     _fileValidator   = fileValidator;
     _stringValidator = stringValidator;
     _objectValidator = objectValidator;
 }
Exemplo n.º 33
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();
            }
        }
Exemplo n.º 34
0
        public DbEngine(IDiskService disk, Logger log)
        {
            // initialize disk service and check if database exists
            var isNew = disk.Initialize();

            // new database? create new datafile
            if (isNew)
            {
                disk.CreateNew();
            }

            _log  = log;
            _disk = disk;

            // initialize all services
            _cache       = new CacheService();
            _pager       = new PageService(_disk, _cache);
            _indexer     = new IndexService(_pager);
            _data        = new DataService(_pager);
            _collections = new CollectionService(_pager, _indexer, _data);
            _transaction = new TransactionService(_disk, _pager, _cache);
        }
Exemplo n.º 35
0
        public DbEngine(IDiskService disk, Logger log)
        {
            // initialize disk service and check if database exists
            var isNew = disk.Initialize();

            // new database? just create header page and save it
            if (isNew)
            {
                disk.WritePage(0, new HeaderPage().WritePage());
            }

            _log  = log;
            _disk = disk;

            // initialize all services
            _cache       = new CacheService();
            _pager       = new PageService(_disk, _cache);
            _indexer     = new IndexService(_pager);
            _data        = new DataService(_pager);
            _collections = new CollectionService(_pager, _indexer, _data);
            _transaction = new TransactionService(_disk, _pager, _cache);

            // check user verion
        }
 public SynchronizationServiceMock(IFileSystem fileSystem, UserDto user, SynchronizationCallbacks callbacks, IDiskService diskService)
     : base(fileSystem, user, callbacks, diskService)
 {
 }
Exemplo n.º 37
0
 public TorLiteDatabase(IDiskService diskService, BsonMapper mapper = null)
     : base(diskService, mapper)
 {
 }
        private void Dispose(bool disposing)
        {
            // If you need thread safety, use a lock around these
            // operations, as well as in your methods that use the resource.

            if (!disposing) return;

            // free managed resources

            if (_diskService != null)
            {
                var service = _diskService as DiskServiceClient;
                if (service != null) service.Close();

                _diskService = null;
            }
        }
Exemplo n.º 39
0
 public PageService(IDiskService disk, /*AesEncryption crypto,*/ Logger log)
 {
     _disk = disk;
     //_crypto = crypto;
     _log = log;
 }
Exemplo n.º 40
0
        public MainViewModel(IUnityContainer container)
        {
            _container = container;
            Items = new ObservableCollection<ListItem>();
            SearchOption = new SearchOption { CaseSensitive = false, Recursive = true, Keyword = "", Global = false };

            OpenVfsCommand = new Command(OpenVfs, p => _manipulator == null);
            NewVfsCommand = new Command(NewVfs, p => _manipulator == null);
            CloseVfsCommand = new Command(CloseVfs, p => _manipulator != null);
            NewFolderCommand = new Command(NewFolder, p => (_manipulator != null));
            OpenCommand = new Command(Open, p => (_manipulator != null && p != null));
            RenameCommand = new Command(Rename, IsItemSelected);
            ImportFileCommand = new Command(ImportFile, p => (_manipulator != null));
            ImportFolderCommand = new Command(ImportFolder, p => (_manipulator != null));
            ExportCommand = new Command(Export, IsItemSelected);
            DeleteCommand = new Command(Delete, IsItemSelected);
            MoveCommand = new Command(Move, IsItemSelected);
            CopyCommand = new Command(Copy, IsItemSelected);
            PasteCommand = new Command(Paste, p => (_manipulator != null && _clipboard.Count > 0));
            SearchCommand = new Command(Search, p => (_manipulator != null));
            CancelSearchCommand = new Command(CancelSearch, p => (_manipulator != null));
            DiskInfoCommand = new Command(DiskInfo, p => (_manipulator != null));
            SwitchToVersionCommand = new Command(SwitchToVersion, p => (_manipulator != null));
            RollBackToVersionCommand = new Command(RollBackToVersion, p => (_manipulator != null));
            SwitchToLatestVersionCommand = new Command(SwitchToLatestVersion, p => (_manipulator != null));

            LoginCommand = new Command(Login, p => (_user == null));
            LogoutCommand = new Command(Logout, p => (_user != null));
            RegisterCommand = new Command(Register, p => (_user == null));
            LinkDiskCommand = new Command(LinkDisk, p => (_manipulator == null && _user != null));
            SwitchToOnlineModeCommand = new Command(SwitchToOnlineMode, p => (_manipulator != null && _user != null && _synchronization == null));
            SwitchToOfflineModeCommand = new Command(SwitchToOfflineMode, p => (_manipulator != null && _user != null && _synchronization != null));

            DropCommand = new Command(Drop, null);

            _diskService = new DiskServiceClient();
        }
Exemplo n.º 41
0
 public LiteDbModel(IDiskService diskService, BsonMapper mapper = null, string password = null,
                    TimeSpan?timeout = null, int cacheSize = 5000, Logger log = null) : base(diskService, mapper, password,
                                                                                             timeout, cacheSize, log)
 {
     AddReferences();
 }
Exemplo n.º 42
0
 public CacheService(IDiskService disk, Logger log)
 {
     _disk = disk;
     _log  = log;
 }