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

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

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

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

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

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

            Fronius.ReadAllAsync().Wait();
        }
示例#2
0
        public async Task TestFroniusReadProperty(string property)
        {
            Assert.True(Fronius.IsProperty(property));
            var status = await _fronius.ReadPropertyAsync(property);

            Assert.True(status.IsGood);
        }
示例#3
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));
            }
        }
示例#4
0
 public void TestProperty(string property)
 {
     Assert.True(Fronius.IsProperty(property));
     Assert.NotNull(_fronius.GetPropertyValue(property));
 }