示例#1
0
 public CommandResult(
     Guid commandId,
     CommandResultType resultType = CommandResultType.Success)
 {
     CommandId  = commandId;
     ResultType = resultType;
 }
示例#2
0
 protected GenericMessage(string message, object[] args, string defaultMessage, CommandResultType type)
 {
     Message = message;
     MessageArguments = args;
     DefaultMessage = defaultMessage;
     Type = type;
 }
示例#3
0
 protected GenericMessage(string message, object[] args, string defaultMessage, CommandResultType type)
 {
     Message          = message;
     MessageArguments = args;
     DefaultMessage   = defaultMessage;
     Type             = type;
 }
示例#4
0
        private void RunArguments(string[] arguments)
        {
            if (arguments.Length <= 0)
            {
                Logger.Error("Invalid input");
                return;
            }

            LoadCommands();
            LoadGlobalParameterConsumer();
            ShowCopyright();
            Logger.Info("Argument Mode");

            CommandResultType result = ProcessArguments(arguments);

            if (result == CommandResultType.Exit)
            {
                ShutdownCommands();
                return;
            }

            Logger.Info("Press `e'-key to exit.");
            ConsoleKeyInfo keyInfo = Console.ReadKey();

            while (keyInfo.Key != ConsoleKey.E)
            {
                keyInfo = Console.ReadKey();
            }

            ShutdownCommands();
        }
示例#5
0
        GenerateResult_Returns_Expected_EndpointResult(
            CommandResultType commandResultType,
            Type expectedResultType,
            int expectedStatusCode)
        {
            _mediatorMock
            .Setup(
                x => x.Send(
                    It.IsAny <IngestEventCommand>(),
                    It.IsAny <CancellationToken>()))
            .Returns(
                Task.FromResult(
                    new CommandResult(
                        Guid.NewGuid(),
                        commandResultType)));
            var generator = CreateGenerator();

            var actual = await generator.GenerateResult(
                new EventWrapper(),
                CancellationToken.None);

            Assert.IsType(
                expectedResultType,
                actual);
            Assert.Equal(
                expectedStatusCode,
                actual.StatusCode);
        }
示例#6
0
 public VerifyUrlCommandResult(
     string challenge,
     Guid commandId,
     CommandResultType commandResultType = CommandResultType.Success)
     : base(
         commandId,
         commandResultType)
     => Challenge = challenge;
示例#7
0
        private void RunInteractive()
        {
            LoadCommands();
            LoadGlobalParameterConsumer();
            ShowCopyright();

            Logger.Info("Interactive Mode");

            _consoleThread.IsBackground = true;
            _consoleThread.Name         = "Console Thread";
            _consoleThread.Start();

            while (!_cancellationTokenSource.Token.IsCancellationRequested)
            {
                string line;
                try
                {
                    line = _inputQueue.Take(_cancellationTokenSource.Token);
                }
                catch (OperationCanceledException)
                {
                    line = null;
                }

                if (line == null)
                {
                    // Ctrl+Z, Ctrl+C or error
                    break;
                }

                string[] arguments = Util.ParseTextArguments(line, CliSeparator, '"');
                if (arguments.Length <= 0)
                {
                    Logger.Error($"Invalid input: '{line}'. Type 'help' for a list of available commands.");
                    continue;
                }

                CommandResultType result = ProcessArguments(arguments);
                if (result == CommandResultType.Exit)
                {
                    break;
                }

                if (result == CommandResultType.Continue)
                {
                    continue;
                }

                if (result == CommandResultType.Completed)
                {
                    Logger.Info("Command Completed");
                    continue;
                }
            }

            StopReadConsoleThread();
            ShutdownCommands();
        }
        Handle_Returns_Expected_CommandResult(
            string challenge,
            string expectedChallenge,
            CommandResultType expectedResultType)
        {
            var handler = CreateHandler();

            var actual = await handler.Handle(
                new VerifyUrlCommand(challenge),
                CancellationToken.None);

            Assert.Equal(
                expectedResultType,
                actual.ResultType);
            Assert.Equal(
                expectedChallenge,
                actual.Challenge);
        }
