public EM300LRFixture()
        {
            // Set the default culture.
            CultureInfo.CurrentCulture = new CultureInfo("en-US");

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

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

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

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

            EM300LR = new EM300LR(logger, client, Settings);

            EM300LR.ReadAllAsync().Wait();
        }
示例#2
0
        public async Task <IActionResult> GetEM300LRData(string name, bool update = false)
        {
            if (string.IsNullOrEmpty(name))
            {
                _logger?.LogDebug($"GetEM300LRData() invalid property.");
                return(StatusCode(StatusCodes.Status400BadRequest, $"Property is invalid."));
            }

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

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

                    if (update)
                    {
                        var status = await _em300lr.ReadAllAsync();

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

                    return(Ok(_em300lr.GetPropertyValue(name)));
                }
                else
                {
                    _logger?.LogDebug($"GetEM300LRData('{name}') property not found.");
                    return(NotFound($"Property '{name}' not found."));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
示例#3
0
 public void TestProperty(string property)
 {
     Assert.True(EM300LR.IsProperty(property));
     Assert.NotNull(_em300lr.GetPropertyValue(property));
 }