public IEnumerable <ReplayMatchPlayerScoreResult> ReadTopRecords(int amount)
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayMatchPlayerScoreResults.AsNoTracking().Take(amount).ToList());
     }
 }
Exemple #2
0
 public IEnumerable <ReplayRenamedPlayer> ReadLastRecords(int amount)
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayRenamedPlayers.AsNoTracking().OrderByDescending(x => x.RenamedPlayerId).Take(amount).ToList());
     }
 }
Exemple #3
0
 public IEnumerable <ReplayRenamedPlayer> ReadTopRecords(int amount)
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayRenamedPlayers.AsNoTracking().Take(amount).ToList());
     }
 }
Exemple #4
0
        /// <summary>
        /// Returns the Replay along all the other ReplayMatch models
        /// </summary>
        /// <param name="replayId">Replay Id</param>
        /// <returns>Replay</returns>
        public ReplayMatch ReadReplayIncludeAssociatedRecords(long replayId)
        {
            ReplayMatch replayMatch = new ReplayMatch();

            using (var db = new ReplaysContext())
            {
                replayMatch = db.Replays.AsNoTracking().Where(x => x.ReplayId == replayId)
                              .Include(x => x.ReplayMatchPlayers)
                              .Include(x => x.ReplayMatchPlayerTalents)
                              .Include(x => x.ReplayMatchTeamBan)
                              .Include(x => x.ReplayMatchPlayerScoreResults)
                              .Include(x => x.ReplayMatchMessage)
                              .Include(x => x.ReplayMatchAward)
                              .Include(x => x.ReplayMatchTeamLevels)
                              .Include(x => x.ReplayMatchTeamExperiences)
                              .FirstOrDefault();

                if (replayMatch == null)
                {
                    return(null);
                }
            }

            return(replayMatch);
        }
Exemple #5
0
        internal override long CreateRecord(ReplaysContext db, ReplayRenamedPlayer model)
        {
            db.ReplayRenamedPlayers.Add(model);
            db.SaveChanges();

            return(model.RenamedPlayerId);
        }
Exemple #6
0
 public List <ReplayMatch> ReadLatestReplaysByDateTimeList(int amount)
 {
     using (var db = new ReplaysContext())
     {
         return(db.Replays.AsNoTracking().OrderByDescending(x => x.TimeStamp).Take(amount).ToList());
     }
 }
Exemple #7
0
 public long ReadReplayIdByHash(ReplayMatch model)
 {
     using (var db = new ReplaysContext())
     {
         return(db.Replays.AsNoTracking().SingleOrDefault(x => x.Hash == model.Hash).ReplayId);
     }
 }
 public IEnumerable <ReplayHotsLogsUpload> ReadLastRecords(int amount)
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayHotsLogsUploads.AsNoTracking().OrderByDescending(x => x.ReplayId).Take(amount).ToList());
     }
 }
 public IEnumerable <ReplayHotsLogsUpload> ReadTopRecords(int amount)
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayHotsLogsUploads.AsNoTracking().Take(amount).ToList());
     }
 }
Exemple #10
0
 public ReplayAllHotsPlayer ReadRecordFromPlayerId(long playerId)
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayAllHotsPlayers.AsNoTracking().Where(x => x.PlayerId == playerId).FirstOrDefault());
     }
 }
 public IEnumerable <ReplayHotsLogsUpload> ReadAllRecords()
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayHotsLogsUploads.AsNoTracking().ToList());
     }
 }
