Пример #1
0
        public static Stream awsLambdaHandler(Stream inputStream)
        {
            Console.WriteLine("starting via lambda");

            string input = StringUtils.GetString(inputStream);

            Console.WriteLine("Input:" + input);

            WebUtils.WebRequest request = WebUtils.GetJsonObject(input);

            string response = "default response";

            if (TwitterUtils.IsChallengeRequest(request))
            {
                TwitterUtils.InitializeCredentials(false);
                response = TwitterUtils.HandleChallengeRequest(request);
            }
            else if (TwitterUtils.IsAccountActivityRequest(request))
            {
                TwitterUtils.InitializeCredentials();
                response = TwitterUtils.HandleAccountActivityRequest(request);
            }

            return(StringUtils.GetStream(response));
        }
Пример #2
0
        public static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            Console.WriteLine("Beginning program");

            using (StreamReader file = File.OpenText("input.txt"))
            {
                string input = file.ReadToEnd();
                if (input.Length > 0)
                {
                    WebUtils.WebRequest request = WebUtils.GetJsonObject(input);
                    TwitterUtils.InitializeCredentials();
                    TwitterUtils.HandleAccountActivityRequest(request);
                    return;
                }
            }

            string previousGameText;

            using (StreamReader file = File.OpenText("output.txt"))
            {
                previousGameText = file.ReadToEnd();
            }

            if (previousGameText == "")
            {
                string newGameOutput = StartFreshGame(DateTimeOffset.UtcNow);
                using (StreamWriter file = File.CreateText("output.txt"))
                {
                    file.Write(newGameOutput);
                }
            }

            while (true)
            {
                using (StreamReader file = File.OpenText("output.txt"))
                {
                    previousGameText = file.ReadToEnd();
                }

                string inputText = Console.ReadLine();

                string gameOutput = "";
                if (Game.MatchesResetCommand(inputText))
                {
                    gameOutput = StartFreshGame(DateTimeOffset.UtcNow);
                }
                else if (Game.MatchesHelpCommand(inputText))
                {
                    string commandsList = Game.GetCommandsList();
                    var    tweets       = TwitterUtils.SplitLinesIntoTweets(commandsList);
                    foreach (string tweet in tweets)
                    {
                        gameOutput += tweet + "\n\n";
                    }
                }
                else
                {
                    gameOutput = RunOneTick(previousGameText, inputText, DateTimeOffset.UtcNow);
                }

                using (StreamWriter file = File.CreateText("output.txt"))
                {
                    file.Write(gameOutput);
                }
            }
        }