public List <AppSetting> GetAppSettings() { // get edited app settings from db List <AppSetting> editedAppSettings = (List <AppSetting>)_cache.GetValue(AppCache.AppCacheKeys.EditedAppSettings.ToString()); if (editedAppSettings == null) { editedAppSettings = _dataProvider.GetAppSettings(); _cache.SetValue(AppCache.AppCacheKeys.EditedAppSettings.ToString(), editedAppSettings); } // get default app settings List <AppSetting> appSettings = (List <AppSetting>)_cache.GetValue(AppCache.AppCacheKeys.AppSettings.ToString()); if (appSettings == null) { // read app settings string appSettingsString = File.ReadAllText("orgappsettings.json"); if (appSettingsString != null && appSettingsString != String.Empty) { appSettings = new List <AppSetting>(); var appSettingsObj = JsonConvert.DeserializeObject(appSettingsString); foreach (var prop in JsonConvert.DeserializeObject(appSettingsString).GetType().GetProperties()) { if (prop.Name == nameof(JToken.First) && prop.PropertyType.Name == nameof(JToken)) { var token = (JToken)prop.GetValue(appSettingsObj); while (token != null) { if (token is JProperty castProp) { appSettings.Add(new AppSetting { Key = castProp.Name, Value = castProp.Value.ToString() }); } token = token.Next; } } } } _cache.SetValue(AppCache.AppCacheKeys.AppSettings.ToString(), appSettings); } foreach (var appSetting in appSettings) { AppSetting editedAppSetting = editedAppSettings.FirstOrDefault(x => x.Key == appSetting.Key); if (editedAppSetting != null) { appSetting.Value = editedAppSetting.Value; } } return(appSettings); }
public List <AppResource> GetAppResources() { string culture = CultureInfo.CurrentCulture.Name; List <AppResource> editedAppResources = (List <AppResource>)_cache.GetValue(AppCache.AppCacheKeys.EditedAppResources.ToString()); if (editedAppResources == null) { editedAppResources = _dataProvider.GetAppResources(); _cache.SetValue(AppCache.AppCacheKeys.EditedAppResources.ToString(), editedAppResources); } List <AppResource> appResources = Enum.GetValues(typeof(AppResourcesKeys)).OfType <AppResourcesKeys>() .Where(x => IsExistResources(x.ToString())) .Select(x => new AppResource() { Key = x.ToString(), Value = GetString(x.ToString()), DefaultValue = GetString(x.ToString()) }) .ToList(); foreach (var appResource in appResources) { AppResource editedAppResource = editedAppResources.FirstOrDefault(x => x.Key == appResource.Key); if (editedAppResource != null) { appResource.Value = editedAppResource.Value; } } return(appResources); }