Ejemplo n.º 1
0
        public void CheckTournaments()
        {
            AddNewAndActiveTournaments();
            foreach (TrackableTournament t in Tournaments.Where(t => t.Tracking))
            {
                Tournament oldTournament = t.Tournament;
                Tournament newTournament = _reader.getTournament(t.Tournament.TournamentId).WithName(t.Name);
                t.Tournament = newTournament;
                Boolean uploadAll = false;
                if (!t.TournamentUploaded)
                {
                    UploadEvent e = new UploadEvent(() => _uploader.UploadTournament(t), newTournament, UploadEvent.Type.Tournament, 0);
                    UploadQueue.Enqueue(e);
                    t.TournamentUploaded = true;
                    uploadAll            = true;
                }
                if (!oldTournament.Equals(newTournament) || uploadAll)
                {
                    if (!oldTournament.Teams.SequenceEqual(newTournament.Teams) || !newTournament.Teams.IsEmpty && uploadAll)
                    {
                        UploadEvent e = new UploadEvent(() => _uploader.UploadTeams(newTournament.SanctionNumber, newTournament.Teams),
                                                        newTournament, UploadEvent.Type.Teams, 0);
                        UploadQueue.Enqueue(e);
                        uploadAll = true;
                    }
                    if (!oldTournament.Seatings.SequenceEqual(newTournament.Seatings) || !newTournament.Seatings.IsEmpty && uploadAll)
                    {
                        UploadEvent e = new UploadEvent(() => _uploader.UploadSeatings(newTournament.SanctionNumber, newTournament.Seatings),
                                                        newTournament, UploadEvent.Type.Seatings, 0);
                        UploadQueue.Enqueue(e);
                    }
                    if (!oldTournament.Rounds.SequenceEqual(newTournament.Rounds) || !newTournament.Rounds.IsEmpty && uploadAll)
                    {
                        foreach (var round in oldTournament.Rounds.ZipAll(newTournament.Rounds, (r1, r2) => new { OldRound = r1, NewRound = r2 }))
                        {
                            if (round.NewRound == null)
                            {
                                UploadEvent e = new UploadEvent(() => _uploader.DeleteRound(newTournament.SanctionNumber, round.OldRound.Number),
                                                                newTournament, UploadEvent.Type.Round, round.OldRound.Number);
                                UploadQueue.Enqueue(e);
                            }
                            else
                            {
                                if (round.OldRound == null || round.NewRound == null || !round.OldRound.Pairings.SequenceEqual(round.NewRound.Pairings, new Pairing.PairingEqualityComparer()) || round.NewRound != null && uploadAll)
                                {
                                    UploadEvent e = new UploadEvent(() => _uploader.UploadPairings(newTournament.SanctionNumber, round.NewRound.Number, round.NewRound.Playoff, round.NewRound.Pairings),
                                                                    newTournament, UploadEvent.Type.Pairings, round.NewRound.Number);
                                    UploadQueue.Enqueue(e);
                                    uploadAll = true;
                                }
                                if (round.OldRound == null || !round.OldRound.Pairings.Select(p => p.Result).SequenceEqual(round.NewRound.Pairings.Select(p => p.Result)) || round.NewRound != null && uploadAll)
                                {
                                    UploadEvent e = new UploadEvent(() => _uploader.UploadResults(newTournament.SanctionNumber, round.NewRound.Number, round.NewRound.Pairings),
                                                                    newTournament, UploadEvent.Type.Results, round.NewRound.Number);
                                    UploadQueue.Enqueue(e);
                                    uploadAll = true;
                                }
                            }
                        }
                    }
                    if (!oldTournament.Pods.SequenceEqual(newTournament.Pods) || !newTournament.Pods.IsEmpty && uploadAll)
                    {
                        UploadEvent e = new UploadEvent(() => _uploader.UploadPods(newTournament.SanctionNumber, newTournament.Pods),
                                                        newTournament, UploadEvent.Type.Pods, 0);
                        UploadQueue.Enqueue(e);
                    }
                }
            }

            Thread.Sleep(5000);
            new CheckTournamentsDelegate(CheckTournaments).BeginInvoke(null, null);
        }