示例#9
0
        public async void ErrorIsExceptionMessage_WhenErrorResult(CommandResultType type)
        {
            request.Params = new object();
            var expected  = "expected";
            var badResult = new CommandResult
            {
                ResultStatus = type,
                ErrorMessage = expected
            };

            var processor = Mock <ICommandProcessor>();

            processor.Setup(r => r.Process(command, request.Params, false))
            .Returns(Task.FromResult(badResult));

            var result = await ClassUnderTest.ExecuteCommand(command, request, clientInfo);

            Assert.Equal(expected, result.error);
        }
示例#10
0
        GenerateResult_Returns_Expected_EndpointResult(
            CommandResultType commandResultType,
            Type expectedResultType,
            int expectedStatusCode)
        {
            const string challenge = "challenge";

            _mediatorMock
            .Setup(
                x => x.Send(
                    It.IsAny <VerifyUrlCommand>(),
                    It.IsAny <CancellationToken>()))
            .Returns(
                Task.FromResult(
                    new VerifyUrlCommandResult(
                        challenge,
                        Guid.NewGuid(),
                        commandResultType)));
            var generator = CreateGenerator();

            var actual = await generator.GenerateResult(
                new UrlVerificationEvent { Challenge = challenge },
                CancellationToken.None);

            Assert.IsType(
                expectedResultType,
                actual);
            Assert.Equal(
                expectedStatusCode,
                actual.StatusCode);
            if (actual is OkEndpointResult <UrlVerificationResponse> okEndpointResult)
            {
                Assert.Equal(
                    challenge,
                    okEndpointResult.BodyContent.Challenge);
            }
        }
示例#11
0
        /// <summary>
        /// Helper to test writing files to various directories and testing the output.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="expectedSuccessFlag"></param>
        /// <param name="resultType"></param>
        protected void TestPluginsIsolationWriteToDirectory(String path, bool expectedSuccessFlag, CommandResultType resultType) {
            var plugins = (CorePluginController)new CorePluginController().Execute();

            plugins.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.PluginsEnable,
                Scope = {
                    PluginGuid = plugins.LoadedPlugins.First().PluginGuid
                }
            });

            ICommandResult result = plugins.Tunnel(new Command() {
                Name = "TestPluginsIsolationWriteToDirectory",
                Authentication = {
                    Username = "******"
                },
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    path
                })
            });

            Assert.IsTrue(result.Success == expectedSuccessFlag);
            Assert.AreEqual(resultType, result.CommandResultType);
        }
 public CommandResult(CommandResultType resultType)
 {
     this.ResultType = resultType;
 }
示例#13
0
 public CommandResult(CommandResultType resultType)
     : this()
 {
     ResultType = resultType;
 }
示例#14
0
 static void SetCommandColor(CommandResultType type)
 {
     switch (type)
     {
         case CommandResultType.Error:
             Console.ForegroundColor = ConsoleColor.Red;
             break;
         case CommandResultType.Verbose:
             Console.ForegroundColor = ConsoleColor.Gray;
             break;
         case CommandResultType.Warning:
             Console.ForegroundColor = ConsoleColor.Yellow;
             break;
     }
 }
示例#15
0
 private CommandResult(CommandResultType resultType, T output, Exception exception)
 {
     ResultType = resultType;
     Output     = output;
     Exception  = exception;
 }
示例#16
0
 public CommandResult(CommandResultType resultType, string error = null)
 {
     Error      = error;
     ResultType = resultType;
 }
示例#17
0
 private CommandResult(CommandResultType type, string?message = null)
 {
     Type    = type;
     Message = message;
 }
示例#18
0
        private ICommandResult Run(CommandAttributeType attributeType, ICommand command, CommandResultType maintainStatus) {

            // Loop through all matching commands with the identical name and type
            foreach (var dispatch in this.CommandDispatchers.Where(dispatch => dispatch.CanDispatch(attributeType, command))) {
                
                // Check if we can build a parameter list.
                Dictionary<String, ICommandParameter> parameters = dispatch.BuildParameterDictionary(command.Parameters);

                if (parameters != null) {
                    command.Result = dispatch.Handler(command, parameters);

                    // Our status has changed, break our loop.
                    if (command.Result.CommandResultType != maintainStatus) {
                        break;
                    }
                }
            }

            return command.Result;
        }