/// <summary> /// load as an asynchronous operation. /// </summary> /// <typeparam name="T"></typeparam> /// <returns>Task<T>.</returns> public async Task <T> ReadSettingAsync <T>() where T : class { try { var file = _cloudRootDirectory.GetFileReference(_fileName); if (await file.ExistsAsync()) { var str = await file.DownloadTextAsync(); Log.Debug($"Loading Azure DocumentDb Settings Data (1): {str}"); OnSettingsRead?.Invoke(this, new SettingsLoadingEventArgs() { Data = str }); var settings = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(str); return(settings); } return(null); } finally { } }
/// <summary> /// Loads this instance. /// </summary> /// <typeparam name="T"></typeparam> /// <returns>T.</returns> public T ReadSetting <T>() where T : class { OnSettingsRead?.Invoke(this, new SettingsLoadingEventArgs() { Data = _currentValue }); return(_currentValue); }
public T ReadSetting <T>(string key, T defaultValue = default(T)) { OnSettingsRead?.Invoke(this, new SettingsLoadingEventArgs() { Data = _currentValue }); return(_currentValue[key]); }
/// <summary> /// Loads this instance. /// </summary> /// <typeparam name="T"></typeparam> /// <returns>T.</returns> public T ReadSetting <T>() where T : class { var response = _client.CreateDocumentQuery(_collectionLink).Select(x => x).OrderByDescending(x => x.Timestamp).ToList().FirstOrDefault(); T result; if (response == null) { return(default(T)); } try { if (_jsonSettings != null) { var str = response.ToString(); Log.Debug($"Loading Azure DocumentDb Settings Data (1): {str}"); OnSettingsRead?.Invoke(this, new SettingsLoadingEventArgs() { Data = str }); result = JsonConvert.DeserializeObject <T>(str, _jsonSettings); } else { result = (T)(dynamic)response; } } catch (Exception e) when(_jsonSettings != null) { Log.Warning(e, "Azure DocumentDb Failed to Load"); try { var str = response.ToString(); Log.Debug($"Loading Azure DocumentDb Settings Data (2): {str}"); result = JsonConvert.DeserializeObject <T>(str, _jsonSettings); } catch { throw e; } } return(result); }
public T ReadSetting <T>() where T : class { if (!System.IO.File.Exists(_fileName)) { return(default(T)); } var str = System.IO.File.ReadAllText(_fileName); Log.Debug($"Loading JsonNet Settings Data: {str}"); OnSettingsRead?.Invoke(this, new SettingsLoadingEventArgs() { Data = str }); var settings = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(str, _jsonSettings); return(settings); }