public static Databases SetUpRepositories(ILogger logger, BaseConfig baseConfig)
        {
            IClock clock = SystemClock.Instance;

            CustomSerializers.RegisterAll();
            IMongoClient   mongoClient             = new MongoClient(baseConfig.MongoDbConnectionUri);
            IMongoDatabase mongoDatabase           = mongoClient.GetDatabase(baseConfig.MongoDbDatabaseName);
            IMongoDatabase mongoDatabaseMessagelog = mongoClient.GetDatabase(baseConfig.MongoDbDatabaseNameMessagelog);
            UserRepo       userRepo = new(
                database : mongoDatabase,
                startingPokeyen : baseConfig.StartingPokeyen,
                startingTokens : baseConfig.StartingTokens,
                defaultOperators : baseConfig.Chat.DefaultOperatorNames);
            IMongoBadgeLogRepo badgeLogRepo = new BadgeLogRepo(mongoDatabase);
            IBadgeRepo         badgeRepo    = new BadgeRepo(mongoDatabase, badgeLogRepo, clock);

            badgeRepo.UserLostBadgeSpecies += (_, args) => TaskToVoidSafely(logger, () =>
                                                                            userRepo.UnselectBadgeIfSpeciesSelected(args.UserId, args.Species));
            IBank <User> pokeyenBank = new Bank <User>(
                database: mongoDatabase,
                currencyCollectionName: UserRepo.CollectionName,
                transactionLogCollectionName: "pokeyentransactions",
                u => u.Pokeyen,
                u => u.Id,
                clock: clock);
            IBank <User> tokenBank = new Bank <User>(
                database: mongoDatabase,
                currencyCollectionName: UserRepo.CollectionName,
                transactionLogCollectionName: "tokentransactions",
                u => u.Tokens,
                u => u.Id,
                clock: clock);

            tokenBank.AddReservedMoneyChecker(
                new PersistedReservedMoneyCheckers(mongoDatabase).AllDatabaseReservedTokens);
            return(new Databases
                   (
                       UserRepo: userRepo,
                       BadgeRepo: badgeRepo,
                       PollRepo: new PollRepo(mongoDatabase, clock),
                       PokeyenBank: pokeyenBank,
                       TokensBank: tokenBank,
                       CommandLogger: new CommandLogger(mongoDatabase, clock),
                       MessagequeueRepo: new MessagequeueRepo(mongoDatabase),
                       MessagelogRepo: new MessagelogRepo(mongoDatabaseMessagelog),
                       LinkedAccountRepo: new LinkedAccountRepo(mongoDatabase, userRepo.Collection),
                       SubscriptionLogRepo: new SubscriptionLogRepo(mongoDatabase),
                       ModLogRepo: new ModLogRepo(mongoDatabase),
                       ResponseCommandRepo: new ResponseCommandRepo(mongoDatabase)
                   ));
        }
Exemple #2
0
        public static Databases SetUpRepositories(BaseConfig baseConfig)
        {
            IClock clock = SystemClock.Instance;

            CustomSerializers.RegisterAll();
            IMongoClient   mongoClient             = new MongoClient(baseConfig.MongoDbConnectionUri);
            IMongoDatabase mongoDatabase           = mongoClient.GetDatabase(baseConfig.MongoDbDatabaseName);
            IMongoDatabase mongoDatabaseMessagelog = mongoClient.GetDatabase(baseConfig.MongoDbDatabaseNameMessagelog);
            IUserRepo      userRepo = new UserRepo(
                database: mongoDatabase,
                startingPokeyen: baseConfig.StartingPokeyen,
                startingTokens: baseConfig.StartingTokens);
            IMongoBadgeLogRepo badgeLogRepo = new BadgeLogRepo(mongoDatabase);
            IBadgeRepo         badgeRepo    = new BadgeRepo(mongoDatabase, badgeLogRepo, clock);

            badgeRepo.UserLostBadgeSpecies += async(_, args) =>
                                              await userRepo.UnselectBadgeIfSpeciesSelected(args.UserId, args.Species);

            IBank <User> pokeyenBank = new Bank <User>(
                database: mongoDatabase,
                currencyCollectionName: UserRepo.CollectionName,
                transactionLogCollectionName: "pokeyentransactions",
                u => u.Pokeyen,
                u => u.Id,
                clock: clock);
            IBank <User> tokenBank = new Bank <User>(
                database: mongoDatabase,
                currencyCollectionName: UserRepo.CollectionName,
                transactionLogCollectionName: "tokentransactions",
                u => u.Tokens,
                u => u.Id,
                clock: clock);

            tokenBank.AddReservedMoneyChecker(
                new PersistedReservedMoneyCheckers(mongoDatabase).AllDatabaseReservedTokens);
            return(new Databases
                   (
                       UserRepo: userRepo,
                       BadgeRepo: badgeRepo,
                       PokeyenBank: pokeyenBank,
                       TokensBank: tokenBank,
                       CommandLogger: new CommandLogger(mongoDatabase, clock),
                       MessagequeueRepo: new MessagequeueRepo(mongoDatabase),
                       MessagelogRepo: new MessagelogRepo(mongoDatabaseMessagelog)
                   ));
        }