Exemplo n.º 1
0
        public static int ScanNG()
        {
            List <DSReplay> DSReplays = new List <DSReplay>();

            foreach (var dir in Directory.GetFiles(DSdata.ServerConfig.SumDir1))
            {
                DSReplays.AddRange(DataService.ReadJson(dir));
            }

            int c = DSReplays.Count;

            DSReplays = DataService.FindDups(DSReplays);
            Console.WriteLine("New Replays found: " + c);
            Console.WriteLine("Insert Replays: " + DSReplays.Count);



            int i = 0;

            using (var context = new DSReplayContext(Program._opt))
            {
                foreach (DSReplay rep in DSReplays)
                {
                    i++;
                    DBService.SaveReplay(context, rep, true);
                    if (i % 100 == 0)
                    {
                        context.SaveChanges();
                    }
                }
                context.SaveChanges();
            }

            return(DSReplays.Count);
        }
Exemplo n.º 2
0
 public static void Delete(HashSet <int> DeleteMe)
 {
     using (var context = new DSReplayContext(Program._opt))
     {
         int i = 0;
         foreach (int id in DeleteMe)
         {
             DBService.DeleteRep(context, id, true);
             i++;
             if (i % 100 == 0)
             {
                 context.SaveChanges();
             }
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
        public static HashSet <int> CheckDups(Dictionary <int, List <int> > CompareMe)
        {
            HashSet <int> DeleteMe = new HashSet <int>();
            int           i        = 0;
            int           c        = CompareMe.Count;

            using (var context = new DSReplayContext(Program._opt))
            {
                foreach (int id in CompareMe.Keys)
                {
                    i++;
                    if (i % 100 == 0)
                    {
                        Program.logger.LogInformation($"{i}/{c}");
                    }

                    if (DeleteMe.Contains(id))
                    {
                        continue;
                    }



                    DSReplay replay = context.DSReplays.First(s => s.ID == id);

                    foreach (int cid in CompareMe[id])
                    {
                        if (DeleteMe.Contains(cid))
                        {
                            continue;
                        }
                        DSReplay crep          = context.DSReplays.First(s => s.ID == cid);
                        int      isDupPossible = 0;

                        if (replay.REPLAY == crep.REPLAY)
                        {
                            if (new Version(replay.VERSION) >= new Version(crep.VERSION))
                            {
                                DeleteMe.Add(crep.ID);
                            }
                            else
                            {
                                DeleteMe.Add(replay.ID);
                            }
                            continue;
                        }

                        if (replay.VERSION == crep.VERSION)
                        {
                            if (replay.MAXKILLSUM == crep.MAXKILLSUM)
                            {
                                isDupPossible++;
                            }
                            if (replay.MAXLEAVER == crep.MAXLEAVER)
                            {
                                isDupPossible++;
                            }
                            if (replay.MININCOME == crep.MININCOME)
                            {
                                isDupPossible++;
                            }
                            if (replay.MINARMY == crep.MINARMY)
                            {
                                isDupPossible++;
                            }
                        }
                        else
                        {
                            int kdiff = Math.Abs(replay.MAXKILLSUM - crep.MAXKILLSUM);
                            //int adiff = Math.Abs(rep.MINARMY - crep.MINARMY);
                            int mdiff = Math.Abs(replay.MINKILLSUM - crep.MINKILLSUM);
                            int ddiff = Math.Abs(replay.DURATION - crep.DURATION);

                            if (ddiff == 0 || (kdiff < 1000 && mdiff < 1000))
                            {
                                isDupPossible = 4;
                            }
                        }

                        if (isDupPossible > 2)
                        {
                            replay = context.DSReplays
                                     .Include(p => p.DSPlayer)
                                     .Single(s => s.ID == id);
                            crep = context.DSReplays
                                   .Include(p => p.DSPlayer)
                                   .Single(s => s.ID == cid);

                            if (new Version(replay.VERSION) > new Version(crep.VERSION))
                            {
                                foreach (var ent in crep.DSPlayer.Select(s => new { s.NAME, s.REALPOS }))
                                {
                                    try
                                    {
                                        if (ent.NAME.Length == 64 && replay.DSPlayer.Single(x => x.REALPOS == ent.REALPOS).NAME.Length < 64)
                                        {
                                            replay.DSPlayer.Single(x => x.REALPOS == ent.REALPOS).NAME = ent.NAME;
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Program.logger.LogInformation($"No RealPos Player found {e.Message}: {replay.ID}");
                                    }
                                }
                                DeleteMe.Add(crep.ID);
                            }
                            else
                            {
                                foreach (var ent in replay.DSPlayer.Select(s => new { s.NAME, s.REALPOS }))
                                {
                                    try
                                    {
                                        if (ent.NAME.Length == 64 && crep.DSPlayer.Single(x => x.REALPOS == ent.REALPOS).NAME.Length < 64)
                                        {
                                            crep.DSPlayer.Single(x => x.REALPOS == ent.REALPOS).NAME = ent.NAME;
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Program.logger.LogInformation($"No RealPos Player found {e.Message}: {crep.ID}");
                                    }
                                }
                                DeleteMe.Add(replay.ID);
                            }
                            context.SaveChanges();
                        }
                    }
                }
            }
            return(DeleteMe);
        }
Exemplo n.º 4
0
        public static List <DSReplay> InsertReplays()
        {
            List <DSReplay> NewDbReps = new List <DSReplay>();
            List <DSReplay> Dups      = new List <DSReplay>();

            using (var context = new DSReplayContext(Program._opt))
            {
                var Replays = context.DSReplays.Include(p => p.DSPlayer);
                foreach (dsreplay replay in sReplays.ToArray())
                {
                    //DSReplay crep = context.DSReplays
                    //    .Include(p => p.DSPlayer)
                    //    .FirstOrDefault(s => s.HASH == replay.HASH);



                    DSReplay crep = Replays.FirstOrDefault(s => s.HASH == replay.HASH);
                    if (crep != null)
                    {
                        if (new Version(replay.VERSION) > new Version(crep.VERSION))
                        {
                            foreach (var ent in crep.DSPlayer.Select(s => new { s.NAME, s.REALPOS }))
                            {
                                try
                                {
                                    if (ent.NAME.Length == 64 && replay.PLAYERS.Single(x => x.REALPOS == ent.REALPOS).NAME.Length < 64)
                                    {
                                        replay.PLAYERS.Single(x => x.REALPOS == ent.REALPOS).NAME = ent.NAME;
                                    }
                                }
                                catch
                                {
                                    Console.WriteLine("???");
                                }
                            }
                            DBService.DeleteRep(context, crep.ID);
                        }
                        else
                        {
                            int i = 0;
                            foreach (var ent in replay.PLAYERS.Select(s => new { s.NAME, s.REALPOS }))
                            {
                                try
                                {
                                    if (ent.NAME.Length == 64 && crep.DSPlayer.Single(x => x.REALPOS == ent.REALPOS).NAME.Length < 64)
                                    {
                                        i++;
                                        crep.DSPlayer.Single(x => x.REALPOS == ent.REALPOS).NAME = ent.NAME;
                                    }
                                }
                                catch
                                {
                                    Console.WriteLine(":(");
                                }
                            }
                            if (i > 0)
                            {
                                context.SaveChanges();
                            }
                            sReplays.Remove(replay);
                        }
                    }
                }

                int j = 0;
                foreach (dsreplay rep in sReplays)
                {
                    DSReplay newdbrep = Map.Rep(rep);
                    newdbrep.REPLAYPATH = "";
                    DBService.SaveReplay(context, newdbrep, true);
                    NewDbReps.Add(newdbrep);
                    j++;
                    if (j % 100 == 0)
                    {
                        context.SaveChanges();
                        Console.WriteLine($"{j}/{sReplays.Count}");
                    }
                }
                context.SaveChanges();
            }

            return(NewDbReps);
        }
Exemplo n.º 5
0
        public static List <DSReplay> InsertDSReplays(List <DSReplay> replays)
        {
            List <DSReplay> NewDbReps = new List <DSReplay>();
            List <DSReplay> Dups      = new List <DSReplay>();

            using (var context = new DSReplayContext(Program._opt))
            {
                var Replays = context.DSReplays.Include(p => p.DSPlayer);
                foreach (DSReplay replay in replays.ToArray())
                {
                    if (replay.MINARMY == 0 && replay.MINKILLSUM == 0 && replay.MAXKILLSUM == 0 && replay.DURATION < 120)
                    {
                        replays.Remove(replay);
                        continue;
                    }
                    //DSReplay crep = context.DSReplays
                    //    .Include(p => p.DSPlayer)
                    //    .FirstOrDefault(s => s.HASH == replay.HASH);
                    DSReplay crep = Replays.FirstOrDefault(s => s.HASH == replay.HASH);
                    if (crep != null)
                    {
                        if (new Version(replay.VERSION) > new Version(crep.VERSION))
                        {
                            foreach (var ent in crep.DSPlayer.Select(s => new { s.NAME, s.REALPOS }))
                            {
                                try
                                {
                                    if (ent.NAME.Length == 64 && replay.DSPlayer.Single(x => x.REALPOS == ent.REALPOS).NAME.Length < 64)
                                    {
                                        replay.DSPlayer.Single(x => x.REALPOS == ent.REALPOS).NAME = ent.NAME;
                                    }
                                }
                                catch (Exception e)
                                {
                                    Program.logger.LogInformation($"Error in finding RealPos {e.Message}");
                                }
                            }
                            DBService.DeleteRep(context, crep.ID);
                        }
                        else
                        {
                            int i = 0;
                            foreach (var ent in replay.DSPlayer.Select(s => new { s.NAME, s.REALPOS }))
                            {
                                try
                                {
                                    if (ent.NAME.Length == 64 && crep.DSPlayer.Single(x => x.REALPOS == ent.REALPOS).NAME.Length < 64)
                                    {
                                        i++;
                                        crep.DSPlayer.Single(x => x.REALPOS == ent.REALPOS).NAME = ent.NAME;
                                    }
                                }
                                catch (Exception e)
                                {
                                    Program.logger.LogInformation($"Error in finding RealPos {e.Message}");
                                }
                            }
                            if (i > 0)
                            {
                                context.SaveChanges();
                            }
                            replays.Remove(replay);
                        }
                    }
                    else
                    {
                        //Console.WriteLine("no dup");
                    }
                }

                int j = 0;
                foreach (DSReplay newdbrep in replays)
                {
                    newdbrep.REPLAYPATH = "";
                    DBService.SaveReplay(context, newdbrep, true);
                    NewDbReps.Add(newdbrep);
                    j++;
                    if (j % 100 == 0)
                    {
                        context.SaveChanges();
                        Program.logger.LogInformation($"{j}/{replays.Count}");
                    }
                }
                context.SaveChanges();
            }

            return(NewDbReps);
        }