//// =========================================================================================================== //// Methods //// =========================================================================================================== public async Task <IServiceCommandResponse> SendCommandAsync(IServiceCommand command) { var valueSet = new ValueSet(); command.SerializeToValueSet(valueSet); AppServiceResponse bridgeResponse = await _connection.SendMessageAsync(valueSet); AppServiceResponseStatus status = bridgeResponse.Status; IServiceCommandResponse response; if (status == AppServiceResponseStatus.Success) { if (!ServiceCommandResponse.TryDeserializeFromValueSet( bridgeResponse.Message, out response, out IServiceCommandResponse errorResponse)) { response = errorResponse; } } else { response = ServiceCommandResponse.CreateError(command.CommandName, ServiceErrorInfo.InternalError($"AppServiceConnection failed with status '{status}'")); } return(response); }
public void CreateError_should_store_the_properties() { var response = ServiceCommandResponse.CreateError( ServiceCommandName.RegistryReadIntValue, ServiceErrorInfo.InternalError("message")); response.CommandName.Should().Be(ServiceCommandName.RegistryReadIntValue); response.Result.Should().BeNull(); response.ErrorCode.Should().Be(ServiceCommandErrorCode.InternalError); response.ErrorMessage.Should().NotBeNull(); }
public IServiceCommandResponse Execute(IServiceCommand command) { IServiceCommandResponse response; _logger.LogDebug("Executing command: ", command.ToDebugString()); switch (command) { case ShutdownServerCommand _: response = ServiceCommandResponse.Create(ServiceCommandName.ShutdownServer, true); break; case EchoCommand echoCommand: response = ServiceCommandResponse.Create(ServiceCommandName.Echo, echoCommand.EchoMessage); break; case RegistryReadIntValueCommand registryCommand: response = _registryExecutor.ExecuteRead(registryCommand, _logger); break; case RegistryReadStringValueCommand registryCommand: response = _registryExecutor.ExecuteRead(registryCommand, _logger); break; case RegistryWriteIntValueCommand registryCommand: response = _registryExecutor.ExecuteWrite(registryCommand, _logger); break; default: _logger.LogWarning("Unsupported command: ", command.CommandName); response = ServiceCommandResponse.CreateError( command.CommandName, ServiceErrorInfo.InternalError( $"Command '{command.CommandName}' is not supported for execution in the elevated bridge application.")); break; } return(response); }