Exemple #1
0
 public static void SaveReplay(DSReplayContext stcontext, DSReplay rep, bool bulk = false)
 {
     lock (stlockobject)
     {
         stcontext.DSReplays.Add(rep);
         if (bulk == false)
         {
             stcontext.SaveChanges();
         }
     }
 }
Exemple #2
0
        public static void DeleteRep(DSReplayContext stcontext, int id, bool bulk = false)
        {
            lock (stlockobject)
            {
                var replay = stcontext.DSReplays
                             .Include(o => o.Middle)
                             .Include(p => p.DSPlayer)
                             .ThenInclude(q => q.Breakpoints)
                             .FirstOrDefault(s => s.ID == id);

                if (replay.DSPlayer != null)
                {
                    foreach (DSPlayer pl in replay.DSPlayer)
                    {
                        if (pl.Breakpoints != null)
                        {
                            foreach (DbBreakpoint bp in pl.Breakpoints)
                            {
                                stcontext.Breakpoints.Remove(bp);
                            }
                        }
                        stcontext.DSPlayers.Remove(pl);
                    }
                }
                if (replay.Middle != null)
                {
                    foreach (DbMiddle mid in replay.Middle)
                    {
                        stcontext.Middle.Remove(mid);
                    }
                }
                stcontext.DSReplays.Remove(replay);
                if (bulk == false)
                {
                    stcontext.SaveChanges();
                }
            }
        }
Exemple #3
0
 public DBSearch(DSReplayContext context, IMemoryCache cache, ILogger <DBSearch> logger)
 {
     _context = context;
     _logger  = logger;
     _cache   = cache;
 }
Exemple #4
0
        public static IQueryable <DSReplay> Filter(DSoptions options, DSReplayContext context, bool isFiltered = false, IQueryable <DSReplay> ireps = null)
        {
            var replays = ireps;

            if (replays == null)
            {
                replays = context.DSReplays
                          .Include(p => p.DSPlayer)
                          .Where(x => x.WINNER >= 0)
                ;
            }



            HashSet <string> Gamemodes = options.Gamemodes.Where(x => x.Value == true).Select(y => y.Key).ToHashSet();

            IQueryable <DSReplay> filReplays;

            if (isFiltered == false)
            {
                if (String.IsNullOrEmpty(options.Interest))
                {
                    if (options.Leaver > 0)
                    {
                        filReplays = replays
                                     .Where(x => x.DURATION > options.Duration)
                                     .Where(x => x.MAXLEAVER < options.Leaver)
                                     .Where(x => x.MINARMY > options.Army)
                                     .Where(x => x.MININCOME > options.Income)
                                     .Where(x => x.MINKILLSUM > options.Kills)
                                     .Where(x => x.PLAYERCOUNT >= options.PlayerCount)
                                     .Where(x => Gamemodes.Contains(x.GAMEMODE))
                                     //.ToArray()
                        ;
                    }
                    else
                    {
                        filReplays = replays
                                     .Where(x => x.DURATION > options.Duration)
                                     .Where(x => x.MINARMY > options.Army)
                                     .Where(x => x.MININCOME > options.Income)
                                     .Where(x => x.MINKILLSUM > options.Kills)
                                     .Where(x => x.PLAYERCOUNT >= options.PlayerCount)
                                     .Where(x => Gamemodes.Contains(x.GAMEMODE))
                                     //.ToArray()
                        ;
                    }
                }
                else
                if (options.Leaver > 0)
                {
                    filReplays = replays
                                 .Where(x => x.DURATION > options.Duration)
                                 .Where(x => x.MAXLEAVER < options.Leaver)
                                 .Where(x => x.MINARMY > options.Army)
                                 .Where(x => x.MININCOME > options.Income)
                                 .Where(x => x.MINKILLSUM > options.Kills)
                                 .Where(x => x.PLAYERCOUNT >= options.PlayerCount)
                                 .Where(x => Gamemodes.Contains(x.GAMEMODE))
                                 .Where(x => x.DSPlayer.FirstOrDefault(s => s.RACE == options.Interest) != null)
                                 //.ToArray()
                    ;
                }
                else
                {
                    filReplays = replays
                                 .Where(x => x.DURATION > options.Duration)
                                 .Where(x => x.MINARMY > options.Army)
                                 .Where(x => x.MININCOME > options.Income)
                                 .Where(x => x.MINKILLSUM > options.Kills)
                                 .Where(x => x.PLAYERCOUNT >= options.PlayerCount)
                                 .Where(x => Gamemodes.Contains(x.GAMEMODE))
                                 .Where(x => x.DSPlayer.FirstOrDefault(s => s.RACE == options.Interest) != null)
                                 //.ToArray()
                    ;
                }
            }
            else
            {
                filReplays = replays;
            }

            if (options.Startdate != default(DateTime))
            {
                filReplays = filReplays.Where(x => x.GAMETIME >= options.Startdate);
            }
            if (options.Enddate != default(DateTime))
            {
                filReplays = filReplays.Where(x => x.GAMETIME <= options.Enddate.AddDays(1));
            }

            if (DSdata.IsMySQL)
            {
                if (options.MengskPreviewFilter)
                {
                    var testReplays = from r in filReplays
                                      from p in r.DSPlayer
                                      where p.RACE == "Mengsk" && r.GAMETIME < new DateTime(2020, 07, 28, 5, 23, 0)
                                      select r.ID;
                    filReplays = filReplays.Where(x => !testReplays.Contains(x.ID));
                }

                if (options.Dataset.Any())
                {
                    filReplays = filReplays
                                 .Where(x => x.DSPlayer.Select(s => s.NAME).Contains(options.Dataset.First()));
                }
            }
            return(filReplays);
        }
Exemple #5
0
 public DBService(DSReplayContext context, ILogger <DBService> logger)
 {
     _context = context;
     _logger  = logger;
 }