public bool Sync(JsonNode rootNode, SettingManager manager = null) { bool save = false; // Load setting data from file. var freshSettingData = this.ReadData(rootNode); // Synchronize modified settings with freshly read setting data. foreach (var groupData in this._groups.Values) { ISettingGroup group = (manager != null ? manager.GetGroup(groupData.Key) : null); JsonObjectNode freshGroupData; freshSettingData.TryGetValue(groupData.Key, out freshGroupData); save |= groupData.Sync(group, freshGroupData); } // Read preferences for newly found groups. foreach (var freshGroupData in freshSettingData) { if (this._groups.ContainsKey(freshGroupData.Key)) { continue; } var groupData = this.GetGroupData(freshGroupData.Key, true); groupData.Sync(null, freshGroupData.Value); } return(save); }
private void mItem_Settings(Object sender, EventArgs e) { this.Visibility = Visibility.Collapsed; UISettings settings = new UISettings(); // settings.SettingGroups.Add(new String[] { "general" }, new UIGeneral()); settings.SettingGroups.Add(new String[] { "proxy" }, new UIProxy()); settings.SettingGroups.Add(new String[] { "providers" }, new UIProviders(this.Providers.AvailableProviders)); // foreach (IProvider provider in this.Providers.AvailableProviders) { if (provider.getSettingGroups() == null) { continue; } foreach (Uri xamlUri in provider.getSettingGroups()) { ISettingGroup sGroup = (ISettingGroup)System.Windows.Application.LoadComponent(xamlUri); settings.SettingGroups.Add(new String[] { "providersettings", provider.GetType().ToString() }, sGroup); } } // settings.Settings = this.Settings; settings.Show(); }
public static ISettingValue AddOrUpdateTenantSettingValue(this ISettingGroup group, ISettingValue value, int?tenantId) { using (var db = new AppDbContext()) { var scopes = SettingScopes.Tenant; var theTenantId = tenantId == null ? WeiChatApplicationContext.Current.TenantId : tenantId.Value; var groupInfo = db.App_SettingGroups.FirstOrDefault(p => (p.Name == group.Name) && (p.Scopes == scopes)); if (groupInfo == null) { throw new Exception("名称为" + group.Name + "的配置组不存在。"); } var settingValue = db.App_SettingValues.FirstOrDefault(p => (p.Name == value.Name) && (p.Scopes == scopes)); var isAdd = settingValue == null; if (settingValue == null) { settingValue = new App_SettingValue(); } settingValue.IsVisibleToClients = value.IsVisibleToClients; settingValue.Scopes = scopes; settingValue.UpdateTime = DateTime.Now; settingValue.DisplayName = value.DisplayName; settingValue.Name = value.Name; settingValue.Description = value.Description; settingValue.CreateBy = WeiChatApplicationContext.Current.UserId; settingValue.Value = value.Value; settingValue.GroupId = groupInfo.Id; settingValue.CustomData = value.CustomData; settingValue.TenantId = theTenantId; if (isAdd) { db.App_SettingValues.Add(settingValue); } db.SaveChanges(); ConcurrentDictionary <string, ISettingValue> settings = null; if (SettingManager.Current.TenantSettings.ContainsKey(theTenantId)) { settings = SettingManager.Current.TenantSettings[theTenantId]; } else { settings = new ConcurrentDictionary <string, ISettingValue>(); { var tenantSettings = db.App_SettingValues.Where(p => (p.Scopes == scopes) && (p.TenantId == theTenantId)); foreach (var item in tenantSettings) { settings.TryAdd(item.Name, item); } SettingManager.Current.TenantSettings.TryAdd(theTenantId, settings); } } settings.AddOrUpdate(settingValue.Name, settingValue, (tKey, existingVal) => { return(settingValue); }); return(settingValue); } }
public SettingCategoryViewModel(string groupName, ISettingGroup group) { this.title = groupName; this.Groups = new List <SettingGroupViewModel>() { new SettingGroupViewModel(group.GroupName, group.Items) }; }
/// <inheritdoc/> public override void DeleteUnreferencedSettings(ISettingGroup group) { if (group == null) { throw new ArgumentNullException("group"); } var groupData = this._data.GetGroupData(group.Key); if (groupData != null) { groupData.DeleteUnreferencedSettings(group); } }
public ISettingGroup AddOrUpdateTenantGroupSetting(ISettingGroup group, int?tenantId) { using (var db = new AppDbContext()) { var scopes = SettingScopes.Tenant; var theTenantId = tenantId == null ? WeiChatApplicationContext.Current.TenantId : tenantId.Value; var groupInfo = db.App_SettingGroups.FirstOrDefault(p => (p.Name == group.Name) && (p.Scopes == scopes)); var isAdd = groupInfo == null; if (groupInfo == null) { groupInfo = new App_SettingGroup(); } groupInfo.IsVisibleToClients = group.IsVisibleToClients; groupInfo.Name = group.Name; groupInfo.Scopes = scopes; groupInfo.UpdateTime = DateTime.Now; groupInfo.DisplayName = group.DisplayName; groupInfo.Description = group.Description; groupInfo.TenantId = theTenantId; groupInfo.CreateBy = WeiChatApplicationContext.Current.UserId; if (group.ParentGroup != null) { var parentGroup = db.App_SettingGroups.FirstOrDefault( p => (p.Name == group.ParentGroup.Name) && (p.Scopes == scopes)); if (parentGroup != null) { groupInfo.ParentId = parentGroup.Id; } else { throw new ArgumentException("ParentGroup不存在", "ParentGroup"); } } if (isAdd) { db.App_SettingGroups.Add(groupInfo); } db.SaveChanges(); var settings = GetTenantSettingGroupDictionary(theTenantId); settings.AddOrUpdate(groupInfo.Name, groupInfo, (tKey, existingVal) => { return(groupInfo); }); return(groupInfo); } }
public void DeleteUnreferencedSettings(ISettingGroup group) { if (group == null) { throw new ArgumentNullException("group"); } this._clean = true; // Fetch list of keys for settings which are not referenced by group. var keys = from key in this._settings.Keys where [email protected](key) select key; foreach (var key in keys.ToArray()) { this._settings.Remove(key); } }
public bool Sync(ISettingGroup group, JsonObjectNode jsonGroup) { bool dirty = false; this._settings.Clear(); if (group != null) { // Serialize modified properties. foreach (ISetting setting in group.Settings) { if (setting.IsDirty) { try { setting.Serialize(this); dirty = true; } catch (Exception ex) { this.Owner.LogFeedback(MessageFeedbackType.Error, string.Format("Was unable to serialize setting '{0}.{1}', skipping...", setting.GroupKey, setting.Key), ex); } } } } if (!this._clean) { if (jsonGroup != null) { // Merge freshly loaded setting data with setting data. foreach (var jsonSetting in jsonGroup) { if (!this._settings.ContainsKey(jsonSetting.Key)) { this._settings[jsonSetting.Key] = jsonSetting.Value; } } } this._clean = false; } return(dirty); }
public static ISettingValue AddOrUpdateApplicationSettingValue(this ISettingGroup group, ISettingValue value) { using (var db = new AppDbContext()) { var scopes = SettingScopes.Application; var groupInfo = db.App_SettingGroups.FirstOrDefault(p => (p.Name == group.Name) && (p.Scopes == scopes)); if (groupInfo == null) { throw new Exception("名称为" + group.Name + "的配置组不存在。"); } var settingValue = db.App_SettingValues.FirstOrDefault(p => (p.Name == value.Name) && (p.Scopes == scopes)); var isAdd = settingValue == null; if (settingValue == null) { settingValue = new App_SettingValue(); } settingValue.IsVisibleToClients = value.IsVisibleToClients; settingValue.Scopes = scopes; settingValue.UpdateTime = DateTime.Now; settingValue.DisplayName = value.DisplayName; settingValue.Name = value.Name; settingValue.Description = value.Description; settingValue.CreateBy = WeiChatApplicationContext.Current.UserId; settingValue.Value = value.Value; settingValue.GroupId = groupInfo.Id; if (isAdd) { db.App_SettingValues.Add(settingValue); } db.SaveChanges(); SettingManager.Current.ApplicationSettings.AddOrUpdate(value.Name, settingValue, (tKey, existingVal) => { return(settingValue); }); return(settingValue); } }
private IActionResult GetSettingResult(string settingType) { SettingsModel model = null; ISettingGroup settings = null; var result = R.Success; switch (settingType) { case "general": settings = DependencyResolver.Resolve <GeneralSettings>(); model = _modelMapper.Map <GeneralSettingsModel>(settings); var menuService = DependencyResolver.Resolve <IMenuService>(); var menus = menuService.Get(x => true).ToList(); var menuSelectList = SelectListHelper.GetSelectItemList(menus, x => x.Id, x => x.Name); result.WithTimezones(); result.With("availableMenus", menuSelectList); //get themes var themes = _themeProvider.GetAvailableThemes() .Select(x => new ThemeInfoModel() { DirectoryName = x.DirectoryName, Name = x.Name, ThumbnailUrl = x.ThumbnailUrl, PendingRestart = x.PendingRestart }).ToList(); result.With("availableThemes", themes); break; case "order": settings = DependencyResolver.Resolve <OrderSettings>(); result.WithAvailableOrderStatusTypes(); model = _modelMapper.Map <OrderSettingsModel>(settings); break; case "user": settings = DependencyResolver.Resolve <UserSettings>(); model = _modelMapper.Map <UserSettingsModel>(settings); result.WithRegistrationModes(); break; case "url": settings = DependencyResolver.Resolve <UrlSettings>(); model = _modelMapper.Map <UrlSettingsModel>(settings); break; case "media": settings = DependencyResolver.Resolve <MediaSettings>(); model = _modelMapper.Map <MediaSettingsModel>(settings); break; case "tax": settings = DependencyResolver.Resolve <TaxSettings>(); var taxService = DependencyResolver.Resolve <ITaxService>(); var taxes = taxService.Get(x => true).ToList(); var taxesSelectList = SelectListHelper.GetSelectItemList(taxes, x => x.Id, x => x.Name); model = _modelMapper.Map <TaxSettingsModel>(settings); result.With("availableTaxes", taxesSelectList); break; case "email": settings = DependencyResolver.Resolve <EmailSenderSettings>(); model = _modelMapper.Map <EmailSettingsModel>(settings); result.WithEmailAccounts(); break; case "catalog": settings = DependencyResolver.Resolve <CatalogSettings>(); model = _modelMapper.Map <CatalogSettingsModel>(settings); result.WithCatalogPaginationTypes(); break; case "localization": settings = DependencyResolver.Resolve <LocalizationSettings>(); model = _modelMapper.Map <LocalizationSettingsModel>(settings); var currencyService = DependencyResolver.Resolve <ICurrencyService>(); var currencies = currencyService.Get(x => x.Published).ToList(); var currenciesSelectList = SelectListHelper.GetSelectItemListWithAction(currencies, x => x.Id, x => $"{x.Name} ({x.IsoCode})"); result.With("availableCurrencies", currenciesSelectList); result.WithCatalogPaginationTypes(); break; case "gdpr": settings = DependencyResolver.Resolve <GdprSettings>(); model = _modelMapper.Map <GdprSettingsModel>(settings); var consentGroupService = DependencyResolver.Resolve <IConsentGroupService>(); var consentGroups = consentGroupService.Get(x => true).ToList(); var groupSelectList = SelectListHelper.GetSelectItemList(consentGroups, x => x.Id, x => x.Name); result.With("availableConsentGroups", groupSelectList); break; case "security": settings = DependencyResolver.Resolve <SecuritySettings>(); model = _modelMapper.Map <SecuritySettingsModel>(settings); break; case "affiliate": settings = DependencyResolver.Resolve <AffiliateSettings>(); model = _modelMapper.Map <AffiliateSettingsModel>(settings); break; } return(result.With("settings", model).With("settingType", settingType).Result); }
/// <summary> /// Delete persisted state for all settings within a specific group which /// have not been fetched from the data store. This might be useful for /// truncating settings which have become obsolete. /// </summary> /// <remarks> /// <para>The <see cref="ISettingGroup"/> input includes a collection of /// settings which have been fetched from the data store. Persisted data for /// settings which are not included within this group are considered unreferenced /// and thus should be deleted.</para> /// <para>In a well designed application all required settings should have /// already been fetched for the specified <see cref="ISettingGroup"/> since /// sealed setting groups cannot fetch additional settings, and non-sealed /// setting groups should never be exposed in the public API.</para> /// <para>This method is used upon invoking <see cref="ISettingGroup.RestoreDefaultValues">ISettingGroup.RestoreDefaultValues</see> /// to provide consistent results for the end-user. For instance, if the end-user /// is using multiple versions or instances of the same application and triggers /// an action to "Reset Default Settings"; it would be inconsistent if only some /// settings had been reset when opening a different version or instance of the /// same application.</para> /// <para>This method should only interact with persisted state within the /// associated data store and <strong>must not</strong> make any modifications /// to the associated <see cref="SettingManager"/>, <see cref="ISettingGroup"/> /// or <see cref="ISetting"/> instances.</para> /// </remarks> /// <param name="group">The setting group.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="group"/> has a value of <c>null</c>. /// </exception> public abstract void DeleteUnreferencedSettings(ISettingGroup group);