Example #1
0
        private bool ClassHasRequiredFields(DataClassInfo dci)
        {
            var form = new FormInfo(dci.ClassFormDefinition);

            return(form.FieldExists("Title") &&
                   form.FieldExists("Text") &&
                   form.FieldExists("Image"));
        }
        private bool VerifyFieldExists(DataClassInfo customTable, string column, FormFieldDataTypeEnum?expectedType = null)
        {
            if (customTable == null)
            {
                return(false);
            }

            var formInfo = new FormInfo(customTable.ClassFormDefinition);

            if (!formInfo.FieldExists(column))
            {
                HandleError(string.Format("The custom table {0} does not contain the column '{1}'", customTable.ClassName, column));
                return(false);
            }

            var fieldInfo = formInfo.GetFormField(column);

            if (expectedType.HasValue && fieldInfo.DataType != expectedType)
            {
                HandleError(string.Format("The column '{0}.{1}' expected to be type '{2}' but found to be type '{3}",
                                          customTable.ClassName, column, expectedType, fieldInfo.DataType));
                return(false);
            }

            return(true);
        }
Example #3
0
        private void UpdateForm()
        {
            var formClassInfo = DataClassInfoProvider.GetDataClassInfo(FORM_CLASS_NAME);

            if (formClassInfo == null)
            {
                return;
            }

            var form = new FormInfo(formClassInfo.ClassFormDefinition);

            if (form.FieldExists(FORM_FIELD_NAME))
            {
                return;
            }

            // Update ClassFormDefinition
            var field = CreateFormField();

            form.AddFormItem(field);
            formClassInfo.ClassFormDefinition = form.GetXmlDefinition();
            formClassInfo.Update();

            // Update Form builder JSON
            IFormBuilderConfigurationSerializer formBuilderConfigurationSerializer = Service.Resolve <IFormBuilderConfigurationSerializer>();
            var contactUsForm            = BizFormInfoProvider.GetBizFormInfo(FORM_NAME, mSite.SiteID);
            var formBuilderConfiguration = formBuilderConfigurationSerializer.Deserialize(contactUsForm.FormBuilderLayout);

            formBuilderConfiguration.EditableAreas.LastOrDefault()
            .Sections.LastOrDefault()
            .Zones.LastOrDefault()
            .FormComponents
            .Add(new FormComponentConfiguration {
                Properties = new ConsentAgreementProperties()
                {
                    Guid = field.Guid
                }
            });
            contactUsForm.FormBuilderLayout = formBuilderConfigurationSerializer.Serialize(formBuilderConfiguration, true);
            contactUsForm.Update();
        }
