private void ProcessCommand(Command command)
        {
            var removeMessageFromXenStore = true;

            try {
                var executableResult = _factory.CreateCommand(command.name).Execute(command.value);
                _store.Write(command.key, new Json<object>().Serialize(new { returncode = executableResult.ExitCode, message = executableResult.Output.Value() }));
            } catch (InvalidCommandException exception) {
                _store.Write(command.key, new Json<object>().Serialize(new { returncode = "1", message = exception.Message }));
            } catch (UnsuccessfulCommandExecutionException exception) {
                var result = (ExecutableResult) exception.Data["result"];
                var output = "";
                var error = "";
                if (result.Output != null && !string.IsNullOrEmpty(result.Output.Value()))
                    output = ", Output:" + result.Output.Value();
                if (result.Error != null && !string.IsNullOrEmpty(result.Error.Value()))
                    error = ", Error:" + result.Error.Value();
                _store.Write(command.key, new Json<object>().Serialize(new
                                                                           {
                                                                               returncode = result.ExitCode,
                                                                               message = exception.Message +
                                                                               output + error
                                                                           }));
            } catch(Exception ex) {
                removeMessageFromXenStore = false;
                _logger.Log(String.Format("Exception was : {0}\nStackTrace Was: {1}", ex.Message, ex.StackTrace));
            } finally {
                if (removeMessageFromXenStore) _store.Remove(command.key);
            }
        }
        public void Setup()
        {
            CreateContext();

            command = new Command { key = "key1", name = "12345", value = "Valuewrong" };
            XenSetup(command);
            executableCommand.Stub(x => x.Execute(Arg<string>.Is.Anything)).Return(new ExecutableResult { ExitCode = "0", Error = new List<string>() });
            commandFactory.Stub(x => x.CreateCommand(Arg<string>.Is.Anything)).Return(executableCommand);

            commandQueue.Work();
        }
 public ExecutableResult Execute(IExecutableCommand commandExecutable, Command command)
 {
     runInSafeBlock(SvcConfiguration.PreHookPath(command.name));
     var result = commandExecutable.Execute(command.value);
     if (result.ExitCode == "0")
     {
         runInSafeBlock(SvcConfiguration.PostHookPath(command.name));
     }
     else
     {
         _logger.Log(string.Format("Bypassing post command hook, received an exit code of {0} from the command {1}", result.ExitCode, command.name));
     }
     return result;
 }
コード例 #4
0
        public void should_serialize_partially_filled_object_to_json()
        {
            var command = new Command {name = "password", value = "somepassword"};

            Assert.AreEqual(_fullJsonStringWithObjectPartiallyPopulated, _jsonCommand.Serialize(command));
        }
 public void Setup()
 {
     CreateContext();
     xenStore.GetMockRepository().Ordered();
     xendata = new Command { key = "key1", name = "BadCommand", value = "Valuewrong" };
     XenSetup(xendata);
     commandFactory.Stub(x => x.CreateCommand(Arg<string>.Is.Anything)).Throw(new InvalidCommandException("BadCommand"));
 }
 public void Setup()
 {
     CreateContext();
     firstcommand = new Command { key = "key1", name = "Command1", value = "12345" };
     secondcommand = new Command { key = "key2", name = "Command2", value = "23456" };
     XenSetup(firstcommand, secondcommand);
     executableCommand.Stub(x => x.Execute(Arg<string>.Is.Anything)).Return(new ExecutableResult { ExitCode = "0", Error = new List<string> { "Error1" } });
     commandFactory.Stub(x => x.CreateCommand(Arg<string>.Is.Anything)).Return(executableCommand);
     commandQueue.Work();
 }