public static Bitmap RenderTournamentBrackets(Tournament tourny, bool isPerformanceRound)
        {
            try
            {
                var teams = new Dictionary<Guid, string>();
                foreach (var team in from t in tourny.TeamsForTournament
                                     select new KeyValuePair<Guid, string>(t.TeamId, t.TeamName))
                {
                    teams.Add(team.Key, team.Value);
                }
                Bitmap rendered = new Bitmap(1, 1);
                //var g = new SvgNet.SvgGdi.SvgGraphics();
                var grs = new SystemGraphics();
                if (isPerformanceRound)
                {
                    var size = tourny.VisualizedBracketsSeeded.Measure(grs, new TournamentApi.TournamentNameTable(teams));
                    rendered = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height));
                    tourny.VisualizedBracketsSeeded.Render(new SystemGraphics(rendered), new TournamentApi.TournamentNameTable(teams));

                }
                else
                {
                    var size = tourny.VisualizedBrackets.Measure(grs, new TournamentApi.TournamentNameTable(teams));
                    rendered = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height));
                    tourny.VisualizedBrackets.Render(new SystemGraphics(rendered), new TournamentApi.TournamentNameTable(teams));

                }
                return rendered;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return null;

        }
示例#2
0
        public void RunTournament(IPairingsGenerator pg, List<TournamentTeam> teams, List<TournamentRound> rounds, bool allowTies, TournamentNameTable nameTable)
        {
            ITournamentVisualizer viz = null;
            if (nameTable != null)
            {
                viz = pg as ITournamentVisualizer;
            }

            while (true)
            {
                pg.LoadState(teams, rounds);
                TournamentRound newRound = pg.CreateNextRound(null);

                if (viz != null)
                {
                    var gfx = new SystemGraphics();
                    var q2 = viz.Measure(gfx, nameTable);
                    viz.Render(gfx, nameTable);
                }

                if (newRound == null)
                {
                    pg.LoadState(teams, rounds);
                    newRound = pg.CreateNextRound(null);
                    break;
                }

                if (allowTies)
                {
                    foreach (var pairing in newRound.Pairings)
                    {
                        foreach (var teamScore in pairing.TeamScores)
                        {
                            teamScore.Score = new HighestPointsScore(r.Next(20));
                        }
                    }
                }
                else
                {
                    foreach (var pairing in newRound.Pairings)
                    {
                        List<double> scoresUsed = new List<double>();
                        foreach (var teamScore in pairing.TeamScores)
                        {
                            double score;
                            do
                            {
                                score = r.NextDouble();
                            } while (scoresUsed.Where(s => s == score).Any());

                            teamScore.Score = new HighestPointsScore(score);
                        }
                    }
                }

                rounds.Add(newRound);
            }
        }