Example #1
0
        private Kalender CreateKalenderMatch(Reeks reeks, TeamMatchEntryType frenoyMatch, string thuisPloegCode)
        {
            var kalender = new Kalender
            {
                FrenoyMatchId = frenoyMatch.MatchId,
                Datum         = frenoyMatch.Date,
                Uur           = new TimeSpan(frenoyMatch.Time.Hour, 0, 0),
                ThuisClubId   = GetClubId(frenoyMatch.HomeClub),
                ThuisPloeg    = ExtractTeamCodeFromFrenoyName(frenoyMatch.HomeTeam),
                UitClubId     = GetClubId(frenoyMatch.AwayClub),
                UitPloeg      = ExtractTeamCodeFromFrenoyName(frenoyMatch.AwayTeam),
                Week          = int.Parse(frenoyMatch.WeekName)
            };

            kalender.ThuisClubPloegId = GetClubPloegId(reeks.Id, kalender.ThuisClubId.Value, kalender.ThuisPloeg);
            kalender.UitClubPloegId   = GetClubPloegId(reeks.Id, kalender.UitClubId.Value, kalender.UitPloeg);

            // In the db the ThuisClubId is always Erembodegem
            kalender.Thuis = kalender.ThuisClubId == _thuisClubId && kalender.ThuisPloeg == thuisPloegCode ? 1 : 0;
            if (kalender.Thuis == 0)
            {
                var thuisClubId      = kalender.ThuisClubId;
                var thuisPloeg       = kalender.ThuisPloeg;
                var thuisClubPloegId = kalender.ThuisClubPloegId;

                kalender.ThuisClubId      = kalender.UitClubId;
                kalender.ThuisPloeg       = kalender.UitPloeg;
                kalender.ThuisClubPloegId = kalender.UitClubPloegId;

                kalender.UitClubId      = thuisClubId;
                kalender.UitPloeg       = thuisPloeg;
                kalender.UitClubPloegId = thuisClubPloegId;
            }
            return(kalender);
        }
 private static void AddMatchGames(TeamMatchEntryType frenoyMatch, MatchEntity matchEntity)
 {
     if (frenoyMatch.MatchDetails.IndividualMatchResults != null)
     {
         int id = 0;
         foreach (var frenoyIndividual in frenoyMatch.MatchDetails.IndividualMatchResults)
         {
             id--;
             AddMatchGames(frenoyIndividual, id, matchEntity);
         }
     }
 }
        /// <summary>
        /// Sync match score, players and individual results
        /// </summary>
        private async Task SyncMatchResults(MatchEntity matchEntity, TeamMatchEntryType frenoyMatch)
        {
            if (_forceSync || (!matchEntity.IsSyncedWithFrenoy && matchEntity.ShouldBePlayed))
            {
                if (frenoyMatch.Score != null)
                {
                    string score     = frenoyMatch.Score.ToLowerInvariant();
                    bool   isForfeit = score.Contains("ff") || score.Contains("af") || score.Contains("gu");
                    matchEntity.WalkOver = isForfeit;

                    // Uitslag
                    var scoreRex = new Regex(@"^(\d+)-(\d+)");
                    var match    = scoreRex.Match(frenoyMatch.Score);
                    if (match.Success)
                    {
                        matchEntity.HomeScore = int.Parse(match.Groups[1].Value);
                        matchEntity.AwayScore = int.Parse(match.Groups[2].Value);
                    }
                }

                if (frenoyMatch.MatchDetails != null && frenoyMatch.MatchDetails.DetailsCreated)
                {
                    await AddMatchPlayers(frenoyMatch.MatchDetails.HomePlayers.Players, matchEntity, true);
                    await AddMatchPlayers(frenoyMatch.MatchDetails.AwayPlayers.Players, matchEntity, false);

                    //AssertMatchPlayers(matchEntity);

                    if (!frenoyMatch.IsAwayForfeited && !frenoyMatch.IsHomeForfeited)
                    {
                        AddMatchGames(frenoyMatch, matchEntity);
                    }

                    await RemoveExistingMatchPlayersAndGames(matchEntity);
                }

                if (frenoyMatch.Score != null && frenoyMatch.MatchDetails != null && frenoyMatch.MatchDetails.DetailsCreated)
                {
                    matchEntity.IsSyncedWithFrenoy = true;
                }
            }
        }
 private static void AddMatchGames(TeamMatchEntryType frenoyMatch, MatchEntity matchEntity)
 {
     if (frenoyMatch.MatchDetails.IndividualMatchResults != null)
     {
         int id = 0;
         foreach (var frenoyIndividual in frenoyMatch.MatchDetails.IndividualMatchResults)
         {
             id--;
             AddMatchGames(frenoyIndividual, id, matchEntity);
         }
     }
 }
        private void SyncMatchDetails(MatchEntity matchEntity, TeamMatchEntryType frenoyMatch)
        {
            if (!matchEntity.IsSyncedWithFrenoy)
            {
                if (frenoyMatch.Score != null)
                {
                    string score = frenoyMatch.Score.ToLowerInvariant();
                    bool isForfeit = score.Contains("ff") || score.Contains("af") || score.Contains("gu");
                    if (!isForfeit)
                    {
                        // Uitslag
                        matchEntity.HomeScore = int.Parse(frenoyMatch.Score.Substring(0, frenoyMatch.Score.IndexOf("-")));
                        matchEntity.AwayScore = int.Parse(frenoyMatch.Score.Substring(frenoyMatch.Score.IndexOf("-") + 1));
                        matchEntity.WalkOver = false;
                    }
                    else
                    {
                        matchEntity.WalkOver = true;
                    }
                }

                if (frenoyMatch.MatchDetails != null && frenoyMatch.MatchDetails.DetailsCreated)
                {
                    AddMatchPlayers(frenoyMatch.MatchDetails.HomePlayers.Players, matchEntity, true);
                    AddMatchPlayers(frenoyMatch.MatchDetails.AwayPlayers.Players, matchEntity, false);
                    //AssertMatchPlayers(matchEntity);

                    AddMatchGames(frenoyMatch, matchEntity);

                    RemoveExistingMatchPlayersAndGames(matchEntity);
                }

                if (frenoyMatch.Score != null && frenoyMatch.MatchDetails != null && frenoyMatch.MatchDetails.DetailsCreated)
                {
                    matchEntity.IsSyncedWithFrenoy = true;
                }

                CommitChanges();
            }
        }
        private void MapMatch(MatchEntity entity, int? teamId, int frenoyDivisionId, TeamMatchEntryType frenoyMatch, int frenoySeason = Constants.FrenoySeason)
        {
            entity.FrenoyMatchId = frenoyMatch.MatchId;
            entity.Date = frenoyMatch.Date + new TimeSpan(frenoyMatch.Time.Hour, frenoyMatch.Time.Minute, 0);
            entity.HomeClubId = GetClubId(frenoyMatch.HomeClub);
            entity.HomeTeamCode = ExtractTeamCodeFromFrenoyName(frenoyMatch.HomeTeam);
            entity.AwayClubId = GetClubId(frenoyMatch.AwayClub);
            entity.AwayTeamCode = ExtractTeamCodeFromFrenoyName(frenoyMatch.AwayTeam);
            entity.Week = int.Parse(frenoyMatch.WeekName);
            entity.FrenoySeason = frenoySeason;
            entity.FrenoyDivisionId = frenoyDivisionId;
            entity.Competition = _settings.Competition;

            //TODO: we zaten hier for the derby problem
            // do not pass teamId here but find out what the Team is based on HomeClubId and HomeTeamCode
            if (teamId.HasValue)
            {
                if (entity.HomeClubId == Constants.OwnClubId)
                {
                    entity.HomeTeamId = teamId;
                }
                else if (entity.AwayClubId == Constants.OwnClubId)
                {
                    entity.AwayTeamId = teamId;
                }
            }
        }
        private Kalender CreateKalenderMatch(Reeks reeks, TeamMatchEntryType frenoyMatch, string thuisPloegCode)
        {
            var kalender = new Kalender
            {
                FrenoyMatchId = frenoyMatch.MatchId,
                Datum = frenoyMatch.Date,
                Uur = new TimeSpan(frenoyMatch.Time.Hour, 0, 0),
                ThuisClubId = GetClubId(frenoyMatch.HomeClub),
                ThuisPloeg = ExtractTeamCodeFromFrenoyName(frenoyMatch.HomeTeam),
                UitClubId = GetClubId(frenoyMatch.AwayClub),
                UitPloeg = ExtractTeamCodeFromFrenoyName(frenoyMatch.AwayTeam),
                Week = int.Parse(frenoyMatch.WeekName)
            };

            kalender.ThuisClubPloegId = GetClubPloegId(reeks.Id, kalender.ThuisClubId.Value, kalender.ThuisPloeg);
            kalender.UitClubPloegId = GetClubPloegId(reeks.Id, kalender.UitClubId.Value, kalender.UitPloeg);

            // In the db the ThuisClubId is always Erembodegem
            kalender.Thuis = kalender.ThuisClubId == _thuisClubId && kalender.ThuisPloeg == thuisPloegCode ? 1 : 0;
            if (kalender.Thuis == 0)
            {
                var thuisClubId = kalender.ThuisClubId;
                var thuisPloeg = kalender.ThuisPloeg;
                var thuisClubPloegId = kalender.ThuisClubPloegId;

                kalender.ThuisClubId = kalender.UitClubId;
                kalender.ThuisPloeg = kalender.UitPloeg;
                kalender.ThuisClubPloegId = kalender.UitClubPloegId;

                kalender.UitClubId = thuisClubId;
                kalender.UitPloeg = thuisPloeg;
                kalender.UitClubPloegId = thuisClubPloegId;
            }
            return kalender;
        }
        private async Task MapMatch(MatchEntity entity, int?teamId, int frenoyDivisionId, TeamMatchEntryType frenoyMatch, int?frenoySeason)
        {
            frenoySeason = frenoySeason ?? _db.CurrentFrenoySeason;

            entity.ShouldBePlayed = !frenoyMatch.HomeTeam.Trim().StartsWith("Vrij") && !frenoyMatch.AwayTeam.Trim().StartsWith("Vrij");
            entity.FrenoyMatchId  = frenoyMatch.MatchId;
            entity.Date           = frenoyMatch.Date + new TimeSpan(frenoyMatch.Time.Hour, frenoyMatch.Time.Minute, 0);
            if (frenoyMatch.HomeClub != "-")
            {
                entity.HomeClubId = await GetClubId(frenoyMatch.HomeClub);

                entity.HomeTeamCode = ExtractTeamCodeFromFrenoyName(frenoyMatch.HomeTeam);
            }

            Debug.Assert(entity.ShouldBePlayed || frenoyMatch.AwayClub == "-" || frenoyMatch.HomeClub == "-");
            if (frenoyMatch.AwayClub != "-")
            {
                entity.AwayClubId = await GetClubId(frenoyMatch.AwayClub);

                entity.AwayTeamCode = ExtractTeamCodeFromFrenoyName(frenoyMatch.AwayTeam);
            }

            entity.Week             = int.Parse(frenoyMatch.WeekName);
            entity.FrenoySeason     = frenoySeason.Value;
            entity.FrenoyDivisionId = frenoyDivisionId;
            entity.Competition      = _settings.Competition;

            //TODO: we zaten hier for the derby problem
            // do not pass teamId here but find out what the Team is based on HomeClubId and HomeTeamCode
            if (teamId.HasValue)
            {
                if (entity.HomeClubId == Constants.OwnClubId)
                {
                    entity.HomeTeamId = teamId;
                    entity.AwayTeamId = null;
                }
                else if (entity.AwayClubId == Constants.OwnClubId)
                {
                    entity.AwayTeamId = teamId;
                    entity.HomeTeamId = null;
                }
            }
        }