Example #1
0
        //~~~~~~~~ The entry point ~~~~~~~~~

        public void Start(string[] args)
        {
            if (!RecordingSystem.IsRecordingSystemOk())
            {
                Console.WriteLine("Please run `record_screen_and_upload` before continuing.");
                return;
            }

            WindowsConsoleSupport.EnableColours();

            Console.WriteLine("Connecting to " + hostname);

            if (UseExperimentalFeature())
            {
                ExecuteServerActionFromUserInput(args);
            }
            else
            {
                ExecuteRunnerActionFromArgs(args);
            }

            bool holdAfterFinish = bool.Parse(CredentialsConfigFile.Get("tdl_hold_after_finish", "true"));

            if (holdAfterFinish)
            {
                Console.Write("\nPress any key to exit... ");
                Console.ReadKey();
            }
        }
Example #2
0
        //~~~~~~~~ Server Actions ~~~~~~~~~

        private void ExecuteServerActionFromUserInput(string[] args)
        {
            try
            {
                var journeyId             = CredentialsConfigFile.Get("tdl_journey_id");
                var useColours            = bool.Parse(CredentialsConfigFile.Get("tdl_use_coloured_output", "true"));
                var challengeServerClient = new ChallengeServerClient(hostname, journeyId, useColours);

                var journeyProgress = challengeServerClient.GetJourneyProgress();
                Console.WriteLine(journeyProgress);

                var availableActions = challengeServerClient.GetAvailableActions();
                Console.WriteLine(availableActions);

                if (availableActions.Contains("No actions available."))
                {
                    return;
                }

                var userInput = GetUserInput(args);
                if (userInput == null)
                {
                    Console.Error.WriteLine("No input stream detected. Please run this Solution on External Console.");
                    return;
                }

                //Obs: Deploy seems to be the only "special" action, everything else is driven by the server
                if (userInput.Equals("deploy"))
                {
                    // DEBT - the RecordingSystem.notifyEvent happens in executeRunnerAction, but once we migrate form the legacy system, we should move it outside for clarity
                    var runnerAction = RunnerAction.DeployToProduction;
                    ExecuteRunnerAction(runnerAction);
                }

                var actionFeedback = challengeServerClient.SendAction(userInput);
                Console.WriteLine(actionFeedback);

                var responseString = challengeServerClient.GetRoundDescription();
                RoundManagement.SaveDescription(
                    responseString,
                    lastFetchedRound => RecordingSystem.NotifyEvent(lastFetchedRound, RunnerAction.GetNewRoundDescription.ShortName)
                    );
            } catch (ServerErrorException e) {
                Console.Error.WriteLine("Server experienced an error. Try again. " + e);
            } catch (OtherCommunicationException e) {
                Console.Error.WriteLine("Client threw an unexpected error. " + e);
            } catch (ClientErrorException e) {
                Console.Error.WriteLine("The client sent something the server didn't expect.");
                Console.WriteLine(e.Message);
            }
        }
Example #3
0
 private static bool IsRecordingSystemOk() =>
 !bool.Parse(CredentialsConfigFile.Get("tdl_require_rec", "true")) ||
 RecordingSystem.IsRunning();
Example #4
0
 private static bool UseExperimentalFeature()
 {
     return(bool.Parse(CredentialsConfigFile.Get("tdl_enable_experimental", "false")));
 }
Example #5
0
 private static bool IsRecordingRequired()
 {
     return(bool.Parse(CredentialsConfigFile.Get("tdl_require_rec", "true")));
 }