public static async Task Initialize(WriteDatabaseConfiguration configuration) { await _semaphore.WaitAsync(); try { var databaseFilePath = Path.Combine(configuration.DirectoryPath, configuration.FileName); var encryptionService = new EncryptionService(new SecuredText(configuration.EncryptionKey)); var databaseContext = new FileDatabaseContext(databaseFilePath, encryptionService); databaseContext.Initialize(); using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await AddApplicationSettings(databaseContext); await AddTextureConverterSettings(databaseContext); await AddUsageStatistics(databaseContext); if (databaseContext.Games.IsNullOrEmpty()) { var gameRepository = new GameRepository(databaseContext); foreach (GameType gameType in Enum.GetValues(typeof(GameType))) { try { await AddGame(gameType, gameRepository); } catch (GameTemplateNotFoundException) { } } var gameId = ((GameType)typeof(GameType).GetDefaultValue().GetValueOrDefault()).GetAggregateId(); var game = databaseContext.Games.SingleOrDefault(entity => entity.Id == gameId); if (game == null) { throw new AggregateRootNotFoundException($"game with id: {gameId} could not be found"); } await gameRepository.ChangeGameProfileAsync(game.Profiles.First().Id); } transaction.Complete(); } DatabaseContext = databaseContext; } finally { _semaphore.Release(); } }
private static async Task AddApplicationSettings(FileDatabaseContext context) { var repository = new ApplicationSettingsRepository(context); try { await repository.LoadAsync(); } catch (AggregateRootNotFoundException) { await repository.SaveAsync(new ApplicationSettingsFactory().Create()); } }
public TextureManagementSettingsRepository(FileDatabaseContext context) { _context = context; }
public ApplicationSettingsRepository(FileDatabaseContext context) { _context = context; }
public GameRepository(FileDatabaseContext context) { _context = context; }
public UsageStatisticsRepository(FileDatabaseContext context) { _context = context; }