Beispiel #1
0
        /// <summary>
        /// Retrieves a string setting value using a string key name from the configuration hub.  If there is a fallback provider registered
        /// for strings then this fallback provider will be called.  If the default appconfig provider is registerd this will also be called.
        /// </summary>
        /// <param name="settingName">The key identifying the setting</param>
        /// <param name="mustBePresent">Boolean, defaults to false.  Set to true if an exception should be thrown if no value can be found.</param>
        /// <returns>A string based value indicating the setting</returns>
        public string GetSetting(string settingName, bool mustBePresent = false, bool isEncrypted = false)
        {
            b.Info.Flow($"{settingName},{mustBePresent}");
            string val = null;

            if (functionList.ContainsKey(settingName))
            {
                b.Verbose.Log($"Direct Retrieval Funcation Call Made");
                val = functionList[settingName]();
            }

            if (val == null)
            {
                foreach (var v in fallbackList1)
                {
                    b.Verbose.Log($"Fallback Function Call");

                    val = v(settingName);
                    if (val != null)
                    {
                        b.Verbose.Log($"Value Found {val}");
                        break;
                    }
                }
            }

            if ((val != null) && (isEncrypted))
            {
                b.Verbose.Log("Encrypted - Running through registered decryptor");
                val = CryptoProvider.DecryptValue(val);
            }

            if ((val == null) && (mustBePresent))
            {
                b.Warning.Log("Value not matched, and must be present set - throwing exception");
                throw new ConfigHubMissingConfigException($"The setting {settingName ?? "null"} must be present and have a value.");
            }

            b.Verbose.Log($"{settingName}={val}");
            return(val);
        }