Beispiel #1
0
        private async Task UpdateVariables(ForeignExchangeRatesDevice device)
        {
            try
            {
                var url    = "http://api.fixer.io/latest?base=" + device.IsoCode.ToUpperInvariant();
                var client = _httpClientProvider.Get();
                var json   = await client.GetStringAsync(url);

                var dto = JsonConvert.DeserializeObject <FixerDto>(json);

                device.Rates.Clear();
                device.LastUpdate = dto.Date;
                _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "LastUpdate", dto.Date));

                foreach (var rate in dto.Rates)
                {
                    device.Rates[rate.Key] = rate.Value;
                    _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, rate.Key, rate.Value));
                }
            }
            catch (Exception e)
            {
                _log.Error(e.Message, e);
            }
        }
Beispiel #2
0
        //-----------------------------
        public async Task <IActionResult> Details(int?id) // z HomeControler
        {
            Book book = await _httpClientProvider.Get(id ?? 1);

            HomeDetailsViewModel homeDetailsViewModel = new
                                                        HomeDetailsViewModel()
            {
                Id         = book.Id,
                Cover      = book.Cover,
                Date       = book.Date,
                ItemType   = book.ItemType,
                Title      = book.Title,
                AuthorName = book.AuthorName,
                Status     = book.Status,
            };

            return(View(homeDetailsViewModel));
        }
        private async Task <string> GetStationCallSignAsync(string stationId)
        {
            var result = await _httpClientProvider.Get().GetStringAsync("http://opml.radiotime.com/Describe.ashx?id=" + stationId);

            var document = new XmlDocument();

            document.LoadXml(result);

            var status = document.SelectSingleNode("/opml/head/status")?.InnerText;

            if (string.IsNullOrEmpty(status) || status != "200")
            {
                return(null);
            }

            var callSign = document.SelectSingleNode("/opml/body/outline/station/call_sign")?.InnerText;

            return(Uri.EscapeDataString(callSign));
        }
Beispiel #4
0
        public SermonHosedService(ILogger <SermonHosedService> logger,
                                  IHttpClientProvider httpClientProvider,
                                  IServicesInfoProvider servicesInfoProvider,
                                  IMemoryCache memoryCache)
        {
            _logger = logger;
            _servicesInfoProvider = servicesInfoProvider;
            _memoryCache          = memoryCache;
            _httpClient           = httpClientProvider.Get();

            _timerInterval = int.TryParse(Environment.GetEnvironmentVariable("SERMON_CHECK_INTERVAL_S"), out var s)
                ? s
                : DEFAULT_CHECK_INTERVAL_S;
            _logger.LogInformation($"_timerInterval = {_timerInterval}s");
        }
Beispiel #5
0
        /// <summary>
        /// The awaiter that enables a SolidHttpRequest to be awaited
        /// </summary>
        /// <returns>A TaskAwaiter for an HttpResponseMessage</returns>
        public TaskAwaiter <HttpResponseMessage> GetAwaiter()
        {
            Func <SolidHttpRequest, Task <HttpResponseMessage> > waiter = (async r =>
            {
                if (BaseResponse == null)
                {
                    await _onHttpRequestAsync.InvokeAllAsync(Services, BaseRequest);
                    var http = _httpClientProvider.Get(BaseRequest.RequestUri);
                    BaseResponse = await http.SendAsync(BaseRequest, CancellationToken);
                    await _onHttpResponseAsync.InvokeAllAsync(Services, BaseResponse);
                }
                return(BaseResponse);
            });

            return(waiter(this).GetAwaiter());
        }
Beispiel #6
0
 public MZCRCovidInfoProvider(ILogger <MZCRCovidInfoProvider> logger,
                              IHttpClientProvider httpClientProvider)
 {
     _logger     = logger;
     _httpClient = httpClientProvider.Get();
 }