コード例 #1
0
        /// <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 (!ETAPU11Data.IsProperty(Property))
                {
                    _logger?.LogError($"The property '{Property}' has not been found.");
                    return(false);
                }

                if (!ETAPU11Data.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);
        }
コード例 #2
0
ファイル: TestWrite.cs プロジェクト: polytronicgr/HomeControl
        public async Task TestETAPU11WriteProperty(string property, string data)
        {
            Assert.True(ETAPU11Data.IsProperty(property));
            Assert.True(ETAPU11Data.IsWritable(property));
            var status = await _etapu11.WritePropertyAsync(property, data);

            Assert.True(status.IsGood);
        }
コード例 #3
0
        public async Task <IActionResult> PutETAPU11Data(string name, [FromQuery] string value)
        {
            if (string.IsNullOrEmpty(name))
            {
                _logger?.LogDebug($"PutETAPU11Data({name}, {value}) invalid property.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property name is invalid."));
            }

            if (string.IsNullOrEmpty(value))
            {
                _logger?.LogDebug($"PutETAPU11Data({name}, {value}) invalid value.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property value is invalid."));
            }

            try
            {
                _logger?.LogDebug($"PutETAPU11Data({name}, {value})...");

                if (ETAPU11Data.IsProperty(name))
                {
                    if (ETAPU11Data.IsWritable(name))
                    {
                        if (!_etapu11.IsLocked)
                        {
                            return(StatusCode(StatusCodes.Status406NotAcceptable, "Locked: update not yet finished."));
                        }

                        var status = await _etapu11.WritePropertyAsync(name, value);

                        if (!status.IsGood)
                        {
                            return(StatusCode(StatusCodes.Status502BadGateway, status));
                        }

                        return(Ok());
                    }
                    else
                    {
                        _logger?.LogDebug($"PutETAPU11Data('{name}, {value}') property not writable.");
                        return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Property '{name}' not writable."));
                    }
                }
                else
                {
                    _logger?.LogDebug($"PutETAPU11Data('{name}, {value}') property not found.");
                    return(NotFound($"Property '{name}' not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }