Exemple #1
0
        private String RespondToTVChannel(IBaseballSensor sensor, BaseballTeam team, DateTime time)
        {
            BaseballGame lastGame = null;

            foreach (BaseballGame game in sensor.LoadScoresForTeam(time, team))
            {
                List <String> possibleChannels = GetChannelsGameIsOn(sensor, game);
                lastGame = game;
                switch (game.State)
                {
                case GameState.NoGame:
                    return(String.Format("The {0} are not playing today.", team.Name));

                case GameState.GameHasntStarted:
                    if (!possibleChannels.Any())
                    {
                        return(String.Format("The {0} game will not be available on national TV.", team.Name));
                    }
                    else
                    {
                        return(String.Format("The {0} game will be available on {1} at {2}", team.Name, SayList(possibleChannels), game.StartingTime.ToShortTimeString()));
                    }

                case GameState.RainDelay:
                    if (!possibleChannels.Any())
                    {
                        return(String.Format("The {0} game is not available on national TV.", team.Name));
                    }
                    else
                    {
                        return(String.Format("The {0} game is currently in a rain delay, but is available on {1}", team.Name, SayList(possibleChannels)));
                    }

                case GameState.Started:
                    if (!possibleChannels.Any())
                    {
                        return(String.Format("The {0} game is not available on national TV.", team.Name));
                    }
                    else
                    {
                        return(String.Format("The {0} game is available on {1}.", team.Name, SayList(possibleChannels)));
                    }
                }
            }
            if (lastGame != null)
            {
                if (lastGame.State == GameState.Postponed)
                {
                    return(RespondForOneGame(lastGame, team));
                }
                return(String.Format("The game has already completed. {0}", RespondForOneGame(lastGame, team)));
            }
            return(String.Format("The {0} are not playing today.", team.Name));
        }
Exemple #2
0
        private String RespondForAllGames(IBaseballSensor sensor, DateTime time, BaseballTeam team)
        {
            IEnumerable <BaseballGame> scores = sensor.LoadScoresForTeam(time, team);

            if (!scores.Any())
            {
                return(String.Format("The {0} are not playing today.", team.Name));
            }
            if (scores.Count() == 1)
            {
                return(RespondForOneGame(scores.First(), team));
            }
            else if (scores.Count() == 2)
            {
                return("In the first game, " + RespondForOneGame(scores.First(), team) +
                       ". In the second game, " + RespondForOneGame(scores.Last(), team) + ".");
            }
            else
            {
                // We shouldn't have more than a doubleheader...
                return(String.Empty);
            }
        }
Exemple #3
0
        private String RespondToTurnToGame(IBaseballSensor sensor, BaseballTeam team, DateTime time)
        {
            BaseballGame lastGame = null;

            foreach (BaseballGame game in sensor.LoadScoresForTeam(time, team))
            {
                List <String> possibleChannels = GetChannelsGameIsOn(sensor, game);
                lastGame = game;
                switch (game.State)
                {
                case GameState.NoGame:
                    return(String.Format("The {0} are not playing today.", team.Name));

                case GameState.GameHasntStarted:
                    if (possibleChannels.Any())
                    {
                        return(String.Format("The {0} will be playing at {1}.", team.Name, game.StartingTime.ToShortTimeString()));
                    }
                    else
                    {
                        return(String.Format("The {0} game will not be available on national TV.", team.Name));
                    }

                case GameState.RainDelay:
                    if (possibleChannels.Any())
                    {
                        return(String.Format("The {0} game is currently in a rain delay, but is available on ESPN.", team.Name));
                    }
                    else
                    {
                        return(String.Format("The {0} game is not available on national TV.", team.Name));
                    }

                case GameState.Started:
                    if (possibleChannels.Any() && _remotes.Any())
                    {
                        IEnumerable <String>    possibleRemoteNames = _remotes.Select(r => r.Name);
                        IEnumerable <ITVRemote> remotes             = ConfigManager.FindAllComponentsOfType <ITVRemote>();
                        foreach (ITVRemote remote in remotes)
                        {
                            if (possibleRemoteNames.Contains(remote.Name) &&
                                possibleChannels.Any(c => remote.GetChannels().Contains(c)))
                            {
                                Task.Run(() => remote.SendChannel(possibleChannels.First(c => remote.GetChannels().Contains(c))));
                            }
                        }
                        return("OK");
                    }
                    else if (possibleChannels.Any())
                    {
                        return(String.Format("There is no T V remote connected to me for me to use. The {0} game is on {1}.", team.Name, SayList(possibleChannels)));
                    }
                    else
                    {
                        return(String.Format("The {0} game is not on a national broadcast!", team.Name));
                    }

                case GameState.Postponed:
                case GameState.Completed:
                    break;
                }
            }
            if (lastGame != null)
            {
                if (lastGame.State == GameState.Postponed)
                {
                    return(RespondForOneGame(lastGame, team));
                }
                return(String.Format("The game has already completed. {0}", RespondForOneGame(lastGame, team)));
            }
            return(String.Format("The {0} are not playing today.", team.Name));
        }