Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, StatsDbContext context)
        {
            context.Seed();

            app.UseHttpsRedirection();
            app.UseRouting();
        }
Esempio n. 2
0
        public static StatsDbContext Stats(IServiceProvider x, bool beginTrans = true)
        {
            var config  = new StandardEfDbConfig(x.GetRequiredService <IConfiguration>(), DatabaseConnectionStringNames.Stats);
            var builder = new SqlServerDbContextOptionsBuilder(config, x.GetRequiredService <ILoggerFactory>());
            var result  = new StatsDbContext(builder.Build());

            if (beginTrans)
            {
                result.BeginTransaction();
            }
            return(result);
        }
 /// <summary>
 /// This method saves the initial set of data to the database before we begin parsing.
 /// This is done to ensure I have the raw match data saved in case I encounter bad data during a parse.
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="text"></param>
 private void SaveMatchBeforeParsing(string fileName, string text)
 {
     logger.Info("Saving initial match details");
     using (var db = new StatsDbContext())
     {
         db.Match.Add(new Match()
         {
             MatchId = fileName, MatchType = "", MapName = "", MatchText = text, Date = MatchResults.MatchDate
         });
         db.SaveChanges();
     }
 }
 public DatabaseProvisioner(DbProvisionLoggingExtensions logger,
                            WorkflowDbContext workflowDbContext,
                            ContentDbContext contentDbContext,
                            EksPublishingJobDbContext eksPublishingJobDbContext,
                            DataProtectionKeysDbContext dataProtectionKeysDbContext,
                            StatsDbContext statsDbContext,
                            DkSourceDbContext dkSourceDbContext,
                            IksInDbContext iksInDbContext,
                            IksOutDbContext iksOutDbContext,
                            IksPublishingJobDbContext iksPublishingJobDbContext)
 {
     _Logger                      = logger ?? throw new ArgumentNullException(nameof(logger));
     _WorkflowDbContext           = workflowDbContext ?? throw new ArgumentNullException(nameof(workflowDbContext));
     _ContentDbContext            = contentDbContext ?? throw new ArgumentNullException(nameof(contentDbContext));
     _EksPublishingJobDbContext   = eksPublishingJobDbContext ?? throw new ArgumentNullException(nameof(eksPublishingJobDbContext));
     _DataProtectionKeysDbContext = dataProtectionKeysDbContext ?? throw new ArgumentNullException(nameof(dataProtectionKeysDbContext));
     _StatsDbContext              = statsDbContext ?? throw new ArgumentNullException(nameof(statsDbContext));
     _DkSourceDbContext           = dkSourceDbContext ?? throw new ArgumentNullException(nameof(dkSourceDbContext));
     _IksInDbContext              = iksInDbContext ?? throw new ArgumentNullException(nameof(iksInDbContext));
     _IksOutDbContext             = iksOutDbContext ?? throw new ArgumentNullException(nameof(iksOutDbContext));
     _IksPublishingJobDbContext   = iksPublishingJobDbContext ?? throw new ArgumentNullException(nameof(iksPublishingJobDbContext));
 }
Esempio n. 5
0
 protected Repository(StatsDbContext context)
 {
     _context = context;
 }
 public GameRepository(StatsDbContext context) : base(context)
 {
 }