Example #4
0
        private void UpdateForm(string formName, string formFieldName)
        {
            var formClassInfo = DataClassInfoProvider.GetDataClassInfo($"BizForm.{formName}");

            if (formClassInfo == null)
            {
                return;
            }

            var form = new FormInfo(formClassInfo.ClassFormDefinition);

            if (form.FieldExists(formFieldName))
            {
                return;
            }

            // Update ClassFormDefinition
            var field = CreateFormField(formFieldName);

            form.AddFormItem(field);
            formClassInfo.ClassFormDefinition = form.GetXmlDefinition();
            formClassInfo.Update();

            // Update Form builder JSON
            var contactUsForm            = BizFormInfo.Provider.Get(formName, mSite.SiteID);
            var formBuilderConfiguration = mFormBuilderConfigurationSerializer.Deserialize(contactUsForm.FormBuilderLayout);

            formBuilderConfiguration.EditableAreas.LastOrDefault()
            .Sections.LastOrDefault()
            .Zones.LastOrDefault()
            .FormComponents
            .Add(new FormComponentConfiguration {
                Properties = new ConsentAgreementProperties()
                {
                    Guid = field.Guid
                }
            });
            contactUsForm.FormBuilderLayout = mFormBuilderConfigurationSerializer.Serialize(formBuilderConfiguration, true);
            contactUsForm.Update();
        }
    /// <summary>
    /// Initializes the custom table
    /// </summary>
    /// <param name="dci">DataClassInfo of the custom table</param>
    /// <param name="fi">Form info</param>
    /// <param name="tm">Table manager</param>
    private void InitCustomTable(DataClassInfo dci, FormInfo fi, TableManager tm)
    {
        // Created by
        if (chkItemCreatedBy.Checked && !fi.FieldExists("ItemCreatedBy"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemCreatedBy";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Created by");
            ffi.DataType = FieldDataType.Integer;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Created when
        if (chkItemCreatedWhen.Checked && !fi.FieldExists("ItemCreatedWhen"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemCreatedWhen";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Created when");
            ffi.DataType = FieldDataType.DateTime;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Modified by
        if (chkItemModifiedBy.Checked && !fi.FieldExists("ItemModifiedBy"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemModifiedBy";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Modified by");
            ffi.DataType = FieldDataType.Integer;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Modified when
        if (chkItemModifiedWhen.Checked && !fi.FieldExists("ItemModifiedWhen"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemModifiedWhen";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Modified when");
            ffi.DataType = FieldDataType.DateTime;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Item order
        if (chkItemOrder.Checked && !fi.FieldExists("ItemOrder"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemOrder";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Order");
            ffi.DataType = FieldDataType.Integer;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // GUID
        if (chkItemGUID.Checked && !fi.FieldExists("ItemGUID"))
        {
            var ffiGuid = CreateGuidField();

            fi.AddFormItem(ffiGuid);
        }

        // Update table structure - columns could be added
        bool old = TableManager.UpdateSystemFields;

        TableManager.UpdateSystemFields = true;

        string schema = fi.GetXmlDefinition();
        tm.UpdateTableByDefinition(dci.ClassTableName, schema);

        TableManager.UpdateSystemFields = old;

        // Update xml schema and form definition
        dci.ClassFormDefinition = schema;
        dci.ClassXmlSchema = tm.GetXmlSchema(dci.ClassTableName);

        using (CMSActionContext context = new CMSActionContext())
        {
            // Disable logging into event log
            context.LogEvents = false;

            DataClassInfoProvider.SetDataClassInfo(dci);
        }
    }
    /// <summary>
    /// Initializes the custom table
    /// </summary>
    /// <param name="dci">DataClassInfo of the custom table</param>
    /// <param name="fi">Form info</param>
    private void InitCustomTable(DataClassInfo dci, FormInfo fi)
    {
        // Created by
        if (chkItemCreatedBy.Checked && !fi.FieldExists("ItemCreatedBy"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemCreatedBy";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Created by");
            ffi.DataType = FieldDataType.Integer;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Created when
        if (chkItemCreatedWhen.Checked && !fi.FieldExists("ItemCreatedWhen"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemCreatedWhen";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Created when");
            ffi.DataType = FieldDataType.DateTime;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Modified by
        if (chkItemModifiedBy.Checked && !fi.FieldExists("ItemModifiedBy"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemModifiedBy";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Modified by");
            ffi.DataType = FieldDataType.Integer;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Modified when
        if (chkItemModifiedWhen.Checked && !fi.FieldExists("ItemModifiedWhen"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemModifiedWhen";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Modified when");
            ffi.DataType = FieldDataType.DateTime;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Item order
        if (chkItemOrder.Checked && !fi.FieldExists("ItemOrder"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemOrder";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Order");
            ffi.DataType = FieldDataType.Integer;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // GUID
        if (chkItemGUID.Checked && !fi.FieldExists("ItemGUID"))
        {
            fi.AddFormItem(CreateGuidField("ItemGUID"));
        }

        UpdateDataClass(dci, fi);
    }
    /// <summary>
    /// Initializes class.
    /// </summary>
    /// <param name="dci">DataClassInfo</param>
    /// <param name="fi">Form info</param>
    private void InitClass(DataClassInfo dci, FormInfo fi)
    {
        // Get class code name
        var pkName = txtPKName.Text.Trim();
        var codeName = pkName.Substring(0, pkName.Length - 2);

        // Guid
        if (chkClassGuid.Checked && !fi.FieldExists(codeName + "Guid"))
        {
            fi.AddFormItem(CreateGuidField(codeName + "Guid"));
        }

        // Last modified
        if (chkClassLastModified.Checked && !fi.FieldExists(codeName + "LastModified"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = codeName + "LastModified";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Last modified");
            ffi.DataType = FieldDataType.DateTime;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, String.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, String.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = false;

            fi.AddFormItem(ffi);
        }

        UpdateDataClass(dci, fi);
    }
Example #8
0
        private void EnsureCmsUserAzureCustomField()
        {
            var cmsUserDataClass = DataClassInfoProvider.GetDataClassInfo("cms.user");

            if (cmsUserDataClass == null)
            {
                return;
            }

            var formInfo = new FormInfo(cmsUserDataClass.ClassFormDefinition);

            if (formInfo.FieldExists("AzureADUsername"))
            {
                EventLogProvider.LogInformation("AzureADAuthentication", "Skip Create Field", "AzureADUsername");
                return;
            }

            // Create "AzureADUsername" field if it doesn't exist
            EventLogProvider.LogInformation("AzureADAuthentication", "Create Field", "AzureADUsername");

            var azureAdUsernameTextField = new FormFieldInfo
            {
                Name         = "AzureADUsername",
                DataType     = "text",
                Size         = 200,
                Precision    = -1,
                AllowEmpty   = true,
                DefaultValue = string.Empty,
                System       = false,
                FieldType    = FormFieldControlTypeEnum.TextBoxControl,
                Visible      = true,
                Caption      = "Azure AD Username",
                Enabled      = true
            };

            using (var tr = new CMSLateBoundTransaction())
            {
                var tm = new TableManager(cmsUserDataClass.ClassConnectionString);
                tr.BeginTransaction();

                var newFieldHandler = (AbstractAdvancedHandler)null;
                try
                {
                    newFieldHandler =
                        DataDefinitionItemEvents.AddItem.StartEvent(cmsUserDataClass, azureAdUsernameTextField);

                    var sqlType = DataTypeManager.GetSqlType(azureAdUsernameTextField.DataType,
                                                             azureAdUsernameTextField.Size, azureAdUsernameTextField.Precision);
                    tm.AddTableColumn(cmsUserDataClass.ClassTableName, azureAdUsernameTextField.Name, sqlType,
                                      azureAdUsernameTextField.AllowEmpty, azureAdUsernameTextField.DefaultValue);

                    formInfo.AddFormItem(azureAdUsernameTextField);

                    cmsUserDataClass.ClassFormDefinition = formInfo.GetXmlDefinition();
                    cmsUserDataClass.ClassXmlSchema      = tm.GetXmlSchema(cmsUserDataClass.ClassTableName);
                    DataClassInfoProvider.SetDataClassInfo(cmsUserDataClass);
                    FormHelper.UpdateInheritedClasses(cmsUserDataClass);

                    QueryInfoProvider.ClearDefaultQueries(cmsUserDataClass, true, true);
                    newFieldHandler.FinishEvent();

                    tr.Commit();

                    ClearHashtables("cms.user");
                }
                catch (Exception ex)
                {
                    EventLogProvider.LogException("AzureADAuthentication", "Create Field", ex);
                }
                finally
                {
                    newFieldHandler?.Dispose();
                }
            }
        }