Esempio n. 1
0
    public async Task TestParseHeader(
        int bitsMatchId,
        int homeTeamId,
        DateTime date,
        string team,
        string opponent,
        int turn,
        string oilPatternName,
        string oilPatternUrl,
        string location)
    {
        // Arrange
        Web.Infrastructure.Bits.Contracts.HeadInfo content = await BitsGateway.GetHeadInfo(bitsMatchId);

        // Act
        ParseHeaderResult header = BitsParser.ParseHeader(content, homeTeamId);

        // Assert
        Assert.That(header.Date, Is.EqualTo(date));
        Assert.That(header.Team, Is.EqualTo(team));
        Assert.That(header.Opponent, Is.EqualTo(opponent));
        Assert.That(header.Turn, Is.EqualTo(turn));
        Assert.That(header.OilPattern.Name, Is.EqualTo(oilPatternName));
        Assert.That(header.OilPattern.Url, Is.EqualTo(oilPatternUrl));
        Assert.That(header.Location, Is.EqualTo(location));
    }
Esempio n. 2
0
        public async Task <ActionResult> CreateBitsVerify(VerifyBitsViewModel vm)
        {
            if (DocumentSession.Query <Roster, RosterSearchTerms>()
                .SingleOrDefault(x => x.BitsMatchId == vm.BitsMatchId) != null)
            {
                ModelState.AddModelError("BitsMatchId", "Matchen redan upplagd");
            }

            if (ModelState.IsValid == false)
            {
                return(View("CreateBits"));
            }

            int           season        = DocumentSession.LatestSeasonOrDefault(DateTime.Now.Year);
            WebsiteConfig websiteConfig = DocumentSession.Load <WebsiteConfig>(WebsiteConfig.GlobalId);

            Infrastructure.Bits.Contracts.HeadInfo content = await bitsClient.GetHeadInfo(vm.BitsMatchId);

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

            ViewBag.TeamNamesAndLevels = websiteConfig.TeamNamesAndLevels;
            return(View(
                       "Create", new CreateRosterViewModel
            {
                Season = season,
                Turn = header.Turn,
                BitsMatchId = vm.BitsMatchId,
                Team = header.Team,
                IsFourPlayer = false,
                Opponent = header.Opponent,
                Date = header.Date.ToString(DateTimeFormat),
                Location = header.Location,
                OilPatternName = header.OilPattern.Name,
                OilPatternUrl = header.OilPattern.Url
            }));
        }
Esempio n. 3
0
    public override async Task Handle(HandlerContext <Command> context)
    {
        Roster roster = CompositionRoot.DocumentSession.Load <Roster>(context.Payload.RosterId);

        if (roster.IsVerified && context.Payload.Force == false)
        {
            return;
        }

        WebsiteConfig websiteConfig = CompositionRoot.DocumentSession.Load <WebsiteConfig>(WebsiteConfig.GlobalId);
        HeadInfo      result        = await CompositionRoot.BitsClient.GetHeadInfo(roster.BitsMatchId);

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

        // chance to update roster values
        Roster.Update update = new(
            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 CompositionRoot.BitsClient.GetBitsMatchResult(roster.BitsMatchId);

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

        _ = roster.UpdateWith(context.CorrelationId, update);
    }
Esempio n. 4
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());
        }