Esempio n. 7
0
 public TeamRepository(StatsDbContext context) : base(context)
 {
 }
        /// <summary>
        /// Once all the match data is parsed this method begins inserting into the database.
        /// </summary>
        private void PersistMatchData()
        {
            logger.Info("Saving all data to database");
            using (var db = new StatsDbContext())
            {
                /*
                 * We saved the initial match data in the SaveBeforeParsing method.
                 * let's finish saving the match details now that we've parsed the data.
                 */

                // find the match by the matchId
                var match = db.Match
                            .Where(b => b.MatchId == MatchResults.MatchId)
                            .FirstOrDefault();
                match.MatchType      = MatchResults.MatchType;
                match.MapName        = MatchResults.MapName;
                match.MatchTimeLimit = MatchResults.MatchTimeLimit.ConvertToInt();
                db.SaveChanges();

                // Save each individual team stats.
                foreach (KeyValuePair <string, MatchTeamStatDTO> teamEntry in MatchResults.ListOfTeams)
                {
                    var newMatchTeamStat = new MatchTeamStats()
                    {
                        MatchId               = match.Id,
                        TeamColor             = teamEntry.Value.TeamColor,
                        TeamVerdict           = teamEntry.Value.TeamVerdict,
                        TeamTotalFrags        = teamEntry.Value.TeamTotalFrags.ConvertToInt(),
                        TeamTotalQuads        = teamEntry.Value.TeamTotalQuads.ConvertToInt(),
                        TeamTotalPents        = teamEntry.Value.TeamTotalPents.ConvertToInt(),
                        TeamTotalEyes         = teamEntry.Value.TeamTotalEyes.ConvertToInt(),
                        TeamTotalRL           = teamEntry.Value.TeamTotalRL.ConvertToInt(),
                        TeamTotalLG           = teamEntry.Value.TeamTotalLG.ConvertToInt(),
                        TeamTotalGL           = teamEntry.Value.TeamTotalGL.ConvertToInt(),
                        TeamTotalSNG          = teamEntry.Value.TeamTotalSNG.ConvertToInt(),
                        TeamTotalNG           = teamEntry.Value.TeamTotalNG.ConvertToInt(),
                        TeamTotalMH           = teamEntry.Value.TeamTotalMH.ConvertToInt(),
                        TeamTotalRA           = teamEntry.Value.TeamTotalRA.ConvertToInt(),
                        TeamTotalYA           = teamEntry.Value.TeamTotalYA.ConvertToInt(),
                        TeamTotalGA           = teamEntry.Value.TeamTotalGA.ConvertToInt(),
                        TeamPlusRLPack        = teamEntry.Value.TeamPlusRLPack.Trim(),
                        TeamMinusRLPack       = teamEntry.Value.TeamMinusRLPack.Trim(),
                        TeamControlPercentage = teamEntry.Value.TeamControlPercentage.ConvertEfficiency(),
                    };
                    db.MatchTeamStats.Add(newMatchTeamStat);
                    db.SaveChanges();
                }

                // add all player detailed stats
                foreach (KeyValuePair <string, MatchPlayerDTO> playerEntry in MatchResults.ListOfPlayers)
                {
                    var playerId = playerEntry.Key.ConvertToInt();
                    var mpStats  = new MatchPlayerStats();

                    // Because I'm setting every unique non logged in player to an int < 0 in the dictionary, I basically check if this user is logged in.
                    // Of course this could be handled more elagantly with a proper object but time is limited at the moment.
                    // if the player in this entry is logged in
                    if (playerId > 0)
                    {
                        // let's test that the player id is actually a user in the database since we could have an ID in config but not in the database.
                        var playerInDatabase = db.Player
                                               .Where(x => x.Id == playerId)
                                               .FirstOrDefault();

                        // if the player id isn't found in the database throw exception.
                        if (playerInDatabase == null)
                        {
                            throw new Exception("PlayerId: " + playerId + " was deemed logged in but player was not found in the database. Please check id exists.");
                        }

                        // let's make sure the player it found wasn't the unknown player for whatever reason.
                        if (playerId != 999 && playerId > 0)
                        {
                            // populate team stats
                            mpStats.KillEfficiency   = playerEntry.Value.KillEfficiency.ConvertEfficiency();
                            mpStats.WeaponEfficiency = playerEntry.Value.WeaponEfficiency.ConvertEfficiency();
                            // populate quad stats
                            mpStats.NumberOfQuads     = playerEntry.Value.NumberOfQuads.ConvertToInt();
                            mpStats.QuadEfficiency    = playerEntry.Value.QuadEfficiency.ConvertEfficiency();
                            mpStats.NumQuadEnemyKills = playerEntry.Value.NumQuadEnemyKills.ConvertToInt();
                            mpStats.NumQuadSelfKills  = playerEntry.Value.NumQuadSelfKills.ConvertToInt();
                            mpStats.NumQuadTeamKills  = playerEntry.Value.NumQuadTeamKills.ConvertToInt();
                            // populate kill stats
                            mpStats.NumOfFrags      = playerEntry.Value.NumOfFrags.ConvertToInt();
                            mpStats.NumOfEnemyKills = playerEntry.Value.NumOfEnemyKills.ConvertToInt();
                            mpStats.NumOfSelfKills  = playerEntry.Value.NumOfSelfKills.ConvertToInt();
                            mpStats.NumOfTeamKills  = playerEntry.Value.NumOfTeamKills.ConvertToInt();
                            mpStats.NumOfDeaths     = playerEntry.Value.NumOfDeaths.ConvertToInt();
                            // populate efficiency stats
                            mpStats.BulletEfficiency    = playerEntry.Value.BulletEfficiency.ConvertEfficiency();
                            mpStats.NailsEfficiency     = playerEntry.Value.NailsEfficiency.ConvertEfficiency();
                            mpStats.RocketEfficiency    = playerEntry.Value.RocketEfficiency.ConvertEfficiency();
                            mpStats.LightningEfficiency = playerEntry.Value.LightningEfficiency.ConvertEfficiency();
                            mpStats.TotalEfficiency     = playerEntry.Value.TotalEfficiency.ConvertEfficiency();
                            // populate bad stats
                            mpStats.DroppedPaks = playerEntry.Value.DroppedPaks.ConvertToInt();
                            mpStats.SelfDamage  = playerEntry.Value.SelfDamage.ConvertEfficiency();
                            mpStats.TeamDamage  = playerEntry.Value.TeamDamage.ConvertEfficiency();
                        }
                        else
                        {
                            throw new Exception("Some how the query for playerId: " + playerId + " came back as 999");
                        }
                    }
                    else
                    {
                        // set id to unknown player
                        playerId = 999;
                    }

                    // Tracking Info
                    mpStats.MatchId   = match.Id;
                    mpStats.PlayerId  = playerId;
                    mpStats.TeamColor = playerEntry.Value.TeamColor;
                    db.MatchPlayerStats.Add(mpStats);
                    db.SaveChanges();
                }
            }
        }
