private static string GetProviderNameFromConnectionString() { var connectionStringProvider = ConfigUtility.GetConnectionString().ProviderName; if (string.IsNullOrEmpty(connectionStringProvider)) { throw new FrameworkException("Missing 'providerName' attribute in 'ServerConnectionString' connection string. Expected providerName format is 'Rhetos.<database language>' or 'Rhetos.<database language>.<natural language settings>', for example 'Rhetos.MsSql' or 'Rhetos.Oracle.XGERMAN_CI'."); } return(connectionStringProvider); }
public Lazy <bool> GetBool(string key, bool defaultValue) { return(new Lazy <bool>(() => { string value = ConfigUtility.GetAppSetting(key); if (!string.IsNullOrEmpty(value)) { if (bool.TryParse(value, out bool result)) { return result; } throw new FrameworkException("Invalid '" + key + "' parameter in configuration file: '" + value + "' is not a boolean value. Allowed values are True and False."); } else { return defaultValue; } })); }
public Lazy <int> GetInt(string key, int defaultValue) { return(new Lazy <int>(() => { string value = ConfigUtility.GetAppSetting(key); if (!string.IsNullOrEmpty(value)) { if (int.TryParse(value, out int result)) { return result; } throw new FrameworkException("Invalid '" + key + "' parameter in configuration file: '" + value + "' is not an integer value."); } else { return defaultValue; } })); }
public Lazy <T> GetEnum <T>(string key, T defaultValue) where T : struct { return(new Lazy <T>(() => { var value = ConfigUtility.GetAppSetting(key); if (!string.IsNullOrEmpty(value)) { if (Enum.TryParse(value, true, out T parsedValue)) { return parsedValue; } else { throw new FrameworkException( $"Invalid '{key}' parameter in configuration file: '{value}' is not a valid value." + $" Allowed values are: {string.Join(", ", Enum.GetNames(typeof(T)))}."); } } else { return defaultValue; } })); }
public Lazy <string> GetString(string key, string defaultValue) { return(new Lazy <string>(() => ConfigUtility.GetAppSetting(key) ?? defaultValue)); }