Exemple #12
0
 internal long ReadPlayerIdFromBattleNetId(ReplaysContext db, int battleNetId, int battleNetRegionId, int battleNetSubId)
 {
     // battleNetId is not unique, player can change their battletag and their battleNetId stays the same
     return(db.ReplayAllHotsPlayers.AsNoTracking().FirstOrDefault(x => x.BattleNetId == battleNetId &&
                                                                  x.BattleNetRegionId == battleNetRegionId &&
                                                                  x.BattleNetSubId == battleNetSubId).PlayerId);
 }
 /// <summary>
 /// Reads the current status of the given ReplayHotsLogsUpload.  Call IsExistingRecord() to ensure record exists.
 /// </summary>
 /// <param name="replayHotsLogsUpload"></param>
 /// <returns></returns>
 public int?ReadUploadStatus(ReplayHotsLogsUpload replayHotsLogsUpload)
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayHotsLogsUploads.AsNoTracking().SingleOrDefault(x => x.ReplayId == replayHotsLogsUpload.ReplayId).Status);
     }
 }
        internal override long CreateRecord(ReplaysContext db, ReplayMatchPlayerScoreResult model)
        {
            db.ReplayMatchPlayerScoreResults.Add(model);
            db.SaveChanges();

            return(model.MatchPlayerScoreResultId);
        }
        internal void SetPlayerPartyCountsForMatch(ReplaysContext db, long replayId)
        {
            var query = (from mp in db.ReplayMatchPlayers
                         where mp.ReplayId == replayId && mp.PartyValue != 0
                         group mp by new
            {
                mp.ReplayId,
                mp.PartyValue,
            }
                         into grp
                         where grp.Count() > 0
                         let partySize = grp.Count()
                                         select new
            {
                grp.Key.ReplayId,
                grp.Key.PartyValue,
                PartySize = partySize,
            }).Distinct();

            foreach (var item in query)
            {
                var matchPlayers = db.ReplayMatchPlayers.Where(x => x.ReplayId == item.ReplayId && x.PartyValue == item.PartyValue);
                foreach (var player in matchPlayers)
                {
                    player.PartySize = item.PartySize;
                }
            }

            db.SaveChanges();
        }
 public bool IsExistingRecord(ReplayHotsLogsUpload replayHotsLogsUpload)
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayHotsLogsUploads.AsNoTracking().Any(x => x.ReplayId == replayHotsLogsUpload.ReplayId));
     }
 }
        public IEnumerable <ReplayMatchPlayer> ReadRecordsWhere(string columnName, string operand, string input)
        {
            if (string.IsNullOrEmpty(columnName) || string.IsNullOrEmpty(operand))
            {
                return(new List <ReplayMatchPlayer>());
            }

            if (columnName.Contains("Is"))
            {
                if (input.ToUpperInvariant() == "TRUE")
                {
                    input = "1";
                }
                else if (input.ToUpperInvariant() == "FALSE")
                {
                    input = "0";
                }
            }
            else if (LikeOperatorInputCheck(operand, input))
            {
                input = $"%{input}%";
            }
            else if (input == null)
            {
                input = string.Empty;
            }

            using (var db = new ReplaysContext())
            {
                return(db.ReplayMatchPlayers.SqlQuery($"SELECT * FROM ReplayMatchPlayers WHERE {columnName} {operand} @Input", new SQLiteParameter("@Input", input)).AsNoTracking().ToList());
            }
        }
Exemple #18
0
        /// <summary>
        /// Gets the score results for a hero on a particular map.
        /// </summary>
        /// <param name="character">Hero name.</param>
        /// <param name="season">Selected season.</param>
        /// <param name="gameMode">Selected GameMode.</param>
        /// <param name="mapName">Selected map.</param>
        /// <returns></returns>
        public List <ReplayMatchPlayerScoreResult> ReadScoreResult(string character, Season season, GameMode gameMode, string mapName)
        {
            var replayBuild = HeroesHelpers.Builds.GetReplayBuildsFromSeason(season);
            List <ReplayMatchPlayerScoreResult> list = new List <ReplayMatchPlayerScoreResult>();

            using (var db = new ReplaysContext())
            {
                db.Configuration.AutoDetectChangesEnabled = false;

                foreach (Enum value in Enum.GetValues(gameMode.GetType()))
                {
                    if ((GameMode)value != GameMode.Unknown && gameMode.HasFlag(value))
                    {
                        var query = from r in db.Replays.AsNoTracking()
                                    join mp in db.ReplayMatchPlayers.AsNoTracking() on r.ReplayId equals mp.ReplayId
                                    join mpsr in db.ReplayMatchPlayerScoreResults.AsNoTracking() on new { mp.ReplayId, mp.PlayerId } equals new { mpsr.ReplayId, mpsr.PlayerId }
                        where mp.PlayerId == UserSettings.UserPlayerId &&
                        mp.Character == character &&
                        r.GameMode == (GameMode)value &&
                        r.ReplayBuild >= replayBuild.Item1 && r.ReplayBuild < replayBuild.Item2 &&
                        r.MapName == mapName
                        select mpsr;

                        list.AddRange(query.ToList());
                    }
                }

                return(list);
            }
        }
Exemple #19
0
 public List <ReplayMatch> ReadNewestLatestReplayByDateTimeList(DateTime?dateTime)
 {
     using (var db = new ReplaysContext())
     {
         return(db.Replays.AsNoTracking().OrderBy(x => x.TimeStamp).Where(x => x.TimeStamp > dateTime).ToList());
     }
 }
