Beispiel #1
0
    /// <summary>
    /// Creates settings key. Called when the "Create key" button is pressed.
    /// </summary>
    private bool CreateSettingsKey()
    {
        // Get the settings group
        SettingsCategoryInfo settingsGroup = SettingsCategoryInfoProvider.GetSettingsCategoryInfoByName("MyNewSettingsGroup");

        if (settingsGroup != null)
        {
            // Create new settings key object
            SettingsKeyInfo newKey = new SettingsKeyInfo();

            // Set the properties
            newKey.KeyDisplayName  = "My new key";
            newKey.KeyName         = "MyNewKey";
            newKey.KeyDescription  = "My new key description";
            newKey.KeyType         = "string";
            newKey.KeyValue        = "My new value";
            newKey.KeyCategoryID   = settingsGroup.CategoryID;
            newKey.KeyDefaultValue = null;

            // Set Site ID for site specific settings key (for global settings key is default value 0).
            newKey.SiteID = SiteContext.CurrentSiteID;

            // Create the settings key
            SettingsKeyInfoProvider.SetSettingsKeyInfo(newKey);

            return(true);
        }

        return(false);
    }
 /// <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);
     }
 }
Beispiel #3
0
    /// <summary>
    /// Gets and updates settings key. Called when the "Get and update key" button is pressed.
    /// Expects the CreateSettingsKey method to be run first.
    /// </summary>
    private bool GetAndUpdateSettingsKey()
    {
        // Get the settings key
        SettingsKeyInfo updateKey = SettingsKeyInfoProvider.GetSettingsKeyInfo("MyNewKey", SiteContext.CurrentSiteID);

        if (updateKey != null)
        {
            // Update the property
            updateKey.KeyDisplayName = updateKey.KeyDisplayName.ToLowerCSafe();

            // Update the settings key
            SettingsKeyInfoProvider.SetSettingsKeyInfo(updateKey);

            return(true);
        }

        return(false);
    }
Beispiel #4
0
    /// <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);
    }
        public void CreateKey(SettingsKey key)
        {
            var groupInfo = GetGroup(key.Group.DisplayName, key.Group.Category.Name);

            var newKey = new SettingsKeyInfo
            {
                KeyDisplayName         = key.KeyDisplayName,
                KeyName                = key.KeyName,
                KeyDescription         = key.KeyDescription,
                KeyType                = key.KeyType,
                KeyValue               = key.KeyDefaultValue,
                KeyCategoryID          = groupInfo.CategoryID,
                KeyDefaultValue        = key.KeyDefaultValue,
                KeyEditingControlPath  = key.KeyEditingControlPath,
                KeyExplanationText     = key.KeyExplanationText,
                KeyFormControlSettings = key.KeyFormControlSettings,
                KeyValidation          = key.KeyValidation
            };

            SettingsKeyInfoProvider.SetSettingsKeyInfo(newKey);
        }
Beispiel #6
0
        private void EnableDataProtectionSamples(ISiteInfo site)
        {
            var dataProtectionSamplesEnabledSettingsKey = SettingsKeyInfoProvider.GetSettingsKeyInfo(DATA_PROTECTION_SETTINGS_KEY);

            if (dataProtectionSamplesEnabledSettingsKey?.KeyValue.ToBoolean(false) ?? false)
            {
                return;
            }

            var keyInfo = new SettingsKeyInfo
            {
                KeyName         = DATA_PROTECTION_SETTINGS_KEY,
                KeyDisplayName  = DATA_PROTECTION_SETTINGS_KEY,
                KeyType         = "boolean",
                KeyValue        = "True",
                KeyDefaultValue = "False",
                KeyIsGlobal     = true,
                KeyIsHidden     = true
            };

            SettingsKeyInfoProvider.SetSettingsKeyInfo(keyInfo);
            EnsureTask(site);
        }
Beispiel #7
0
    /// <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);
    }