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

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

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

                        var status = await _zipato.ReadPropertyAsync(name);

                        if (status != DataValue.Good)
                        {
                            return(StatusCode(StatusCodes.Status502BadGateway, status));
                        }
                    }

                    return(Ok(_zipato.GetPropertyValue(name)));
                }
                else
                {
                    _logger?.LogDebug($"GetData('{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(Zipato.IsProperty(property));
     Assert.NotNull(_zipato.GetPropertyValue(property));
 }