private void enterDataCodeActivity_ExecuteCode(object sender, EventArgs e) { var dataTypeDescriptor = GetBinding <DataTypeDescriptor>("DataTypeDescriptor"); var type = TypeManager.GetType(dataTypeDescriptor.TypeManagerTypeName); var page = GetBinding <IData>("Data") as IPage; var helper = new DataTypeDescriptorFormsHelper(dataTypeDescriptor, true, page.GetDataEntityToken()) { LayoutIconHandle = "associated-data-add" }; var generatedTypesHelper = new GeneratedTypesHelper(dataTypeDescriptor); helper.AddReadOnlyFields(generatedTypesHelper.NotEditableDataFieldDescriptorNames); IData newData; if (!BindingExist("NewData")) { newData = DataFacade.BuildNew(type); PageFolderFacade.AssignFolderDataSpecificValues(newData, page); var publishControlled = newData as IPublishControlled; if (publishControlled != null) { publishControlled.PublicationStatus = GenericPublishProcessController.Draft; } var localizedData = newData as ILocalizedControlled; if (localizedData != null) { var cultureInfo = UserSettings.ActiveLocaleCultureInfo ?? DataLocalizationFacade.DefaultLocalizationCulture; localizedData.SourceCultureName = cultureInfo.Name; } Bindings.Add("NewData", newData); helper.UpdateWithNewBindings(Bindings); helper.ObjectToBindings(newData, Bindings); } else { newData = GetBinding <IData>("NewData"); } DeliverFormData( type.Name, StandardUiContainerTypes.Document, helper.GetForm(), Bindings, helper.GetBindingsValidationRules(newData) ); }
public static void InsertForm(Control control, ParameterList parameters) { Page currentPageHandler = HttpContext.Current.Handler as Page; if (currentPageHandler == null) { throw new InvalidOperationException("The Current HttpContext Handler must be a System.Web.Ui.Page"); } Type dataType = null; DataTypeDescriptor dataTypeDescriptor = null; string dataTypeName = parameters.GetParameter <string>("DataType"); dataType = TypeManager.GetType(dataTypeName); dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(dataType); IFormChannelIdentifier channelIdentifier = FormsRendererChannel.Identifier; formHelper = new DataTypeDescriptorFormsHelper(dataTypeDescriptor); newData = DataFacade.BuildNew(dataType); GeneratedTypesHelper.SetNewIdFieldValue(newData); //Hide not editable fields, fox example - PageId GeneratedTypesHelper generatedTypesHelper = new GeneratedTypesHelper(dataTypeDescriptor); formHelper.AddReadOnlyFields(generatedTypesHelper.NotEditableDataFieldDescriptorNames); //If is Page Datatype if (PageFolderFacade.GetAllFolderTypes().Contains(dataType)) { IPage currentPage = PageRenderer.CurrentPage; if (currentPage.GetDefinedFolderTypes().Contains(dataType) == false) { currentPage.AddFolderDefinition(dataType.GetImmutableTypeId()); } PageFolderFacade.AssignFolderDataSpecificValues(newData, currentPage); } _compiler = new FormTreeCompiler(); //bindings = formHelper.GetBindings(newData); bindings = new Dictionary <string, object>(); formHelper.UpdateWithNewBindings(bindings); formHelper.ObjectToBindings(newData, bindings); using (XmlReader reader = XDocument.Parse(formHelper.GetForm()).CreateReader()) { try { _compiler.Compile(reader, channelIdentifier, bindings, formHelper.GetBindingsValidationRules(newData)); #region ClientValidationRules clientValidationRules = new Dictionary <string, List <ClientValidationRule> >(); foreach (var item in _compiler.GetField <object>("_context").GetProperty <IEnumerable>("Rebindings")) { var SourceProducer = item.GetProperty <object>("SourceProducer"); var uiControl = SourceProducer as IWebUiControl; if (uiControl != null) { clientValidationRules[uiControl.UiControlID] = uiControl.ClientValidationRules; } } #endregion } catch (ConfigurationErrorsException e) { if (e.Message.Contains("Failed to load the configuration for IUiControlFactory")) { throw new ConfigurationErrorsException("Composite.Forms.Renderer does not support widget. " + e.Message); } else { throw new ConfigurationErrorsException(e.Message); } } } webUiControl = (IWebUiControl)_compiler.UiControl; Control form = webUiControl.BuildWebControl(); control.Controls.Add(form); /*if (currentPageHandler.IsPostBack) * try * { * compiler.SaveControlProperties(); * } * catch { }*/ if (!currentPageHandler.IsPostBack) { webUiControl.InitializeViewState(); } return; }