Esempio n. 9
0
 public MiniAppService(StatsDbContext dbContext, IMemoryCache memoryCache)
 {
     this.dbContext   = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     this.memoryCache = memoryCache ?? throw new ArgumentNullException(nameof(memoryCache));
 }
Esempio n. 10
0
 public StatsService(IConfiguration configuration, IMapper mapper, StatsDbContext dbContext)
 {
     this.configuration = configuration;
     this.mapper        = mapper;
     this.dbContext     = dbContext;
 }
Esempio n. 11
0
 public WeighInMgmtSvc(StatsDbContext context)
 {
     _context = context;
 }
Esempio n. 12
0
 public StatisticsService(IHttpClientFactory clientFactory, StatsDbContext context)
 {
     _clientFactory = clientFactory;
     _context       = context;
 }
Esempio n. 13
0
 public IdentityService(IConfiguration configuration, StatsDbContext dbContext)
 {
     this.configuration = configuration;
     this.dbContext     = dbContext;
 }
Esempio n. 14
0
 public StatisticsDbWriter(StatsDbContext dbContext, IUtcDateTimeProvider dtp)
 {
     _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _dtp       = dtp ?? throw new ArgumentNullException(nameof(dtp));
 }
Esempio n. 15
0
 public TeamService(StatsDbContext context, IMapper mapper)
 {
     this.context = context;
     this.mapper  = mapper;
 }
