コード例 #1
0
        private async Task <IHttpActionResult> Handle(VerifyMatchMessage message)
        {
            Roster roster = DocumentSession.Load <Roster>(message.RosterId);

            if (roster.IsVerified && message.Force == false)
            {
                return(Ok());
            }
            WebsiteConfig websiteConfig = DocumentSession.Load <WebsiteConfig>(WebsiteConfig.GlobalId);
            HeadInfo      result        = await bitsClient.GetHeadInfo(roster.BitsMatchId);

            ParseHeaderResult header = BitsParser.ParseHeader(result, websiteConfig.ClubId);

            // chance to update roster values
            var update = new Roster.Update(
                Roster.ChangeType.VerifyMatchMessage,
                "system")
            {
                OilPattern = header.OilPattern,
                Date       = header.Date,
                Opponent   = header.Opponent,
                Location   = header.Location
            };

            if (roster.MatchResultId != null)
            {
                // update match result values
                BitsMatchResult bitsMatchResult = await bitsClient.GetBitsMatchResult(roster.BitsMatchId);

                Player[] players = DocumentSession.Query <Player, PlayerSearch>()
                                   .ToArray()
                                   .Where(x => x.PlayerItem?.LicNbr != null)
                                   .ToArray();
                var parser = new BitsParser(players);
                if (roster.IsFourPlayer)
                {
                    MatchResult4 matchResult = EventStoreSession.Load <MatchResult4>(roster.MatchResultId);
                    Parse4Result parseResult = parser.Parse4(bitsMatchResult, websiteConfig.ClubId);
                    update.Players = GetPlayerIds(parseResult);
                    bool isVerified = matchResult.Update(
                        PublishMessage,
                        roster,
                        parseResult.TeamScore,
                        parseResult.OpponentScore,
                        roster.BitsMatchId,
                        parseResult.CreateMatchSeries(),
                        players);
                    update.IsVerified = isVerified;
                }
                else
                {
                    MatchResult matchResult = EventStoreSession.Load <MatchResult>(roster.MatchResultId);
                    ParseResult parseResult = parser.Parse(bitsMatchResult, websiteConfig.ClubId);
                    update.Players = GetPlayerIds(parseResult);
                    var resultsForPlayer = DocumentSession.Query <ResultForPlayerIndex.Result, ResultForPlayerIndex>()
                                           .Where(x => x.Season == roster.Season)
                                           .ToArray()
                                           .ToDictionary(x => x.PlayerId);
                    MatchSerie[] matchSeries = parseResult.CreateMatchSeries();
                    bool         isVerified  = matchResult.Update(
                        PublishMessage,
                        roster,
                        parseResult.TeamScore,
                        parseResult.OpponentScore,
                        matchSeries,
                        parseResult.OpponentSeries,
                        players,
                        resultsForPlayer);
                    update.IsVerified = isVerified;
                }
            }

            roster.UpdateWith(Trace.CorrelationManager.ActivityId, update);
            return(Ok());
        }