public static string Validate(AppSettingsKey key, string value) => (key, value) switch { (_, null) => "Value should not be null or empty", (AppSettingsKey.Unknown, _) => "Unknown settings key", (AppSettingsKey.ImportantDaysScopeId, _)when value != "" && !Guid.TryParse(value, out _) => "ScopeId value is not a correct GUID", (AppSettingsKey.ImportantDaysDisplayRange, _)when !int.TryParse(value, out _) => "Range value should be set as int", (AppSettingsKey.ImportantDaysDisplayRange, _) => int.Parse(value) <= 1 ? "Range value must be greater than 1" : int.Parse(value) > 30 ? "Range value must be less than 30" : "", (AppSettingsKey.StartPageRecordId, _)when value != "" && !Guid.TryParse(value, out _) => "RecordId value is not a correct GUID", (AppSettingsKey.ImageQuality, _)when !int.TryParse(value, out _) => "Image Quality value should be set as int", (AppSettingsKey.ImageQuality, _) => int.Parse(value) <= 0 ? "Image Quality value must be greater than 0" : int.Parse(value) > 100 ? "Image Quality value must be less than 100" : "", (AppSettingsKey.ThumbnailSize, _)when !int.TryParse(value, out _) => "Value should be set as int", (AppSettingsKey.ThumbnailSize, _) => int.Parse(value) <= 50 ? "Thumbnail Size value must be greater than 50" : int.Parse(value) > 500 ? "Thumbnail Size value must be less than 500" : "", (AppSettingsKey.CropImageMaxScaledWidth, _)when !int.TryParse(value, out _) => "Value should be set as int", (AppSettingsKey.CropImageMaxScaledWidth, _) => int.Parse(value) <= 200 ? "Max Scaled Width value must be greater than 200" : int.Parse(value) > 2000 ? "Max Scaled Width value must be less than 2000" : "", (AppSettingsKey.CropImageMaxScaledHeight, _)when !int.TryParse(value, out _) => "Value should be set as int", (AppSettingsKey.CropImageMaxScaledHeight, _) => int.Parse(value) <= 200 ? "Max Scaled Height value must be greater than 200" : int.Parse(value) > 2000 ? "Max Scaled Height value must be less than 2000" : "", (_, _) => "" }; }
public async Task UpdateAppSetting(AppSettingsKey key, string value) { var message = SettingsValidator.Validate(key, value); if (message != "") { throw new ArgumentException(message); } var keyStr = key.ToString(); var appSetting = await _context.AppSettings.FirstOrDefaultAsync(s => s.Key == keyStr).ConfigureAwait(false); if (appSetting == null) { await _context.AppSettings.AddAsync(new AppSetting { Key = keyStr, Value = value, ModifiedDate = DateTime.UtcNow }); await _context.SaveChangesAsync().ConfigureAwait(false); } else { if (appSetting.Value != value) { appSetting.Value = value; appSetting.ModifiedDate = DateTime.UtcNow; await _context.SaveChangesAsync().ConfigureAwait(false); } } }
public static string GetValueFromAppSettings(AppSettingsKey key) { if (System.Configuration.ConfigurationManager.AppSettings[key.ToString()] == null) { return(string.Empty); } return(System.Configuration.ConfigurationManager.AppSettings[key.ToString()].ToString()); }
/// <summary> /// 取得AppSetting參數 /// </summary> /// <param name="parameter"></param> /// <returns></returns> public static string GetConfig(AppSettingsKey parameter) { //將參數轉為字串 string key = parameter.ToString(); //Return return(Config.GetValue <string>(key)); }
public async Task <(string?value, DateTime?modifiedDate)> GetAppSetting(AppSettingsKey key) { if (key == AppSettingsKey.Unknown) { throw new ArgumentException("Unknown settings key"); } var keyStr = key.ToString(); var setting = await _context.AppSettings.FirstOrDefaultAsync(s => s.Key == keyStr).ConfigureAwait(false); return(setting?.Value, setting?.ModifiedDate); }
public async Task <ActionResult <AppSettingDto> > GetSettings(AppSettingsKey key) { try { var(value, modifiedDate) = await _settingsSvc.GetAppSetting(key); return(new AppSettingDto { Key = key, Value = value ?? "", ModifiedDate = modifiedDate ?? default }); }
private static string GetString(AppSettingsKey key) { return ConfigurationManager.AppSettings[key.ToString()]; }
private static string GetString(AppSettingsKey key) { return(ConfigurationManager.AppSettings[key.ToString()]); }
private static string[] GetStrings(AppSettingsKey key, char split) { return GetString(key).Split(split).Where(s => !string.IsNullOrWhiteSpace(s)).ToArray(); }
private static string[] GetStrings(AppSettingsKey key, char split) { return(GetString(key).Split(split).Where(s => !string.IsNullOrWhiteSpace(s)).ToArray()); }
public async Task <int?> GetAppSettingInt(AppSettingsKey key) { var(str, _) = await GetAppSetting(key).ConfigureAwait(false); return(int.TryParse(str, NumberStyles.None, CultureInfo.CurrentCulture.NumberFormat, out int result) ? result : (int?)null); }
public Task <(string?value, DateTime?modifiedDate)> GetAppSetting(AppSettingsKey key) => key switch