public void Execute()
        {
            AddColumnToTable("Replays", "Hash", "TEXT NOT NULL DEFAULT ''");
            AddColumnToTable("ReplayAllHotsPlayers", "LastSeenBefore", "DATETIME");
            AddColumnToTable("ReplayMatchPlayers", "AccountLevel", "INTEGER NOT NULL DEFAULT 0");
            AddColumnToTable("ReplayAllHotsPlayers", "AccountLevel", "INTEGER NOT NULL DEFAULT 0");

            using (ReplaysContext db = new ReplaysContext())
            {
                var records = db.Replays.ToList();

                foreach (var record in records)
                {
                    record.Hash = ReplayHasher.HashReplay(record);
                }

                db.SaveChanges();
            }

            using (ReplaysContext db = new ReplaysContext())
            {
                var records = db.ReplayAllHotsPlayers.ToList();

                foreach (var record in records)
                {
                    record.LastSeenBefore = record.LastSeen;
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        // returns true if replay already exists in database
        private bool BasicData(string fileName)
        {
            string mapName = Replay.MapAlternativeName;

            if (string.IsNullOrEmpty(mapName))
            {
                mapName = Replay.Map;
            }

            Battleground battleground = HeroesIcons.Battlegrounds(Replay.ReplayBuild).Battleground(mapName);

            if (battleground == null)
            {
                throw new TranslationException(RetrieveAllMapAndHeroNames());
            }

            mapName = battleground.Name;
            mapName = MapVerification(mapName);

            ReplayMatch replayMatch = new ReplayMatch
            {
                Frames             = Replay.Frames,
                GameMode           = (Heroes.Helpers.GameMode)Replay.GameMode,
                GameSpeed          = Replay.GameSpeed.ToString(),
                IsGameEventsParsed = Replay.IsGameEventsParsedSuccessfully,
                MapName            = mapName,
                RandomValue        = Replay.RandomValue,
                ReplayBuild        = Replay.ReplayBuild,
                ReplayLength       = Replay.ReplayLength,
                ReplayVersion      = Replay.ReplayVersion,
                TeamSize           = Replay.TeamSize,
                TimeStamp          = Replay.Timestamp,
                FileName           = fileName,
            };

            replayMatch.Hash = ReplayHasher.HashReplay(replayMatch, GetPlayers());
            ReplayTimeStamp  = replayMatch.TimeStamp.Value;

            // check if replay was added to database already
            if (ReplaysDb.MatchReplay.IsExistingRecord(ReplaysContext, replayMatch))
            {
                ReplayId = ReplaysDb.MatchReplay.ReadReplayIdByHash(replayMatch);
                return(true);
            }
            else
            {
                ReplayId = ReplaysDb.MatchReplay.CreateRecord(ReplaysContext, replayMatch);
                return(false);
            }
        }
        // returns true if replay already exists in database
        private bool BasicData(string fileName)
        {
            if (!HeroesIcons.MapBackgrounds().MapNameTranslation(Replay.Map, out string mapName))
            {
                if (!AutoTranslateMapNameByMapObjectives(out mapName))
                {
                    throw new TranslationException(RetrieveAllMapAndHeroNames());
                }
            }

            ReplayMatch replayMatch = new ReplayMatch
            {
                Frames             = Replay.Frames,
                GameMode           = Replay.GameMode,
                GameSpeed          = Replay.GameSpeed.ToString(),
                IsGameEventsParsed = Replay.IsGameEventsParsedSuccessfully,
                MapName            = mapName,
                RandomValue        = Replay.RandomValue,
                ReplayBuild        = Replay.ReplayBuild,
                ReplayLength       = Replay.ReplayLength,
                ReplayVersion      = Replay.ReplayVersion,
                TeamSize           = Replay.TeamSize,
                TimeStamp          = Replay.Timestamp,
                FileName           = fileName,
            };

            replayMatch.Hash = ReplayHasher.HashReplay(replayMatch);
            ReplayTimeStamp  = replayMatch.TimeStamp.Value;

            // check if replay was added to database already
            if (ReplaysDb.MatchReplay.IsExistingRecord(ReplaysContext, replayMatch))
            {
                ReplayId = ReplaysDb.MatchReplay.ReadReplayIdByHash(replayMatch);
                return(true);
            }
            else
            {
                ReplayId = ReplaysDb.MatchReplay.CreateRecord(ReplaysContext, replayMatch);
                return(false);
            }
        }
        public void Execute()
        {
            using (ReplaysContext db = new ReplaysContext())
            {
                List <ReplayMatch> records = db.Replays
                                             .Include(x => x.ReplayMatchPlayers.Select(p => p.ReplayAllHotsPlayer))
                                             .ToList();

                foreach (ReplayMatch record in records)
                {
                    IEnumerable <Player> players = record.ReplayMatchPlayers.Select(x => new Player()
                    {
                        Character = x.Character,
                    });

                    record.Hash = ReplayHasher.HashReplay(record, players);
                }

                db.SaveChanges();
            }
        }