public async Task <bool> ReadValueAsync(RegistryBaseKey baseKey, string key, string valueName, bool defaultValue) { var command = new RegistryReadIntValueCommand(baseKey, key, valueName, defaultValue ? 1 : 0); IServiceCommandResponse response = await _commandBridge.SendCommandAsync(command); response.ThrowIfError(); return((int)response.Result != 0); }
public void RegistryReadValueCommand_should_serialize_correctly() { var command = new RegistryReadIntValueCommand(RegistryBaseKey.CurrentUser, "Key", "ValueName", 123); var valueSet = new Dictionary <string, object>(); command.SerializeToValueSet(valueSet); valueSet.Select(pair => ((ParamName)Enum.Parse(typeof(ParamName), pair.Key), pair.Value)) .Should() .BeEquivalentTo( new (ParamName, object)[]
private static bool TryDeserialize( BridgeMessageDeserializer deserializer, out IServiceCommand command, out IServiceCommandResponse errorResponse) { switch (deserializer.CommandName) { case ServiceCommandName.ShutdownServer: command = new ShutdownServerCommand(); break; case ServiceCommandName.Echo: command = new EchoCommand(deserializer); break; case ServiceCommandName.RegistryReadIntValue: command = new RegistryReadIntValueCommand(deserializer); break; case ServiceCommandName.RegistryReadStringValue: command = new RegistryReadStringValueCommand(deserializer); break; case ServiceCommandName.RegistryWriteIntValue: command = new RegistryWriteIntValueCommand(deserializer); break; case ServiceCommandName.RegistryWriteStringValue: command = new RegistryWriteStringValueCommand(deserializer); break; case ServiceCommandName.Unknown: default: throw new InvalidOperationException( "This should be unreachable because the deserializer should have detected an invalid command name"); } if (deserializer.HadError) { command = null; } errorResponse = deserializer.LastError; return(!deserializer.HadError); }
public void SerializeToJsonString_should_serialize_into_compact_JSON() { var command = new RegistryReadIntValueCommand(RegistryBaseKey.CurrentUser, "SubPath", "IntValue", 123); string expectedJson = $@" {{ ""{ParamName.CommandName}"": ""{ServiceCommandName.RegistryReadIntValue}"", ""{ParamName.RegistryBaseKey}"": ""{RegistryBaseKey.CurrentUser}"", ""{ParamName.RegistryKey}"": ""SubPath"", ""{ParamName.RegistryValueName}"": ""IntValue"", ""{ParamName.RegistryDefaultValue}"": 123 }} "; expectedJson = expectedJson.Replace("\r", "") .Replace("\n", "") .Replace(" ", ""); command.SerializeToJsonString().Should().Be(expectedJson); }