Exemple #20
0
        public TimeSpan ReadTotalMapGameTime(string character, Season season, GameMode gameMode, string mapName)
        {
            var replayBuild = HeroesHelpers.Builds.GetReplayBuildsFromSeason(season);

            using (var db = new ReplaysContext())
            {
                db.Configuration.AutoDetectChangesEnabled = false;

                var gameModeFilter = PredicateBuilder.New <ReplayMatch>();
                foreach (Enum value in Enum.GetValues(gameMode.GetType()))
                {
                    if ((GameMode)value != GameMode.Unknown && gameMode.HasFlag(value))
                    {
                        Enum temp = value;
                        gameModeFilter = gameModeFilter.Or(x => x.GameMode == (GameMode)temp);
                    }
                }

                var query = from mp in db.ReplayMatchPlayers.AsNoTracking()
                            join r in db.Replays.AsNoTracking() on mp.ReplayId equals r.ReplayId
                            where mp.PlayerId == UserSettings.UserPlayerId &&
                            mp.Character == character &&
                            r.ReplayBuild >= replayBuild.Item1 && r.ReplayBuild < replayBuild.Item2 &&
                            r.MapName == mapName
                            select r;

                query = query.AsExpandable().Where(gameModeFilter);

                return(TimeSpan.FromTicks(query.Count() > 0 ? query.Sum(x => x.ReplayLengthTicks) : 0));
            }
        }
Exemple #21
0
 public long GetTotalReplayCount()
 {
     using (var db = new ReplaysContext())
     {
         return(db.Replays.Count());
     }
 }
Exemple #22
0
        public int ReadMatchAwardCountForHero(string character, Season season, GameMode gameMode, List <string> maps, string mvpAwardType)
        {
            var replayBuild = HeroesHelpers.Builds.GetReplayBuildsFromSeason(season);

            using (var db = new ReplaysContext())
            {
                db.Configuration.AutoDetectChangesEnabled = false;

                var mapFilter = PredicateBuilder.New <ReplayMatch>();
                foreach (var map in maps)
                {
                    string temp = map;
                    mapFilter = mapFilter.Or(x => x.MapName == temp);
                }

                var query = from r in db.Replays.AsNoTracking()
                            join mp in db.ReplayMatchPlayers.AsNoTracking() on r.ReplayId equals mp.ReplayId
                            join ma in db.ReplayMatchAwards.AsNoTracking() on new { mp.ReplayId, mp.PlayerId } equals new { ma.ReplayId, ma.PlayerId }
                where mp.PlayerId == UserSettings.UserPlayerId &&
                mp.Character == character &&
                r.GameMode == gameMode &&
                r.ReplayBuild >= replayBuild.Item1 && r.ReplayBuild < replayBuild.Item2 &&
                ma.Award == mvpAwardType
                select r;
                query = query.AsExpandable().Where(mapFilter);

                return(query.Count());
            }
        }
Exemple #23
0
        internal override long CreateRecord(ReplaysContext db, ReplayMatch model)
        {
            db.Replays.Add(model);
            db.SaveChanges();

            return(model.ReplayId);
        }
Exemple #24
0
        /// <summary>
        /// Gets the total count of wins or losses for a map.
        /// </summary>
        /// <param name="season">Selected season.</param>
        /// <param name="gameMode">Selected GameMode (multiple).</param>
        /// <param name="isWins">Return wins if true otherwise return losses.</param>
        /// <param name="mapName">Selected map.</param>
        /// <returns></returns>
        public int ReadMapResults(Season season, GameMode gameMode, bool isWins, string mapName)
        {
            var replayBuild = HeroesHelpers.Builds.GetReplayBuildsFromSeason(season);
            int total       = 0;

            using (var db = new ReplaysContext())
            {
                db.Configuration.AutoDetectChangesEnabled = false;

                foreach (Enum value in Enum.GetValues(gameMode.GetType()))
                {
                    if (gameMode.HasFlag(value))
                    {
                        var query = from mp in db.ReplayMatchPlayers.AsNoTracking()
                                    join r in db.Replays.AsNoTracking() on mp.ReplayId equals r.ReplayId
                                    where mp.PlayerId == UserSettings.UserPlayerId &&
                                    mp.IsWinner == isWins &&
                                    r.GameMode == (GameMode)value &&
                                    r.ReplayBuild >= replayBuild.Item1 && r.ReplayBuild < replayBuild.Item2 &&
                                    r.MapName == mapName
                                    select mp.IsWinner;

                        total += query.Count();
                    }
                }

                return(total);
            }
        }
