/// <summary> /// Helper method to check options. /// </summary> /// <param name="app"></param> /// <returns>True if options are OK.</returns> private bool CheckOptions(CommandLineApplication app) { if (Property.Length > 0) { if (!SYMO823MData.IsProperty(Property)) { _logger?.LogError($"The property '{Property}' has not been found."); return(false); } if (!SYMO823MData.IsWritable(Property)) { _logger?.LogError($"The property '{Property}' is not writable."); return(false); } if (string.IsNullOrEmpty(Value)) { _logger?.LogError($"The value '{Value}' for the property '{Property}' is invalid."); return(false); } } return(true); }
public async Task TestSYMO823MWriteProperty(string property, string data) { Assert.True(SYMO823MData.IsProperty(property)); Assert.True(SYMO823MData.IsWritable(property)); var status = await _symo823m.WritePropertyAsync(property, data); Assert.True(status.IsGood); }
public async Task TestSYMO823MReadProperty(string property) { Assert.True(SYMO823MData.IsProperty(property)); Assert.True(SYMO823MData.IsReadable(property)); var status = await _symo823m.ReadPropertyAsync(property); Assert.True(status.IsGood); }
public async Task <IActionResult> PutSYMO823MData(string name, [FromQuery] string value) { if (string.IsNullOrEmpty(name)) { _logger?.LogDebug($"PutSYMO823MData({name}, {value}) invalid property."); return(StatusCode(StatusCodes.Status400BadRequest, $"Property name is invalid.")); } if (string.IsNullOrEmpty(value)) { _logger?.LogDebug($"PutSYMO823MData({name}, {value}) invalid value."); return(StatusCode(StatusCodes.Status400BadRequest, $"Property value is invalid.")); } try { _logger?.LogDebug($"PutSYMO823MData({name}, {value})..."); if (SYMO823MData.IsProperty(name)) { if (SYMO823MData.IsWritable(name)) { if (!_symo823m.IsLocked) { return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished.")); } var status = await _symo823m.WritePropertyAsync(name, value); if (!status.IsGood) { return(StatusCode(StatusCodes.Status502BadGateway, status)); } return(Ok()); } else { _logger?.LogDebug($"PutSYMO823MData('{name}, {value}') property not writable."); return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Property '{name}' not writable.")); } } else { _logger?.LogDebug($"PutSYMO823MData('{name}, {value}') property not found."); return(NotFound($"Property '{name}' not found.")); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public async Task <IActionResult> GetSYMO823MData(string name, bool update = false) { if (string.IsNullOrEmpty(name)) { _logger?.LogDebug($"GetSYMO823MData() invalid property."); return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid.")); } try { _logger?.LogDebug($"GetSYMO823MData({name})..."); if (SYMO823MData.IsProperty(name)) { if (update) { if (SYMO823MData.IsReadable(name)) { if (!_symo823m.IsLocked) { return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished.")); } var status = await _symo823m.ReadPropertyAsync(name); if (!status.IsGood) { return(StatusCode(StatusCodes.Status502BadGateway, status)); } } else { _logger?.LogDebug($"GetSYMO823MData('{name}') property not readable."); return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Property '{name}' not readable.")); } } return(Ok(_symo823m.GetPropertyValue(name))); } else { _logger?.LogDebug($"GetSYMO823MData('{name}') property not found."); return(NotFound($"Property '{name}' not found.")); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
/// <summary> /// Helper method to check options. /// </summary> /// <param name="app"></param> /// <returns>True if options are OK.</returns> private bool CheckOptions(CommandLineApplication app) { if (Property.Length > 0) { if (!SYMO823MData.IsProperty(Property)) { _logger?.LogError($"The property '{Property}' has not been found."); return(false); } if (!SYMO823MData.IsReadable(Property)) { _logger?.LogError($"The property '{Property}' is not readable."); return(false); } } return(true); }