Ejemplo n.º 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 (!KWLEC200Data.IsProperty(Property))
                {
                    _logger?.LogError($"The property '{Property}' has not been found.");
                    return(false);
                }

                if (!KWLEC200Data.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);
        }
Ejemplo n.º 2
0
        // SensorConfig1 is not writable.
        // SensorConfig2 is not writable.
        // SensorConfig3 is not writable.
        // SensorConfig4 is not writable.
        // SensorConfig5 is not writable.
        // SensorConfig6 is not writable.
        // SensorConfig7 is not writable.
        // SensorConfig8 is not writable.
        public void TestKWLEC200WriteProperty(string property, string data)
        {
            Assert.True(KWLEC200Data.IsProperty(property));
            Assert.True(KWLEC200Data.IsWritable(property));
            var status = _kwlec200.WriteProperty(property, data);

            Assert.True(status.IsGood);
        }
Ejemplo n.º 3
0
        public IActionResult PutKWLEC200Data(string name, [FromQuery] string value)
        {
            if (string.IsNullOrEmpty(name))
            {
                _logger?.LogDebug($"PutKWLEC200Data({name}, {value}) invalid property.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property name is invalid."));
            }

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

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

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

                        var status = _kwlec200.WriteProperty(name, value);

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

                        return(Ok());
                    }
                    else
                    {
                        _logger?.LogDebug($"PutKWLEC200Data('{name}, {value}') property not writable.");
                        return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Property '{name}' not writable."));
                    }
                }
                else
                {
                    _logger?.LogDebug($"PutKWLEC200Data('{name}, {value}') property not found.");
                    return(NotFound($"Property '{name}' not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Helper method to read the property value from the storage.
        /// </summary>
        /// <param name="property">The property name.</param>
        /// <param name="command">The raw command string.</param>
        public void UpdateData(string property, string command)
        {
            if (!string.IsNullOrEmpty(property))
            {
                if (KWLEC200Data.IsProperty(property))
                {
                    if (KWLEC200Data.IsWritable(property))
                    {
                        object value = Data.GetPropertyValue(property);
                        string name  = KWLEC200Data.GetName(property);
                        ushort size  = KWLEC200Data.GetSize(property);
                        ushort count = KWLEC200Data.GetCount(property);

                        _logger?.LogDebug($"Property '{property}' => Type: {value.GetType()}, Name: {name}, Size: {size}, Count: {count}.");

                        if (value is bool)
                        {
                            var(data, status) = Helios.ParseBoolData(name, size, count, command);

                            if (status.IsGood)
                            {
                                Data.SetPropertyValue(property, data);
                            }
                        }
                        else if (value is int)
                        {
                            var(data, status) = Helios.ParseIntegerData(name, size, count, command);

                            if (status.IsGood)
                            {
                                Data.SetPropertyValue(property, data);
                            }
                        }
                        else if (value is double)
                        {
                            var(data, status) = Helios.ParseDoubleData(name, size, count, command);

                            if (status.IsGood)
                            {
                                Data.SetPropertyValue(property, data);
                            }
                        }
                        else if (value is DateTime)
                        {
                            var(data, status) = Helios.ParseDateData(name, size, count, command);

                            if (status.IsGood)
                            {
                                Data.SetPropertyValue(property, data);
                            }
                        }
                        else if (value is TimeSpan)
                        {
                            var(data, status) = Helios.ParseTimeData(name, size, count, command);

                            if (status.IsGood)
                            {
                                Data.SetPropertyValue(property, data);
                            }
                        }
                        else if (value.GetType().IsEnum)
                        {
                            var(data, status) = Helios.ParseIntegerData(name, size, count, command);

                            if (status.IsGood)
                            {
                                Data.SetPropertyValue(property, data);
                            }
                        }
                        else if (value is string)
                        {
                            var(data, status) = Helios.ParseStringData(name, size, count, command);

                            if (status.IsGood)
                            {
                                Data.SetPropertyValue(property, data);
                            }
                        }
                    }
                    else
                    {
                        _logger?.LogDebug($"UpdateData property '{property}' not writable.");
                    }
                }
                else
                {
                    _logger?.LogWarning($"UpdateData property '{property}' not found.");
                }
            }
            else
            {
                _logger?.LogError($"UpdateData property invalid.");
            }
        }