Exemple #25
0
 public IEnumerable <ReplayRenamedPlayer> ReadAllRecords()
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayRenamedPlayers.AsNoTracking().ToList());
     }
 }
Exemple #26
0
        public List <ReplayMatchPlayer> ReadListOfMatchPlayerHeroes(Season season, GameMode gameMode)
        {
            var replayBuild = HeroesHelpers.Builds.GetReplayBuildsFromSeason(season);
            var list        = new List <ReplayMatchPlayer>();

            using (var db = new ReplaysContext())
            {
                db.Configuration.AutoDetectChangesEnabled = false;

                foreach (Enum value in Enum.GetValues(gameMode.GetType()))
                {
                    if (gameMode.HasFlag(value))
                    {
                        var query = from mp in db.ReplayMatchPlayers.AsNoTracking()
                                    join r in db.Replays.AsNoTracking() on mp.ReplayId equals r.ReplayId
                                    where mp.PlayerId == UserSettings.UserPlayerId &&
                                    r.GameMode == (GameMode)value &&
                                    r.ReplayBuild >= replayBuild.Item1 && r.ReplayBuild < replayBuild.Item2
                                    select mp;

                        list.AddRange(query.ToList());
                    }
                }

                return(list);
            }
        }
Exemple #27
0
        public IEnumerable <ReplayRenamedPlayer> ReadRecordsWhere(string columnName, string operand, string input)
        {
            if (string.IsNullOrEmpty(columnName) || string.IsNullOrEmpty(operand))
            {
                return(new List <ReplayRenamedPlayer>());
            }

            if (columnName.Contains("TimeStamp"))
            {
                if (TimeSpan.TryParse(input, out TimeSpan timeSpan))
                {
                    input      = timeSpan.Ticks.ToString();
                    columnName = string.Concat(columnName, "Ticks");
                }
                else
                {
                    return(new List <ReplayRenamedPlayer>());
                }
            }
            else if (LikeOperatorInputCheck(operand, input))
            {
                input = $"%{input}%";
            }
            else if (input == null)
            {
                input = string.Empty;
            }

            using (var db = new ReplaysContext())
            {
                return(db.ReplayRenamedPlayers.SqlQuery($"SELECT * FROM ReplayRenamedPlayers WHERE {columnName} {operand} @Input", new SQLiteParameter("@Input", input)).AsNoTracking().ToList());
            }
        }
Exemple #28
0
        /// <summary>
        /// Gets the total count of wins or losses for given hero.
        /// </summary>
        /// <param name="character">Hero name.</param>
        /// <param name="season">Selected season.</param>
        /// <param name="gameMode">Selected GameMode (only one).</param>
        /// <param name="isWins">Return wins if true otherwise return losses.</param>
        /// <returns></returns>
        public int ReadGameResults(string character, Season season, GameMode gameMode, bool isWins)
        {
            var replayBuild = HeroesHelpers.Builds.GetReplayBuildsFromSeason(season);

            using (var db = new ReplaysContext())
            {
                db.Configuration.AutoDetectChangesEnabled = false;

                var gameModeFilter = PredicateBuilder.New <ReplayMatch>();
                foreach (Enum value in Enum.GetValues(gameMode.GetType()))
                {
                    if ((GameMode)value != GameMode.Unknown && gameMode.HasFlag(value))
                    {
                        Enum temp = value;
                        gameModeFilter = gameModeFilter.Or(x => x.GameMode == (GameMode)temp);
                    }
                }

                var query = from mp in db.ReplayMatchPlayers.AsNoTracking()
                            join r in db.Replays.AsNoTracking() on mp.ReplayId equals r.ReplayId
                            where mp.PlayerId == UserSettings.UserPlayerId &&
                            mp.Character == character &&
                            mp.IsWinner == isWins &&
                            r.ReplayBuild >= replayBuild.Item1 && r.ReplayBuild < replayBuild.Item2
                            select r;

                query = query.AsExpandable().Where(gameModeFilter);

                return(query.Count());
            }
        }
Exemple #29
0
 public List <string> ReadPlayersFromPlayerId(long playerId)
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayRenamedPlayers.AsNoTracking().Where(x => x.PlayerId == playerId).Select(x => x.BattleTagName).ToList());
     }
 }
 public IEnumerable <ReplayMatchPlayerScoreResult> ReadLastRecords(int amount)
 {
     using (var db = new ReplaysContext())
     {
         return(db.ReplayMatchPlayerScoreResults.AsNoTracking().OrderByDescending(x => x.ReplayId).Take(amount).ToList());
     }
 }