コード例 #1
0
        private void CheckGames()
        {
            logger.Info("Checking for new or removed games now.");

            var games = _client.ListGames().ToDictionary(x => x.Name);

            if (_availableGames.Any())
            {
                // Check for any games that are now available that were not
                //  the last time we checked
                foreach (var game in games)
                {
                    if (!_availableGames.ContainsKey(game.Key))
                    {
                        var message = string.Format("It looks like '{0}' is a new game available for play!", game.Value.Name);

                        if (this._pushOverClient != null)
                        {
                            this._pushOverClient.SendMessage(message, "New game");
                        }

                        logger.Info(message);
                    }
                }

                // Now, check for any games that were removed
                foreach (var game in _availableGames)
                {
                    if (!games.ContainsKey(game.Key))
                    {
                        var message = string.Format("It looks like '{0}' was removed from play.", game.Value.Name);

                        if (this._pushOverClient != null)
                        {
                            this._pushOverClient.SendMessage(message, "Game removed");
                        }

                        logger.Info(message);
                    }
                }
            }

            _availableGames = games;
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            if ((args == null) || (args.Length == 0))
            {
                Console.WriteLine("Usage: RiftScratchGame /u <username> /pa <password> /c <character name@shard name> /g <game> /pu <pushover key>");
                return;
            }

            // Clear the console.
            Console.Clear();

            var arguments = Args.Configuration.Configure <CommandObject> ().CreateAndBind(args);

            var     sessionFactory = new SessionFactory();
            Session session;

            // Login
            try
            {
                session = sessionFactory.Login(arguments.Username, arguments.Password);
            }
            catch (AuthenticationException ex)
            {
                logger.Error(ex.Message);
                return;
            }
            catch (Exception ex)
            {
                logger.Error("An unexpected error occurred", ex);
                return;
            }

            // Create a new client
            var            riftClient     = new RiftClientSecured(session);
            var            gameClient     = new ScratchGameClient(session);
            PushOverClient pushOverClient = arguments.PushoverKey != null ? new PushOverClient(arguments.PushoverKey) : null;

            var games = gameClient.ListGames();

            if (string.IsNullOrWhiteSpace(arguments.Game))
            {
                Console.WriteLine("The following games are available to play:");

                var currentGames = string.Join(System.Environment.NewLine, games.Select(x => string.Format("\t{0}", x.Name)));

                Console.WriteLine(currentGames);

                return;
            }

            var characters = riftClient.ListCharacters();
            var character  = characters.FirstOrDefault(x => x.FullName == arguments.Character);

            if (character == null)
            {
                var characterList = string.Join(System.Environment.NewLine, characters.OrderBy(x => x.Shard.Name).ThenBy(x => x.Name).Select(x => string.Format("\t{0}", x.FullName)));

                logger.ErrorFormat("Unable to locate {0} in your list of characters.  Please use one of the following:", arguments.Character);
                logger.ErrorFormat(characterList);

                return;
            }

            var game = games.FirstOrDefault(x => x.Name == arguments.Game);

            if (game == null)
            {
                var currentGames = string.Join(System.Environment.NewLine, games.Select(x => string.Format("\t{0}", x.Name)));

                logger.ErrorFormat("It doesn't look like '{0}' is a valid game. The following is a list of valid games:", arguments.Game);
                logger.Error(currentGames);

                return;
            }

            logger.InfoFormat("Hello {0}@{1}!  Are you up for a game of {2}?", character.Name, character.Shard.Name, game.Name);

            if (pushOverClient != null)
            {
                logger.InfoFormat("I see you're using PushOver.  I'll let you know there whenever you win something.");
            }

            var checker = new GameChecker(session, pushOverClient);
            var runner  = new GameRunner(session, pushOverClient);
            var waiter  = new Waiter();

            // Start up the game checker
            checker.Start();

            // Start up the game runner
            runner.Start(game, character);

            // Wait for an interrupt
            waiter.Wait();
        }
コード例 #3
0
        public void List_Scratch_Cards_Should_Return_Back_A_Non_Null_Non_Empty_List()
        {
            var cards = client.ListGames();

            Assert.That(cards, Is.Not.Null.And.Not.Empty);
        }