private bool PrepareAddUpdateMetaData(IPage selectedPage, IDictionary <string, IData> dataToAdd, IDictionary <string, IData> dataToUpdate) { var isValid = ValidateBindings(); IEnumerable <IPageMetaDataDefinition> pageMetaDataDefinitions = selectedPage.GetAllowedMetaDataDefinitions().Evaluate(); foreach (var pageMetaDataDefinition in pageMetaDataDefinitions) { var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(pageMetaDataDefinition.MetaDataTypeId); var metaDataType = TypeManager.GetType(dataTypeDescriptor.TypeManagerTypeName); var helper = CreateDataTypeDescriptorFormsHelper(pageMetaDataDefinition, dataTypeDescriptor); var metaData = selectedPage.GetMetaData(pageMetaDataDefinition.Name, metaDataType); if (metaData == null) { var newData = DataFacade.BuildNew(metaDataType); PageMetaDataFacade.AssignMetaDataSpecificValues(newData, pageMetaDataDefinition.Name, selectedPage); var localizedData = newData as ILocalizedControlled; if (localizedData != null) { localizedData.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name; } if (!BindAndValidate(helper, newData)) { isValid = false; } dataToAdd.Add(helper.BindingNamesPrefix, newData); } else { if (!BindAndValidate(helper, metaData)) { isValid = false; } dataToUpdate.Add(helper.BindingNamesPrefix, metaData); } } var pageValidationResults = ValidationFacade.Validate(selectedPage); if (!pageValidationResults.IsValid) { isValid = false; } foreach (var kvp in dataToAdd.Concat(dataToUpdate)) { var validationResults = ValidationFacade.Validate(kvp.Value); if (!validationResults.IsValid) { isValid = false; foreach (var result in validationResults) { ShowFieldMessage(DataTypeDescriptorFormsHelper.GetBindingName(kvp.Key, result.Key), result.Message); } } } return(isValid); }
private void editStateCodeActivity_ExecuteCode(object sender, EventArgs e) { if (!PermissionsFacade.GetPermissionsForCurrentUser(EntityToken).Contains(PermissionType.Publish)) { var formData = WorkflowFacade.GetFormData(InstanceId, true); if (formData.ExcludedEvents == null) { formData.ExcludedEvents = new List <string>(); } formData.ExcludedEvents.Add("SaveAndPublish"); } IPage selectedPage; if (!BindingExist("SelectedPage")) { selectedPage = GetDataItemFromEntityToken <IPage>(); if (selectedPage.PublicationStatus == GenericPublishProcessController.Published) { selectedPage.PublicationStatus = GenericPublishProcessController.Draft; } Bindings.Add("SelectedPage", selectedPage); } else { selectedPage = GetBinding <IPage>("SelectedPage"); } if (!BindingExist("UrlTitleIsRequired")) { var isRootPage = PageManager.GetParentId(selectedPage.Id) == Guid.Empty; Bindings["UrlTitleIsRequired"] = !isRootPage; Bindings["IsRootPage"] = isRootPage; } IFormMarkupProvider markupProvider = new FormDefinitionFileMarkupProvider(@"\Administrative\EditPage.xml"); XDocument formDocument; using (var reader = markupProvider.GetReader()) { formDocument = XDocument.Load(reader); } var bindingsXElement = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Bindings); var layoutXElement = formDocument.Root.Element(DataTypeDescriptorFormsHelper.CmsNamespace + FormKeyTagNames.Layout); var tabPanelsXElement = layoutXElement.Element(DataTypeDescriptorFormsHelper.MainNamespace + "TabPanels"); IEnumerable <ICompositionContainer> compositionContainers = selectedPage.GetAllowedMetaDataContainers().Evaluate(); var compositionTabs = new Dictionary <Guid, XElement>(); foreach (var compositionContainer in compositionContainers) { var element = new XElement(Namespaces.BindingFormsStdUiControls10 + "PlaceHolder"); element.Add(new XAttribute("Label", StringResourceSystemFacade.ParseString(compositionContainer.Label))); compositionTabs.Add(compositionContainer.Id, element); } var clientValidationRules = new Dictionary <string, List <ClientValidationRule> >(); var pageMetaDataDefinitions = selectedPage.GetAllowedMetaDataDefinitions(); foreach (var pageMetaDataDefinition in pageMetaDataDefinitions) { var metaDatTypeId = pageMetaDataDefinition.MetaDataTypeId; var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(metaDatTypeId); Verify.IsNotNull(dataTypeDescriptor, "Failed to get meta data type by id '{0}'. If data type was purposely removed, in order to fix this exception you should remove IPageMetaDataDefinition records that reference this data type.", metaDatTypeId); var metaDataType = TypeManager.TryGetType(dataTypeDescriptor.TypeManagerTypeName); Verify.IsNotNull(metaDataType, "Failed to get meta data type '{0}', id: {1}. If it has been removed, references from '{2}' have to be removed as well", dataTypeDescriptor.TypeManagerTypeName, metaDatTypeId, typeof(IPageMetaDataDefinition).Name); var helper = CreateDataTypeDescriptorFormsHelper(pageMetaDataDefinition, dataTypeDescriptor); var metaData = selectedPage.GetMetaData(pageMetaDataDefinition.Name, metaDataType); if (metaData == null) { metaData = DataFacade.BuildNew(metaDataType); PageMetaDataFacade.AssignMetaDataSpecificValues(metaData, pageMetaDataDefinition.Name, selectedPage); var localizedData = metaData as ILocalizedControlled; if (localizedData != null) { localizedData.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name; } var publishControlled = metaData as IPublishControlled; publishControlled.PublicationStatus = GenericPublishProcessController.Draft; helper.UpdateWithNewBindings(Bindings); helper.ObjectToBindings(metaData, Bindings); } else { helper.UpdateWithBindings(metaData, Bindings); } bindingsXElement.Add(helper.BindingXml.Elements()); compositionTabs[pageMetaDataDefinition.MetaDataContainerId].Add(helper.PanelXml); clientValidationRules.AddDictionary(helper.GetBindingsValidationRules(metaData)); } var previewTabPanel = tabPanelsXElement.Elements().Last(); foreach (var element in compositionTabs.Values) { previewTabPanel.AddBeforeSelf(element); } IDictionary <string, string> transitionNames = new Dictionary <string, string>(); transitionNames.Add(GenericPublishProcessController.Draft, StringResourceSystemFacade.GetString("Composite.Management", "PublishingStatus.draft")); transitionNames.Add(GenericPublishProcessController.AwaitingApproval, StringResourceSystemFacade.GetString("Composite.Management", "PublishingStatus.awaitingApproval")); var username = UserValidationFacade.GetUsername(); var userPermissionDefinitions = PermissionTypeFacade.GetUserPermissionDefinitions(username); var userGroupPermissionDefinitions = PermissionTypeFacade.GetUserGroupPermissionDefinitions(username); var currentPermissionTypes = PermissionTypeFacade.GetCurrentPermissionTypes(UserValidationFacade.GetUserToken(), EntityToken, userPermissionDefinitions, userGroupPermissionDefinitions); foreach (var permissionType in currentPermissionTypes) { if (GenericPublishProcessController.AwaitingPublicationActionPermissionType.Contains(permissionType)) { transitionNames.Add(GenericPublishProcessController.AwaitingPublication, StringResourceSystemFacade.GetString("Composite.Management", "PublishingStatus.awaitingPublication")); break; } } var contents = DataFacade.GetData <IPagePlaceholderContent>(f => f.PageId == selectedPage.Id && f.VersionId == selectedPage.VersionId).ToList(); var namedXhtmlFragments = contents.ToDictionary(content => content.PlaceHolderId, content => content.Content ?? ""); UpdateBinding("SelectablePageTypeIds", GetSelectablePageTypes()); UpdateBinding("SelectableTemplateIds", GetSelectablePageTemplates()); UpdateBinding("NamedXhtmlFragments", namedXhtmlFragments); UpdateBinding("StateOptions", transitionNames); var formDefinition = formDocument.GetDocumentAsString(); DeliverFormData( selectedPage.Title, StandardUiContainerTypes.Document, formDefinition, Bindings, clientValidationRules ); }