private void WriteToXenStore(string key, string value) { if (RestartManager.RestartNeeded) { if (RestartManager.CommandSetsToRun <= 0) { return; } } _store.Write(key, value); }
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 Should_call_executable_implementation_with_the_right_parameters_when_writing_to_xenstore() { xenStore.Write("name1", "value1"); executable.AssertWasCalled(x => x.Run(Constants.XenClientPath, "write data/guest/name1 value1")); }