コード例 #1
0
        public async Task TestETAPU11ReadProperty(string property)
        {
            Assert.True(ETAPU11Data.IsProperty(property));
            Assert.True(ETAPU11Data.IsReadable(property));
            var status = await _etapu11.ReadPropertyAsync(property);

            Assert.True(status.IsGood);
        }
コード例 #2
0
        public async Task <IActionResult> GetETAPU11Data(string name, bool update = false)
        {
            if (string.IsNullOrEmpty(name))
            {
                _logger?.LogDebug($"GetETAPU11Data() invalid property.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid."));
            }

            try
            {
                _logger?.LogDebug($"GetETAPU11Data({name})...");

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

                            var status = await _etapu11.ReadPropertyAsync(name);

                            if (status.IsGood)
                            {
                                return(StatusCode(StatusCodes.Status502BadGateway, status));
                            }
                        }
                        else
                        {
                            _logger?.LogDebug($"GetETAPU11Data('{name}') property not readable.");
                            return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Property '{name}' not readable."));
                        }
                    }

                    return(Ok(_etapu11.GetPropertyValue(name)));
                }
                else
                {
                    _logger?.LogDebug($"GetETAPU11Data('{name}') property not found.");
                    return(NotFound($"Property '{name}' not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
コード例 #3
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.IsReadable(Property))
                {
                    _logger?.LogError($"The property '{Property}' is not readable.");
                    return(false);
                }
            }

            return(true);
        }