Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        public async Task TestFroniusReadProperty(string property)
        {
            Assert.True(Fronius.IsProperty(property));
            var status = await _fronius.ReadPropertyAsync(property);

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