Example #1
0
    /// <summary>
    /// Initializes item selector form control based on selected conversion definition.
    /// </summary>
    /// <param name="force">Forces reload of the selector if <c>true</c></param>
    private void InitializeItemSelector(bool force)
    {
        var conversionDefinition = ABTestConversionDefinitionRegister.Instance.Get(SelectedConversion);
        var controlName          = conversionDefinition?.FormControlDefinition?.FormControlName;
        var formControlType      = conversionDefinition?.FormControlDefinition?.FormControlType;

        if (force)
        {
            plcItemControl.Controls.Clear();
            mItemSelector = null;
        }

        var formUserControl = FormUserControlInfoProvider.GetFormUserControlInfo(controlName);

        if (formUserControl == null && formControlType == null)
        {
            return;
        }

        mItemSelector = formControlType != null
            ? (FormEngineUserControl)Activator.CreateInstance(formControlType)
            : FormUserControlLoader.LoadFormControl(Page, controlName, "", loadDefaultProperties: false);

        if (mItemSelector != null)
        {
            mItemSelector.ID         = "item" + SelectedConversion;
            mItemSelector.IsLiveSite = false;

            var controlParameters = FormHelper.GetFormControlParameters(controlName, formUserControl?.UserControlMergedParameters, false);
            if (controlParameters != null)
            {
                mItemSelector.LoadDefaultProperties(controlParameters);
            }

            var parameters = conversionDefinition?.FormControlDefinition?.FormControlParameters;
            if (parameters != null)
            {
                foreach (var parameter in parameters)
                {
                    mItemSelector.SetValue(parameter.Key, parameter.Value);
                }
            }

            plcItemControl.Controls.Clear();
            plcItemControl.Controls.Add(mItemSelector);

            lblItem.AssociatedControlID = mItemSelector.ID;
            SetItemSelectorCaption(conversionDefinition?.FormControlDefinition?.FormControlCaption);
        }
    }
    /// <summary>
    /// Gets FormEngineUserControl instance for the input SettingsKeyInfo object.
    /// </summary>
    /// <param name="key">SettingsKeyInfo</param>
    /// <param name="groupNo">Number representing index of the processing settings group</param>
    /// <param name="keyNo">Number representing index of the processing SettingsKeyInfo</param>
    private FormEngineUserControl GetFormEngineUserControl(SettingsKeyInfo key, int groupNo, int keyNo)
    {
        string controlNameOrPath = key.KeyEditingControlPath;

        if (string.IsNullOrEmpty(controlNameOrPath))
        {
            return(null);
        }

        // Try to get form control by its name
        FormEngineUserControl control = null;
        var formUserControl           = FormUserControlInfoProvider.GetFormUserControlInfo(controlNameOrPath);

        if (formUserControl != null)
        {
            var formProperties = formUserControl.UserControlMergedParameters;

            if (formUserControl.UserControlParentID > 0)
            {
                // Get parent user control
                var parentFormUserControl = FormUserControlInfoProvider.GetFormUserControlInfo(formUserControl.UserControlParentID);
                if (parentFormUserControl != null)
                {
                    formUserControl = parentFormUserControl;
                }
            }

            // Create FormInfo and load control
            control = Page.LoadUserControl(FormUserControlInfoProvider.GetFormUserControlUrl(formUserControl)) as FormEngineUserControl;
            if (control != null)
            {
                FormInfo fi = FormHelper.GetFormControlParameters(controlNameOrPath, formProperties, false);
                control.LoadDefaultProperties(fi);

                if (!string.IsNullOrEmpty(key.KeyFormControlSettings))
                {
                    control.FieldInfo = FormHelper.GetFormControlSettingsFromXML(key.KeyFormControlSettings);
                    control.LoadControlFromFFI();
                }
            }
        }
        else
        {
            // Try to load the control
            try
            {
                control = Page.LoadUserControl(controlNameOrPath) as FormEngineUserControl;
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("Settings", "LoadControl", ex);
            }
        }

        if (control == null)
        {
            return(null);
        }

        control.ID         = string.Format(@"key{0}{1}", groupNo, keyNo);
        control.IsLiveSite = false;

        return(control);
    }
Example #3
0
    /// <summary>
    /// Gets FormEngineUserControl instance for the input SettingsKeyInfo object.
    /// </summary>
    /// <param name="key">SettingsKeyInfo</param>
    /// <param name="groupNo">Number representing index of the processing settings group</param>
    /// <param name="keyNo">Number representing index of the processing SettingsKeyInfo</param>
    private FormEngineUserControl GetFormEngineUserControl(SettingsKeyInfo key, int groupNo, int keyNo)
    {
        if (string.IsNullOrEmpty(key.KeyEditingControlPath))
        {
            return(null);
        }

        // Try to get form control by its name
        FormEngineUserControl control = null;
        var formUserControl           = FormUserControlInfoProvider.GetFormUserControlInfo(key.KeyEditingControlPath);

        if (formUserControl != null)
        {
            var fileName       = "";
            var formProperties = "";

            if (formUserControl.UserControlParentID > 0)
            {
                // Get parent user control
                var parentFormUserControl = FormUserControlInfoProvider.GetFormUserControlInfo(formUserControl.UserControlParentID);
                if (parentFormUserControl != null)
                {
                    fileName       = parentFormUserControl.UserControlFileName;
                    formProperties = formUserControl.UserControlMergedParameters;
                }
            }
            else
            {
                // Current user control info
                fileName       = formUserControl.UserControlFileName;
                formProperties = formUserControl.UserControlParameters;
            }

            // Create FormInfo and load control
            control = Page.LoadUserControl(fileName) as FormEngineUserControl;
            if (control != null)
            {
                FormInfo fi = FormHelper.GetFormControlParameters(formUserControl.UserControlCodeName, formProperties, true);
                control.LoadDefaultProperties(fi);

                if (!string.IsNullOrEmpty(key.KeyFormControlSettings))
                {
                    control.FieldInfo = FormHelper.GetFormControlSettingsFromXML(key.KeyFormControlSettings);
                    control.LoadControlFromFFI();
                }
            }
        }
        else
        {
            // Try to load the control
            try
            {
                control = Page.LoadUserControl(key.KeyEditingControlPath) as FormEngineUserControl;
            }
            catch
            {
            }
        }

        if (control == null)
        {
            return(null);
        }

        control.ID         = string.Format(@"key{0}{1}", groupNo, keyNo);
        control.IsLiveSite = false;

        if (string.IsNullOrEmpty(key.KeyEditingControlPath))
        {
            return(control);
        }

        // Set properties to the specific controls
        switch (key.KeyEditingControlPath.ToLowerCSafe())
        {
        // Class names selectors
        case "~/cmsformcontrols/classes/selectclassnames.ascx":
            control.SetValue("SiteID", 0);
            break;
        }

        return(control);
    }