コード例 #1
0
ファイル: BuildService.cs プロジェクト: stopdraft/sc2dsstats
        public static async Task GetBuild(DSoptions _options, DSReplayContext _context, object dblock, ILogger _logger)
        {
            if (_options.Vs == "ALL")
            {
                _options.Vs = String.Empty;
            }
            string Hash = _options.GenHash();

            if (!_options.Decoding && BuildCache.ContainsKey(Hash))
            {
                _options.buildResult = BuildCache[Hash];
                return;
            }

            bool doWait = false;

            lock (Computing)
            {
                if (!Computing.Contains(Hash))
                {
                    Computing.Add(Hash);
                }
                else
                {
                    doWait = true;
                }
            }

            if (doWait)
            {
                while (Computing.Contains(Hash))
                {
                    await Task.Delay(500);
                }
                if (BuildCache.ContainsKey(Hash))
                {
                    _options.buildResult = BuildCache[Hash];
                }
                return;
            }

            BuildResult bresult = new BuildResult();

            foreach (var ent in _options.Gamemodes.Keys.ToArray())
            {
                _options.Gamemodes[ent] = false;
            }

            if (_options.Interest == "Terran" || _options.Interest == "Zerg" || _options.Interest == "Protoss")
            {
                _options.Gamemodes["GameModeStandard"] = true;
            }
            else
            {
                _options.Gamemodes["GameModeCommanders"]       = true;
                _options.Gamemodes["GameModeCommandersHeroic"] = true;
            }

            lock (dblock)
            {
                bool mengskfilter = _options.MengskPreviewFilter;
                _options.MengskPreviewFilter = false;
                var replays = DBReplayFilter.Filter(_options, _context);
                _options.MengskPreviewFilter = mengskfilter;

                bresult.TotalGames = replays.Count();

                var presult = (String.IsNullOrEmpty(_options.Vs) switch
                {
                    true => from r in replays
                    from t1 in r.DSPlayer
                    where t1.RACE == _options.Interest
                    where _options.Dataset.Contains(t1.NAME)
                    from u1 in t1.Breakpoints
                    where u1.Breakpoint == _options.Breakpoint
                    select new
                    {
                        r.ID,
                        r.DURATION,
                        r.GAMETIME,
                        t1.WIN,
                        u1.dsUnitsString,
                        u1.Upgrades,
                        u1.Gas
                    },
                    false => from r in replays
                    from t1 in r.DSPlayer
                    where t1.RACE == _options.Interest && t1.OPPRACE == _options.Vs
                    where _options.Dataset.Contains(t1.NAME)
                    from u1 in t1.Breakpoints
                    where u1.Breakpoint == _options.Breakpoint
                    select new
                    {
                        r.ID,
                        r.DURATION,
                        r.GAMETIME,
                        t1.WIN,
                        u1.dsUnitsString,
                        u1.Upgrades,
                        u1.Gas
                    }
                });