Exemple #1
0
        // A game will be a time or date/time, followed by a separator, followed
        // by a separated list of numbers, which are the teams in that game. e.g.:
        // 8:00	1	2	3
        public void Parse(string s, FixtureTeams teams, char separator = '\t')
        {
            string[] lines = s.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string line in lines)
            {
                FixtureGame fg = new FixtureGame();

                string[] fields = line.Split('\t');
                fg.Time = DateTime.Parse(fields[0]);
                for (int i = 1; i < fields.Length; i++)
                {
                    if (!string.IsNullOrEmpty(fields[i]))
                    {
                        FixtureTeam ft;
                        if (int.TryParse(fields[i], out int teamnum))
                        {
                            ft = teams.Find(x => x.Id() == teamnum);
                        }
                        else
                        {
                            ft = teams.Find(x => x.LeagueTeam != null && x.LeagueTeam.Name == fields[i]);
                        }

                        if (ft == null)
                        {
                            ft = new FixtureTeam
                            {
                                Name = "Team " + fields[i]
                            }
                        }
                        ;

                        if (!fg.Teams.ContainsKey(ft))
                        {
                            if (fields.Length <= 5)                              // If there are five or less teams per game,
                            {
                                fg.Teams.Add(ft, (Colour)i);                     // assign colours to teams.
                            }
                            else
                            {
                                fg.Teams.Add(ft, Colour.None);
                            }
                        }
                    }
                }

                Add(fg);
            }
        }
Exemple #2
0
        // Import past games from a league.
        public void Parse(League league, FixtureTeams teams)
        {
            foreach (Game lg in league.Games(false))
            {
                FixtureGame fg = new FixtureGame();

                fg.Time = lg.Time;

                foreach (GameTeam gt in lg.Teams)
                {
                    FixtureTeam ft = teams.Find(x => x.LeagueTeam == league.LeagueTeam(gt));
                    if (ft != null && !fg.Teams.ContainsKey(ft))
                    {
                        fg.Teams.Add(ft, gt.Colour);
                    }
                }

                Add(fg);
            }
        }