public override Task <WeatherData> GetDataAsync(CancellationToken cancellationToken)
        {
            var random         = new Random();
            int maxTemperature = int.Parse(ConfigProvider.GetConfigEntry("TestWeatherPlugin:MaxTemp"));

            return(Task.FromResult(new WeatherData(random.Next(-8, maxTemperature), random.Next(1, 100), Status.OK)));
        }
Example #2
0
        public override Task InitializeAsync()
        {
            _apiKey       = ConfigProvider.GetConfigEntry($"{RootConfig}:ApiKey");
            _cityId       = ConfigProvider.GetConfigEntry($"{RootConfig}:CityId");
            _cronSchedule = ConfigProvider.GetConfigEntry($"{RootConfig}:CronSchedule");
            _tileName     = ConfigProvider.GetConfigEntry($"{RootConfig}:TileName");

            return(Task.CompletedTask);
        }
        private HttpRequestMessage CreateHttpRequest()
        {
            var username = ConfigProvider.GetConfigEntry($"{RootConfig}:UserName");
            var password = ConfigProvider.GetConfigEntry($"{RootConfig}:Password");
            var request  = new HttpRequestMessage(HttpMethod.Get, ConfigProvider.GetConfigEntry($"{RootConfig}:HeartBeatAddress"));

            request.Headers.Add("Authorization", $"Basic {Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))}");

            return(request);
        }
        public override async Task <HeartBeatData> GetDataAsync(CancellationToken cancellationToken = default)
        {
            var httpClient  = new HttpClient();
            var stopwatcher = new Stopwatch();

            stopwatcher.Start();
            try
            {
                var response = await httpClient.GetAsync($"{ConfigProvider.GetConfigEntry($"{RootConfig}:HeartBeatAddress")}", cancellationToken);

                stopwatcher.Stop();
                if (response.IsSuccessStatusCode)
                {
                    return(new HeartBeatData((int)stopwatcher.ElapsedMilliseconds, Status.OK));
                }

                return(new HeartBeatData(0, Status.OK));
            }
            catch (Exception ex)
            {
                return(HeartBeatData.Error(ex.Message + ex.InnerException.Message));
            }
        }