Esempio n. 16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dbContext"></param>
 public AdminController(StatsDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Esempio n. 17
0
 public IndexModel(IConfiguration configuration, StatsDbContext dbContext) : base(dbContext)
 {
     this.configuration = configuration;
 }
Esempio n. 18
0
 public HomeController(StatsDbContext statsDbContext)
 {
     this.statsDbContext = statsDbContext;
 }
Esempio n. 19
0
        protected override void Seed(StatsDbContext context)
        {
            var p1 = new Player {
                FirstName = "Kevin", LastName = "Pietersen", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };
            var p2 = new Player {
                FirstName = "Aaron", LastName = "Finch", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };
            var p3 = new Player {
                FirstName = "Chris", LastName = "Lyn", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };
            var p4 = new Player {
                FirstName = "Johan", LastName = "Botha", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };
            var p5 = new Player {
                FirstName = "Cameron", LastName = "White", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };
            var p6 = new Player {
                FirstName = "George", LastName = "Bailey", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };
            var p7 = new Player {
                FirstName = "Brad", LastName = "Haddin", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };
            var p8 = new Player {
                FirstName = "James", LastName = "Hopes", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };
            var p9 = new Player {
                FirstName = "Yasir", LastName = "Arafat", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };
            var p10 = new Player {
                FirstName = "Usman", LastName = "Khawaja", CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };

            var t1 = new Team {
                Name = "Melbourne Stars", CreatedDate = DateTime.Now, Players = new List <Player> {
                    p1, p5
                }, UpdatedDate = DateTime.Now
            };
            var t2 = new Team {
                Name = "Melbourne Renegades", CreatedDate = DateTime.Now, Players = new List <Player> {
                    p2
                }, UpdatedDate = DateTime.Now
            };
            var t3 = new Team {
                Name = "Adelaide Strikers", CreatedDate = DateTime.Now, Players = new List <Player> {
                    p4
                }, UpdatedDate = DateTime.Now
            };
            var t4 = new Team {
                Name = "Brisbane Heat", CreatedDate = DateTime.Now, Players = new List <Player> {
                    p3, p8
                }, UpdatedDate = DateTime.Now
            };
            var t5 = new Team {
                Name = "Sydney Sixers", CreatedDate = DateTime.Now, Players = new List <Player> {
                    p7
                }, UpdatedDate = DateTime.Now
            };
            var t6 = new Team {
                Name = "Hobart Hurricanes", CreatedDate = DateTime.Now, Players = new List <Player> {
                    p6
                }, UpdatedDate = DateTime.Now
            };
            var t7 = new Team {
                Name = "Perth Scorchers", CreatedDate = DateTime.Now, Players = new List <Player> {
                    p10
                }, UpdatedDate = DateTime.Now
            };
            var t8 = new Team {
                Name = "Sydney Thunder", CreatedDate = DateTime.Now, Players = new List <Player> {
                    p9
                }, UpdatedDate = DateTime.Now
            };


            p1.Team = t1;
            p2.Team = t2;
            p3.Team = t4;
            p4.Team = t3;
            p5.Team = t1;
            p6.Team = t6;
            p7.Team = t5;
            p8.Team = t4;
            //p9.Team = t7;
            //p10.Team = t8;

            var game = new Game {
                AwayTeam = t1, HomeTeam = t2, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now, StartTime = DateTime.Now
            };

            context.Players.AddOrUpdate(p1);
            context.Players.AddOrUpdate(p2);
            context.Players.AddOrUpdate(p3);
            context.Players.AddOrUpdate(p4);
            context.Players.AddOrUpdate(p5);
            context.Players.AddOrUpdate(p6);
            context.Players.AddOrUpdate(p7);
            context.Players.AddOrUpdate(p8);
            //context.Players.AddOrUpdate(p9);
            //context.Players.AddOrUpdate(p10);

            context.Teams.AddOrUpdate(t1);
            context.Teams.AddOrUpdate(t2);
            context.Teams.AddOrUpdate(t3);
            context.Teams.AddOrUpdate(t4);
            context.Teams.AddOrUpdate(t5);
            context.Teams.AddOrUpdate(t6);
            context.Teams.AddOrUpdate(t7);
            context.Teams.AddOrUpdate(t8);

            context.Games.AddOrUpdate(game);
        }
 public EventRepository(StatsDbContext context) : base(context)
 {
 }
Esempio n. 21
0
 public IndexModel(StatsDbContext dbContext) : base(dbContext)
 {
 }
Esempio n. 22
0
 public PlayerRepository(StatsDbContext context) : base(context)
 {
 }
Esempio n. 23
0
 public ReferenceService(StatsDbContext context, IMapper mapper)
 {
     this.context = context;
     this.mapper  = mapper;
 }