private static string GetEnvironmentSettingValue(string key) { // Get value from Cloud Services (if it throws, just ignore) try { var cloudKey = key.Replace(':', '-'); // no ':' supported in cloud services if (SafeRoleEnvironment.TryGetConfigurationSettingValue(cloudKey, out var configValue)) { return(configValue); } } catch { } // Get value from environment/appsettings var value = Environment.GetEnvironmentVariable(key) ?? ConfigurationManager.AppSettings[key]; if (value != null) { return(value); } throw new KeyNotFoundException($"{key} was not found in the environment settings."); }
string AzureConfigurationSourceReplacementExample() { #region azure-configuration-source-replacement var sectionName = "mySection"; var attributeName = "myAttribute"; string value; if (SafeRoleEnvironment.IsAvailable) { var key = sectionName + "." + attributeName; value = SafeRoleEnvironment.GetConfigurationSettingValue(key); } else { var section = ConfigurationResolver.GetConfigurationHandler() .GetSection(sectionName) as MyConfigurationSection; value = section.MyAttribute; } // return value; // value for mySection.myAttribute #endregion return(value); }
public string GetSetting(string name) { if (!SafeRoleEnvironment.IsAvailable) { return(string.Empty); } return(SafeRoleEnvironment.GetConfigurationSettingValue(name)); }
public bool TryGetSetting(string name, out string setting) { setting = null; if (!SafeRoleEnvironment.IsAvailable) { return(false); } return(SafeRoleEnvironment.TryGetConfigurationSettingValue(name, out setting)); }