Exemplo n.º 1
0
        private void ExecuteRunnerAction(RunnerAction runnerAction)
        {
            Console.WriteLine("Chosen action is: " + runnerAction.LongName);

            var client = TdlClient.Build()
                         .SetHostname(hostname)
                         .SetUniqueId(username)
                         .SetAuditStream(new ConsoleAuditStream())
                         .Create();

            var processingRules = new ProcessingRules();

            processingRules
            .On("display_description")
            .Call(p => RoundManagement.SaveDescription(p[0], p[1]))
            .Then(ClientActions.Publish);

            foreach (var solution in solutions)
            {
                processingRules
                .On(solution.Key)
                .Call(solution.Value)
                .Then(runnerAction.ClientAction);
            }

            client.GoLiveWith(processingRules);

            RecordingSystem.NotifyEvent(RoundManagement.GetLastFetchedRound(), runnerAction.ShortName);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
        public void Start(string[] args)
        {
            if (!IsRecordingSystemOk())
            {
                Console.WriteLine("Please run `record_screen_and_upload` before continuing.");
                return;
            }

            var runnerAction = ExtractActionFrom(args).OrElse(defaultRunnerAction);

            Console.WriteLine("Chosen action is: " + runnerAction.LongName);

            var client = TdlClient.Build()
                         .SetHostname(hostname)
                         .SetUniqueId(username)
                         .SetAuditStream(new ConsoleAuditStream())
                         .Create();

            var processingRules = new ProcessingRules();

            processingRules
            .On("display_description")
            .Call(p => RoundManagement.DisplayAndSaveDescription(p[0], p[1]))
            .Then(ClientActions.Publish);

            foreach (var solution in solutions)
            {
                processingRules
                .On(solution.Key)
                .Call(solution.Value)
                .Then(runnerAction.ClientAction);
            }

            client.GoLiveWith(processingRules);

            RecordingSystem.NotifyEvent(RoundManagement.GetLastFetchedRound(), runnerAction.ShortName);
        }