Ejemplo n.º 1
0
            public async Task Handle(ReOpenDatabaseQuery message)
            {
                if (_database.IsOpen)
                {
                    throw new DatabaseOpenException();
                }
                if (string.IsNullOrEmpty(_database.FileAccessToken))
                {
                    throw new DatabaseClosedException();
                }

                var file = await _file.ReadBinaryFile(_database.FileAccessToken);

                await _database.ReOpen(file);
            }
Ejemplo n.º 2
0
            public async Task Handle(SaveDatabaseCommand message)
            {
                if (!_database.IsOpen)
                {
                    throw new DatabaseClosedException();
                }

                try
                {
                    var timeToSave = Stopwatch.StartNew();
                    if (!string.IsNullOrEmpty(message.FilePath))
                    {
                        _database.FileAccessToken = message.FilePath;
                    }

                    var contents = await _database.SaveDatabase();

                    // Test DB integrity
                    _database.CloseDatabase();
                    await _database.ReOpen(contents);

                    // Transactional write to file
                    await _file.WriteBinaryContentsToFile(_database.FileAccessToken, contents);

                    timeToSave.Stop();

                    _logger.LogTrace("SaveCommand", new Dictionary <string, string>
                    {
                        { "duration", timeToSave.ElapsedMilliseconds.ToString() },
                        { "size", _database.Size.ToString() }
                    });
                }
                catch (Exception exception)
                {
                    throw new SaveException(exception);
                }
            }