/// <summary> /// Method removes obsolete settings. /// </summary> private static void CleanupSettings() { var settings = SettingsKeyInfoProvider.GetSettingsKeys().Where(@"[KeyName] = 'CMSFacebookPageId' OR [KeyName] = 'CMSFacebookAccessToken' OR [KeyName] = 'CMSFacebookURLShortenerType' OR [KeyName] = 'CMSTwitterURLShortenerType' OR [KeyName] = 'CMSTwitterConsumerKey' or [KeyName] = 'CMSTwitterConsumerSecret' OR [KeyName] = 'CMSTwitterAccessToken' OR [KeyName] = 'CMSTwitterAccessTokenSecret' OR [KeyName] = 'CMSRequiredFacebookPage'"); foreach (SettingsKeyInfo settingsKeyInfo in settings) { SettingsKeyInfoProvider.DeleteSettingsKeyInfo(settingsKeyInfo); } var categories = SettingsCategoryInfoProvider.GetSettingsCategories().Where(@"[CategoryName] = 'CMS.Facebook.UrlShortening' OR [CategoryName] = 'CMS.Twitter.General' OR [CategoryName] = 'CMS.Twitter.UrlShortening' OR [CategoryName] = 'CMS.Twitter'"); foreach (SettingsCategoryInfo category in categories) { SettingsCategoryInfoProvider.DeleteSettingsCategoryInfo(category); } }
/// <summary> /// Updates key values to default after type change. /// </summary> /// <param name="keyObj">Global key that changed</param> private void UpdateKeyValuesAfterTypeChanged(SettingsKeyInfo keyObj) { // Loop through all the keys (site and global) and set the value to the selected default one foreach (var settingKey in SettingsKeyInfoProvider.GetSettingsKeys().WhereEquals("KeyName", keyObj.KeyName)) { settingKey.KeyValue = keyObj.KeyDefaultValue; SettingsKeyInfoProvider.SetSettingsKeyInfo(settingKey); } }
/// <summary> /// Encrypts all Strands catalog feed passwords /// </summary> private static void EncryptStrandsCatalogFeedPasswords() { const string keyName = "CMSStrandsCatalogFeedPassword"; // Get all not empty keys var keys = SettingsKeyInfoProvider.GetSettingsKeys() .Columns("SiteID, KeyValue") .WhereEquals("KeyName", keyName) .WhereNotEmpty("KeyValue"); foreach (var key in keys) { // Encrypt password SettingsKeyInfoProvider.SetValue(keyName, key.SiteID, EncryptionHelper.EncryptData(key.KeyValue)); } }
private IEnumerable <SettingsKeyInfo> GetKeys(SettingsCategoryInfo group, bool isSite, string searchText, bool searchInDescription) { bool isSearch = !string.IsNullOrEmpty(searchText); IEnumerable <SettingsKeyInfo> keys = SettingsKeyInfoProvider.GetSettingsKeys(group.CategoryID).OrderBy("KeyOrder", "KeyDisplayName"); if (isSearch) { keys = keys.Where(k => SettingsKeyInfoProvider.SearchSettingsKey(k, searchText, searchInDescription)); } if (isSite) { keys = keys.Where(k => !k.KeyIsGlobal); } return(keys); }
private IEnumerable <SettingsKeyInfo> GetKeys(int groupId) { IEnumerable <SettingsKeyInfo> keys = SettingsKeyInfoProvider.GetSettingsKeys(groupId) .Where(new WhereCondition().WhereFalse("KeyIsHidden").Or().WhereNull("KeyIsHidden")) .OrderBy("KeyOrder", "KeyDisplayName"); if (IsSearchTextValid) { keys = keys.Where(k => SettingsKeyInfoProvider.SearchSettingsKey(k, mSearchText, mSearchDescription)); } if (SiteID > 0) { return(keys.Where(k => !k.KeyIsGlobal)); } return(keys); }
private IEnumerable <SettingsKeyInfo> GetKeys(int groupId) { var query = SettingsKeyInfoProvider.GetSettingsKeys(groupId) .WhereEqualsOrNull("KeyIsHidden", false); if (SiteID > 0) { query.WhereEqualsOrNull("KeyIsGlobal", false); } IEnumerable <SettingsKeyInfo> keys = query.OrderBy("KeyOrder", "KeyDisplayName"); if (IsSearchTextValid) { keys = keys.Where(k => SettingsKeyInfoProvider.SearchSettingsKey(k, mSearchText, mSearchDescription)); } return(keys); }
/// <summary> /// Gets and bulk updates settings keys. Called when the "Get and bulk update keys" button is pressed. /// Expects the CreateSettingsKey method to be run first. /// </summary> private bool GetAndBulkUpdateSettingsKeys() { // Get the data var keys = SettingsKeyInfoProvider.GetSettingsKeys().WhereStartsWith("KeyName", "MyNew"); var result = false; foreach (var modifyKey in keys) { // Update the property modifyKey.KeyDisplayName = modifyKey.KeyDisplayName.ToUpper(); // Update the settings key SettingsKeyInfoProvider.SetSettingsKeyInfo(modifyKey); result = true; } return(result); }
/// <summary> /// Updates settings key for all sites (or only global if the IsGlobal checkbox is checked). /// </summary> /// <returns>CodeName of the SettingsKey objects.</returns> private int UpdateKey() { // Try to get the key var keyObj = (mSettingsKeyId > 0) ? SettingsKeyInfoProvider.GetSettingsKeyInfo(mSettingsKeyId) : null; if (keyObj == null) { // Create new keyObj = new SettingsKeyInfo(); } var oldKeyCategoryID = keyObj.KeyCategoryID; // Set values keyObj.KeyName = txtKeyName.Text.Trim(); keyObj.KeyDisplayName = txtKeyDisplayName.Text.Trim(); keyObj.KeyDescription = txtKeyDescription.Text.Trim(); keyObj.KeyType = drpKeyType.SelectedValue; keyObj.KeyCategoryID = mSelectedGroupId >= 0 ? mSelectedGroupId : drpCategory.SelectedCategory; keyObj.KeyIsGlobal = chkKeyIsGlobal.Checked; keyObj.KeyIsHidden = chkKeyIsHidden.Checked; keyObj.KeyValidation = (string.IsNullOrEmpty(txtKeyValidation.Text.Trim()) ? null : txtKeyValidation.Text.Trim()); keyObj.KeyDefaultValue = (string.IsNullOrEmpty(DefaultValue) ? null : DefaultValue); var path = ValidationHelper.GetString(ucSettingsKeyControlSelector.ControlPath, string.Empty); keyObj.KeyEditingControlPath = (string.IsNullOrEmpty(path.Trim()) ? null : path.Trim()); // Update form control settings if (ucSettingsKeyControlSelector.IsFormControlSelected) { var formFieldInfo = new FormFieldInfo(); ucControlSettings.SaveData(); formFieldInfo.SettingsMacroTable = ucControlSettings.MacroTable; if ((ucControlSettings.FormData != null) && (ucControlSettings.FormData.ItemArray.Length > 0)) { foreach (DataColumn column in ucControlSettings.FormData.Table.Columns) { formFieldInfo.Settings[column.ColumnName] = ucControlSettings.FormData.Table.Rows[0][column.Caption]; } } var settings = FormHelper.GetFormControlSettingsXml(formFieldInfo); keyObj.KeyFormControlSettings = settings; } else { keyObj.KeyFormControlSettings = null; } if (drpGeneration.Value >= 0) { keyObj.KeyLoadGeneration = drpGeneration.Value; } if (keyObj.KeyID == 0) { keyObj.KeyValue = DefaultValue; } if (chkKeyIsGlobal.Checked) { keyObj.SiteID = 0; } // If category changed set new order or if new set on the end of key list if (keyObj.KeyCategoryID != oldKeyCategoryID) { var keys = SettingsKeyInfoProvider.GetSettingsKeys(keyObj.KeyCategoryID) .OrderByDescending("KeyOrder") .Column("KeyOrder"); keyObj.KeyOrder = keys.GetScalarResult(0) + 1; } SettingsKeyInfoProvider.SetSettingsKeyInfo(keyObj); // Update property mSettingsKeyObj = keyObj; return(keyObj.KeyID); }
/// <summary> /// Returns string with Settings information for specified site. /// </summary> /// <param name="siteId">Site ID or 0 for global Settings</param> /// <param name="siteName">Site name or null for global Settings</param> private static string GetSettingsString(int siteId, string siteName) { var categories = SettingsCategoryInfoProvider.GetSettingsCategories() .OrderBy("CategoryName", "CategoryOrder") .Columns("CategoryName", "CategoryID"); // Get global setting categories if (siteId > 0) { categories.Where("CategoryID IN (SELECT KeyCategoryID FROM CMS_SettingsKey WHERE SiteID = " + siteId + ")"); } var sb = new StringBuilder(); string site = siteId > 0 ? siteName : "GLOBAL SETTINGS"; sb.Append(" - "); sb.Append(site); sb.AppendLine(); // Loop through all setting categories foreach (DataRow catDr in categories.Tables[0].Rows) { // Get settings keys for specific category var categoryId = ValidationHelper.GetInteger(catDr["CategoryID"], 0); DataSet keys = SettingsKeyInfoProvider.GetSettingsKeys(categoryId, siteId) .Columns("KeyName", "KeyValue", "KeyType"); if (!DataHelper.DataSourceIsEmpty(keys)) { // Display only not empty categories sb.Append("\r\n\t - "); var categoryName = ValidationHelper.GetString(catDr["CategoryName"], ""); sb.Append(ResHelper.LocalizeString(categoryName)); sb.AppendLine(); // Display keys for category foreach (DataRow keyDr in keys.Tables[0].Rows) { var value = keyDr["KeyValue"]; if (value != DBNull.Value) { var name = ValidationHelper.GetString(keyDr["KeyName"], string.Empty); var stringValue = ValidationHelper.GetString(value, string.Empty); var type = ValidationHelper.GetString(keyDr["KeyType"], string.Empty); sb.AppendFormat("\t\t - {0} '{1}' ({2})", name, stringValue, type); sb.AppendLine(); } } } } sb.AppendLine(); return(sb.ToString()); }