Example #1
0
        public DatabaseFixture()
        {
            Secret       = "KeGPyghP5CSoSwPpzkBvKG2k";
            InstanceName = "Hawkeye";

            DbContextOptions <ExilenceContext> options;
            var builder = new DbContextOptionsBuilder <ExilenceContext>();

            builder.UseInMemoryDatabase("Exilence");
            options = builder.Options;

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AccountProfileMapper());
                cfg.AddProfile(new CharacterProfileMapper());
                cfg.AddProfile(new ConnectionProfileMapper());
                cfg.AddProfile(new GroupProfileMapper());
                cfg.AddProfile(new LeagueProfileMapper());
                cfg.AddProfile(new PricedItemProfileMapper());
                cfg.AddProfile(new SnapshotProfileMapper());
                cfg.AddProfile(new SnapshotProfileProfileMapper());
                cfg.AddProfile(new StashtabProfileMapper());
            });
            var mapper = mockMapper.CreateMapper();

            var context = new ExilenceContext(options);

            var accountRepository  = new AccountRepository(context);
            var snapshotRepository = new SnapshotRepository(context);
            var groupRepository    = new GroupRepository(context);

            AccountService  = new AccountService(snapshotRepository, accountRepository, mapper);
            SnapshotService = new SnapshotService(snapshotRepository, accountRepository, mapper);
            GroupService    = new GroupService(groupRepository, accountRepository, mapper);
        }
 public SnapshotRepository(ExilenceContext context)
 {
     _exilenceContext = context;
 }
Example #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IConfiguration configuration, ExilenceContext exilenceContext, ILogger <Startup> logger)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHub <BaseHub>("/hub");
            });

            var instanceName = configuration.GetSection("Settings")["InstanceName"];


            logger.LogInformation("Removing dead connections.");
            //Remove faulty connections to this node on startup if node crasched
            exilenceContext.Database.ExecuteSqlRaw($"DELETE FROM Connections WHERE InstanceName = '{instanceName}'");

            logger.LogInformation("Removing dead groups.");
            //Remove groups with no connections after connection cleanup
            exilenceContext.Database.ExecuteSqlRaw($"DELETE FROM Groups WHERE Id IN (SELECT g.Id FROM Groups g WHERE (SELECT COUNT(*) FROM Connections WHERE GroupId = g.Id) = 0)");

            //Apply mongo migrations on start if neeeded
            var migrationResult = MongoMigrationHandler.Run(configuration.GetSection("ConnectionStrings")["Mongo"], configuration.GetSection("Mongo")["Database"]);

            foreach (var migration in migrationResult.InterimSteps)
            {
                logger.LogInformation($"Applied migration version: {migration.TargetVersion} and name: {migration.MigrationName} to database: {migration.DatabaseName} on host: {migration.ServerAdress}");
            }
            if (migrationResult.InterimSteps.Count() == 0)
            {
                logger.LogInformation($"No pending migrations found. Using MongoDB {migrationResult.DatabaseName} on {migrationResult.ServerAdress} version: {migrationResult.CurrentVersion}.");
            }
        }
 public AccountRepository(ExilenceContext context)
 {
     _exilenceContext = context;
 }
Example #5
0
 public GroupRepository(ExilenceContext context)
 {
     _exilenceContext = context;
 }
Example #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IConfiguration configuration, ExilenceContext exilenceContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHub <BaseHub>("/hub");
            });

            var instanceName = configuration.GetSection("Settings")["InstanceName"];

            //Remove faulty connections to this node on startup if node crasched
            exilenceContext.Database.ExecuteSqlRaw($"DELETE FROM Connections WHERE InstanceName = '{instanceName}'");
            //Remove groups with no connections after connection cleanup
            exilenceContext.Database.ExecuteSqlRaw($"DELETE FROM Groups WHERE Id IN (SELECT g.Id FROM Groups g WHERE (SELECT COUNT(*) FROM Connections WHERE GroupId = g.Id) = 0)");
        }