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.");
        }
Exemplo n.º 2
0
        public bool TryGetSetting(string name, out string setting)
        {
            setting = null;

            if (!SafeRoleEnvironment.IsAvailable)
            {
                return(false);
            }

            return(SafeRoleEnvironment.TryGetConfigurationSettingValue(name, out setting));
        }