コード例 #1
0
        private TrgT CopyControl <SrcT, TrgT>(SrcT sourceControl, FormsManager manager)
            where SrcT : ControlData
            where TrgT : ControlData
        {
            TrgT migratedControlData;

            if (!sourceControl.IsLayoutControl)
            {
                var migratedControl = this.ConfigureFormControl(sourceControl, manager);

                // Placeholder is updated later.
                migratedControlData = manager.CreateControl <TrgT>(migratedControl, "Body");
            }
            else
            {
                migratedControlData = manager.CreateControl <TrgT>();
                manager.CopyControl(sourceControl, migratedControlData);

                this.ConfigureLayoutControl <TrgT>(migratedControlData);
            }

            migratedControlData.Caption = sourceControl.Caption;

            return(migratedControlData);
        }
コード例 #2
0
        public void CreateForm(Guid formId, string formName, string formTitle, string formSuccessMessage, IList <Control> formControls, bool publishForm = true)
        {
            FormsManager formManager = FormsManager.GetManager();
            var          form        = formManager.GetForms().SingleOrDefault(f => f.Id == formId);
            Guid         siblingId   = Guid.Empty;

            if (form == null)
            {
                form = formManager.CreateForm(formName, formId);

                form.Framework      = FormFramework.Mvc;
                form.Title          = formTitle;
                form.UrlName        = Regex.Replace(form.Name.ToLower(), ArrangementConstants.UrlNameCharsToReplace, ArrangementConstants.UrlNameReplaceString);
                form.SuccessMessage = formSuccessMessage;

                var culture = SystemManager.CurrentContext.AppSettings.DefaultFrontendLanguage;
                var draft   = formManager.EditForm(form.Id);
                var master  = formManager.Lifecycle.CheckOut(draft, culture);

                if (master != null)
                {
                    if (formControls != null && formControls.Any())
                    {
                        int controlsCounter = 0;
                        foreach (var control in formControls)
                        {
                            controlsCounter++;
                            control.ID = string.Format(CultureInfo.InvariantCulture, formName + "_C" + controlsCounter.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0'));
                            var formControl = formManager.CreateControl <FormDraftControl>(control, "Body");

                            // Default value of BackwardCompatible does not translate ControllerName property which leads to unability to create forms in ML
                            formControl.GetType().GetProperty("Strategy", BindingFlags.Public | BindingFlags.Instance).SetValue(formControl, PropertyPersistenceStrategy.NotTranslatable);

                            formControl.SetPersistanceStrategy();
                            formControl.SiblingId = siblingId;
                            formControl.Caption   = ObjectFactory.Resolve <IControlBehaviorResolver>().GetBehaviorObject(control).GetType().Name;
                            siblingId             = formControl.Id;
                            master.Controls.Add(formControl);
                            formControl.SetPersistanceStrategy();
                        }
                    }

                    master = formManager.Lifecycle.CheckIn(master, culture);

                    if (publishForm)
                    {
                        formManager.Lifecycle.Publish(master, culture);
                    }

                    formManager.SaveChanges(true);
                }
            }
        }
コード例 #3
0
        private void AppendFormControlsToPlaceholder(string formName, IList <Control> formControls, FormsManager formManager, FormDraft master, string containerId)
        {
            if (formControls != null && formControls.Any())
            {
                Guid siblingId       = Guid.Empty;
                int  controlsCounter = 0;
                foreach (var control in formControls)
                {
                    controlsCounter++;
                    control.ID = string.Format(CultureInfo.InvariantCulture, formName + "_" + containerId + "_C" + controlsCounter.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0'));
                    var formControl = formManager.CreateControl <FormDraftControl>(control, containerId);

                    formControl.SiblingId = siblingId;
                    formControl.Caption   = ObjectFactory.Resolve <IControlBehaviorResolver>().GetBehaviorObject(control).GetType().Name;
                    siblingId             = formControl.Id;
                    master.Controls.Add(formControl);
                    formControl.SetPersistanceStrategy();
                }
            }
        }