Exemplo n.º 1
0
        public async Task <IActionResult> GetFroniusData(string name, bool update = false)
        {
            if (string.IsNullOrEmpty(name))
            {
                _logger?.LogDebug($"GetFroniusData() invalid property.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid."));
            }

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

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

                    if (update)
                    {
                        var status = await _fronius.ReadPropertyAsync(name);

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

                    return(Ok(_fronius.GetPropertyValue(name)));
                }
                else
                {
                    _logger?.LogDebug($"GetFroniusData('{name}') property not found.");
                    return(NotFound($"Property '{name}' not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Exemplo n.º 2
0
 public void TestProperty(string property)
 {
     Assert.True(Fronius.IsProperty(property));
     Assert.NotNull(_fronius.GetPropertyValue(property));
 }