/// <summary> /// Gets the settings for where to display the web chat feature /// </summary> /// <returns></returns> public async Task <WebChatSettings> ReadWebChatSettings() { if (_apiUrl == null) { return(new WebChatSettings()); } try { var cachedSettings = _cache?.ReadFromCache("WebChatSettingsUrl"); if (cachedSettings != null) { return(cachedSettings); } if (_httpClient == null) { _httpClient = _httpClientProvider.GetHttpClient(); } var json = await _httpClient.GetStringAsync(_apiUrl).ConfigureAwait(false); var settings = JsonConvert.DeserializeObject <WebChatSettings>(json); _cache?.AddToCache("WebChatSettingsUrl", settings); return(settings); } catch (Exception exception) { // catch, report and suppress errors because we never want a check for web chat support to stop a page from loading exception.Data.Add("URL", _apiUrl.ToString()); exception.ToExceptionless().Submit(); return(new WebChatSettings()); } }
/// <summary> /// Gets the settings for where to display the web chat feature /// </summary> /// <returns></returns> public WebChatSettings ReadWebChatSettings() { try { var cachedSettings = _cache?.ReadFromCache("WebChatSettingsUrl"); if (cachedSettings != null) { return(cachedSettings); } var client = new WebClient(); if (_proxyProvider != null) { client.Proxy = _proxyProvider.CreateProxy(); } var json = Task.Run(async() => await client.DownloadStringTaskAsync(_apiUrl)).Result; var settings = JsonConvert.DeserializeObject <WebChatSettings>(json); _cache?.AddToCache("WebChatSettingsUrl", settings); return(settings); } catch (Exception exception) { // catch, report and suppress errors because we never want a check for web chat support to stop a page from loading var data = new Dictionary <string, object> { { "URL", _apiUrl.ToString() } }; exception.ToExceptionless(true, data).Submit(); return(new WebChatSettings()); } }