Beispiel #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));
            }
        }
Beispiel #2
0
        public ZipatoFixture()
        {
            // Set the default culture.
            CultureInfo.CurrentCulture = new CultureInfo("en-US");

            var loggerFactory = new LoggerFactory();
            var logger        = loggerFactory.CreateLogger <Zipato>();

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(AppContext.BaseDirectory)
                                .AddJsonFile("appsettings.json", false, false)
                                .AddUserSecrets <Startup>(true)
                                .Build();

            configuration.GetSection("AppSettings").Bind(Settings);

            var client = new ZipatoClient(new HttpClient()
            {
                BaseAddress = new Uri(Settings.BaseAddress),
                Timeout     = TimeSpan.FromSeconds(Settings.Timeout)
            }, Settings, loggerFactory.CreateLogger <ZipatoClient>());

            Zipato = new Zipato(logger, client, Settings);
        }
Beispiel #3
0
 public void TestProperty(string property)
 {
     Assert.True(Zipato.IsProperty(property));
     Assert.NotNull(_zipato.GetPropertyValue(property));
 }