private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { string treeId = this.GetBinding <string>("SelectedTreeId"); Tree tree = TreeFacade.GetTree(treeId); DynamicDataItemAttachmentPoint dataItemAttachmentPoint = (DynamicDataItemAttachmentPoint)tree.GetAttachmentPoints(this.EntityToken).Single(); TreeFacade.RemovePersistedAttachmentPoint(treeId, dataItemAttachmentPoint.InterfaceType, dataItemAttachmentPoint.KeyValue); this.RefreshCurrentEntityToken(); }
public PageTemplateFeatureElementProvider() { AuxiliarySecurityAncestorFacade.AddAuxiliaryAncestorProvider <PageTemplateFeatureEntityToken>(this); foreach (string pageTemplateFeratureFilename in this.PageTemplateFeatureFilenames) { string filename = Path.GetFileName(pageTemplateFeratureFilename); PageTemplateFeatureEntityToken entityToken = new PageTemplateFeatureEntityToken(PageTemplateFeatureEntityToken.FeatureId, filename); TreeFacade.AddCustomAttachmentPoint(filename, entityToken); } }
public DeveloperApplicationProvider() { AuxiliarySecurityAncestorFacade.AddAuxiliaryAncestorProvider <DeveloperApplicationProviderEntityToken>(this); foreach (string treeDefinitionFilename in this.TreeDefinitionFilenames) { string filename = Path.GetFileName(treeDefinitionFilename); DeveloperApplicationProviderEntityToken entityToken = new DeveloperApplicationProviderEntityToken(DeveloperApplicationProviderEntityToken.TreeDefinitionId, filename); TreeFacade.AddCustomAttachmentPoint(filename, entityToken); } }
/// <summary> /// Removes data items that refer to trees that are not registered. /// </summary> /// <param name="pageTypeTreeLinks"></param> /// <returns></returns> public static IEnumerable <IPageTypeTreeLink> RemoveDeadLinks(this IEnumerable <IPageTypeTreeLink> pageTypeTreeLinks) { foreach (IPageTypeTreeLink pageTypeTreeLink in pageTypeTreeLinks) { if (TreeFacade.GetTree(pageTypeTreeLink.TreeId) == null) { DataFacade.Delete <IPageTypeTreeLink>(pageTypeTreeLink); } else { yield return(pageTypeTreeLink); } } }
private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e) { DataEntityToken dataEntityToken = (DataEntityToken)this.EntityToken; object keyValue = dataEntityToken.DataSourceId.GetKeyValue(); string treeId = this.GetBinding <string>("SelectedTreeId"); string serializedPosition = this.GetBinding <string>("SelectedPosition"); ElementAttachingProviderPosition position = (ElementAttachingProviderPosition)Enum.Parse(typeof(ElementAttachingProviderPosition), serializedPosition); TreeFacade.AddPersistedAttachmentPoint(treeId, dataEntityToken.InterfaceType, keyValue, position); this.RefreshCurrentEntityToken(); }
internal static bool AddPageTypePageFoldersAndApplications(IPage page) { #warning Validate that having a page type with associated PageType PageFolders or Applications does not break on 2nd add for same page id Guid pageTypeId = page.PageTypeId; bool treeRefreshindNeeded = false; // Adding page folders IEnumerable <IPageTypeDataFolderTypeLink> pageTypeDataFolderTypeLinks = DataFacade.GetData <IPageTypeDataFolderTypeLink>(). Where(f => f.PageTypeId == pageTypeId). Evaluate(). RemoveDeadLinks(); foreach (IPageTypeDataFolderTypeLink pageTypeDataFolderTypeLink in pageTypeDataFolderTypeLinks) { page.AddFolderDefinition(pageTypeDataFolderTypeLink.DataTypeId); treeRefreshindNeeded = true; } // Adding applications IEnumerable <IPageTypeTreeLink> pageTypeTreeLinks = DataFacade.GetData <IPageTypeTreeLink>(). Where(f => f.PageTypeId == pageTypeId). Evaluate(). RemoveDeadLinks(); var entityToken = page.GetDataEntityToken(); foreach (IPageTypeTreeLink pageTypeTreeLink in pageTypeTreeLinks) { var tree = TreeFacade.GetTree(pageTypeTreeLink.TreeId); if (tree.HasAttachmentPoints(entityToken)) { continue; } TreeFacade.AddPersistedAttachmentPoint(pageTypeTreeLink.TreeId, typeof(IPage), page.Id); treeRefreshindNeeded = true; } return(treeRefreshindNeeded); }
private void IsMarkupValid(object sender, System.Workflow.Activities.ConditionalEventArgs e) { DeveloperApplicationProviderEntityToken castedEntityToken = (DeveloperApplicationProviderEntityToken)this.EntityToken; string content = this.GetBinding <string>("TreeDefinitionMarkup"); this.UpdateBinding("Errors", ""); XDocument document = null; try { document = XDocument.Parse(content); } catch (Exception ex) { this.UpdateBinding("Errors", ex.Message); e.Result = false; return; } Tree tree = TreeFacade.LoadTreeFromDom(castedEntityToken.Filename, document); ValidationError validationError = tree.BuildResult.ValidationErrors.FirstOrDefault(); if (validationError != null) { StringBuilder sb = new StringBuilder(); if (string.IsNullOrEmpty(validationError.XPath) == false) { sb.Append(validationError.Message); sb.Append(" at XPath: "); sb.Append(validationError.XPath); } else { sb.Append(validationError.Message); } this.UpdateBinding("Errors", sb.ToString()); } e.Result = tree.BuildResult.ValidationErrors.Count() == 0; }
private void stepFinalize_codeActivity_ExecuteCode(object sender, EventArgs e) { AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken); Guid parentId = GetParentId(); IPage newPage = this.GetBinding <IPage>("NewPage"); newPage.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name; IPageType selectedPageType = DataFacade.GetData <IPageType>().Single(f => f.Id == newPage.PageTypeId); IQueryable <IPageTypePageTemplateRestriction> templateRestrictions = DataFacade.GetData <IPageTypePageTemplateRestriction>(). Where(f => f.PageTypeId == newPage.PageTypeId); if (selectedPageType.DefaultTemplateId != Guid.Empty) { newPage.TemplateId = selectedPageType.DefaultTemplateId; } else if (templateRestrictions.Any()) { newPage.TemplateId = templateRestrictions.First().PageTemplateId; } bool addToTop = this.GetBinding <string>("SelectedSortOrder") == "Top"; bool addToBottom = this.GetBinding <string>("SelectedSortOrder") == "Bottom"; bool addToAlphabetic = this.GetBinding <string>("SelectedSortOrder") == "Alphabetic"; bool addToRelative = this.GetBinding <string>("SelectedSortOrder") == "Relative"; using (new DataScope(DataScopeIdentifier.Administrated)) { if (addToTop) { newPage = newPage.AddPageAtTop(parentId); } else if (addToBottom) { newPage = newPage.AddPageAtBottom(parentId); } else if (addToAlphabetic) { newPage = newPage.AddPageAlphabetic(parentId); } else if (addToRelative) { Guid relativeSelectedPageId = this.GetBinding <Guid>("RelativeSelectedPageId"); newPage = newPage.AddPageAfter(parentId, relativeSelectedPageId); } } // Adding default page content IEnumerable <IPageTypeDefaultPageContent> pageTypeDefaultPageContents = DataFacade.GetData <IPageTypeDefaultPageContent>(). Where(f => f.PageTypeId == selectedPageType.Id). Evaluate(); foreach (IPageTypeDefaultPageContent pageTypeDefaultPageContent in pageTypeDefaultPageContents) { IPagePlaceholderContent pagePlaceholderContent = DataFacade.BuildNew <IPagePlaceholderContent>(); pagePlaceholderContent.PageId = newPage.Id; pagePlaceholderContent.PlaceHolderId = pageTypeDefaultPageContent.PlaceHolderId; pagePlaceholderContent.Content = pageTypeDefaultPageContent.Content; DataFacade.AddNew <IPagePlaceholderContent>(pagePlaceholderContent); } // Adding page folders IEnumerable <IPageTypeDataFolderTypeLink> pageTypeDataFolderTypeLinks = DataFacade.GetData <IPageTypeDataFolderTypeLink>(). Where(f => f.PageTypeId == selectedPageType.Id). Evaluate(). RemoveDeadLinks(); foreach (IPageTypeDataFolderTypeLink pageTypeDataFolderTypeLink in pageTypeDataFolderTypeLinks) { newPage.AddFolderDefinition(pageTypeDataFolderTypeLink.DataTypeId); } // Adding applications IEnumerable <IPageTypeTreeLink> pageTypeTreeLinks = DataFacade.GetData <IPageTypeTreeLink>(). Where(f => f.PageTypeId == selectedPageType.Id). Evaluate(). RemoveDeadLinks(); foreach (IPageTypeTreeLink pageTypeTreeLink in pageTypeTreeLinks) { Tree tree = TreeFacade.GetTree(pageTypeTreeLink.TreeId); if (tree.HasAttachmentPoints(newPage.GetDataEntityToken())) { continue; } TreeFacade.AddPersistedAttachmentPoint(pageTypeTreeLink.TreeId, typeof(IPage), newPage.Id); } SetSaveStatus(true); addNewTreeRefresher.PostRefreshMesseges(newPage.GetDataEntityToken()); this.ExecuteWorklow(newPage.GetDataEntityToken(), typeof(EditPageWorkflow)); }
internal void CopyPageData(IPage sourcePage, IPage newPage) { Guid sourcePageId = sourcePage.Id; Guid newPageId = newPage.Id; Guid sourceVersionId = sourcePage.VersionId; Guid newVersionId = newPage.VersionId; var newPlaceholders = new List <IPagePlaceholderContent>(); var placeholders = DataFacade.GetData <IPagePlaceholderContent>(false) .Where(ph => ph.PageId == sourcePageId && ph.VersionId == sourceVersionId) .ToList(); foreach (var placeholderContent in placeholders) { var newPlaceholder = DataFacade.BuildNew <IPagePlaceholderContent>(); newPlaceholder.PageId = newPageId; newPlaceholder.PlaceHolderId = placeholderContent.PlaceHolderId; newPlaceholder.Content = placeholderContent.Content; newPlaceholder.VersionId = newVersionId; newPlaceholders.Add(newPlaceholder); } DataFacade.AddNew <IPagePlaceholderContent>(newPlaceholders); var sourceMetaData = sourcePage.GetMetaData().Cast <IPageMetaData>() .Where(d => d.VersionId == sourceVersionId); foreach (var metaDataItem in sourceMetaData) { var metaDataType = metaDataItem.DataSourceId.InterfaceType; var typeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(metaDataType.GetImmutableTypeId()); var definition = PageMetaDataFacade.GetMetaDataDefinition(sourcePageId, metaDataItem.GetTypeTitle()); var newDataItem = (IPageMetaData)DataFacade.BuildNew(metaDataType); var properties = metaDataType.GetPropertiesRecursively().ToDictionary(p => p.Name); foreach (var field in typeDescriptor.Fields) { var propertyInfo = properties[field.Name]; propertyInfo.SetValue(newDataItem, propertyInfo.GetValue(metaDataItem)); } newDataItem.VersionId = newVersionId; newDataItem.Id = Guid.NewGuid(); newDataItem.PageId = newPageId; newDataItem.PublicationStatus = GenericPublishProcessController.Draft; newDataItem = (IPageMetaData)DataFacade.AddNew((IData)newDataItem); if (definition != null) { string title = newDataItem.GetTypeTitle(); newPage.AddMetaDataDefinition(title, title, newDataItem.GetImmutableTypeId(), definition.MetaDataContainerId); } } List <string> selectableTreeIds = TreeFacade.AllTrees.Where( tree => tree.HasAttachmentPoints(sourcePage.GetDataEntityToken())) .Where(tree => !tree.HasAttachmentPoints(newPage.GetDataEntityToken())) .Select(tree => tree.TreeId).ToList(); foreach (var selectableTreeId in selectableTreeIds) { TreeFacade.AddPersistedAttachmentPoint(selectableTreeId, newPage.DataSourceId.InterfaceType, newPage.DataSourceId.GetKeyValue()); } foreach (var dataFolderType in sourcePage.GetDefinedFolderTypes()) { newPage.AddFolderDefinition(dataFolderType); } }
private void initializeCodeActivity_BuildNewData_ExecuteCode(object sender, EventArgs e) { Initialize(); this.FormsHelper.UpdateWithNewBindings(this.Bindings); IData newData = DataFacade.BuildNew(InterfaceType); if (PageFolderFacade.GetAllFolderTypes().Contains(InterfaceType)) { Dictionary <string, string> piggybag = PiggybagSerializer.Deserialize(this.ExtraPayload); var piggybagDataFinder = new PiggybagDataFinder(piggybag, this.EntityToken); IPage page = (IPage)piggybagDataFinder.TryGetData(typeof(IPage)); if (page != null) { PageFolderFacade.AssignFolderDataSpecificValues(newData, page); } } var publishControlled = newData as IPublishControlled; if (publishControlled != null) { publishControlled.PublicationStatus = GenericPublishProcessController.Draft; } var values = new Dictionary <string, string>(); var castedEntityToken = this.EntityToken as TreeDataFieldGroupingElementEntityToken; if (castedEntityToken != null) { Tree tree = TreeFacade.GetTree(castedEntityToken.Source); var treeNode = (DataFolderElementsTreeNode)tree.GetTreeNode(castedEntityToken.TreeNodeId); if (treeNode.Range == null && !treeNode.FirstLetterOnly) { foreach (var kvp in castedEntityToken.DeserializedGroupingValues) { values.Add(kvp.Key, ValueTypeConverter.Convert <string>(kvp.Value)); } } } var props = InterfaceType.GetPropertiesRecursively().ToDictionary(prop => prop.Name); foreach (var kvp in this.DataPayload) { // Filtering payload data which is not default field values if (props.ContainsKey(kvp.Key)) { values[kvp.Key] = StringConversionServices.DeserializeValueString(kvp.Value); } } newData.SetValues(values); this.FormsHelper.ObjectToBindings(newData, this.Bindings); GeneratedTypesHelper.SetNewIdFieldValue(newData); this.Bindings.Add("NewData", newData); }
private void saveCodeActivity_ExecuteCode(object sender, EventArgs e) { var updateTreeRefresher = CreateUpdateTreeRefresher(EntityToken); var selectedPage = GetBinding <IPage>("SelectedPage"); var originalPage = DataFacade.GetData <IPage>(f => f.Id == selectedPage.Id).SingleOrDefault(); var viewLabelUpdated = originalPage == null || selectedPage.MenuTitle != originalPage.MenuTitle || selectedPage.Title != originalPage.Title; var treeviewRequiresRefreshing = false; var dataToAdd = new Dictionary <string, IData>(); var dataToUpdate = new Dictionary <string, IData>(); var dataValidated = true; WorkflowInstance publishWorkflowInstance = null; WorkflowInstance unpublishWorkflowInstance = null; try { using (var transactionScope = TransactionsFacade.CreateNewScope()) { dataValidated = PrepareAddUpdateMetaData(selectedPage, dataToAdd, dataToUpdate); if (dataValidated) { PublishControlledHelper.HandlePublishUnpublishWorkflows(selectedPage, UserSettings.ActiveLocaleCultureInfo.Name, PublishDate, UnpublishDate, ref publishWorkflowInstance, ref unpublishWorkflowInstance); if (selectedPage.PageTypeId != originalPage.PageTypeId) { // Adding metadata fields var oldPageMetaDataDefinitions = originalPage.GetAllowedMetaDataDefinitions().Except(selectedPage.GetAllowedMetaDataDefinitions(), new PageMetaDataDefinitionEqualityComparer()); foreach (var pageMetaDataDefinition in oldPageMetaDataDefinitions) { var oldMetaData = selectedPage.GetMetaData(pageMetaDataDefinition.Name, pageMetaDataDefinition.MetaDataTypeId); if (oldMetaData != null) { ProcessControllerFacade.FullDelete(oldMetaData); } } // Adding page folders var pageTypeDataFolderTypeLinks = DataFacade.GetData <IPageTypeDataFolderTypeLink>(). Where(f => f.PageTypeId == selectedPage.PageTypeId). Evaluate(). RemoveDeadLinks(); foreach (var pageTypeDataFolderTypeLink in pageTypeDataFolderTypeLinks) { if (selectedPage.GetFolderDefinitionId(pageTypeDataFolderTypeLink.DataTypeId) != Guid.Empty) { continue; } selectedPage.AddFolderDefinition(pageTypeDataFolderTypeLink.DataTypeId); treeviewRequiresRefreshing = true; } // Adding applications var pageTypeTreeLinks = DataFacade.GetData <IPageTypeTreeLink>(). Where(f => f.PageTypeId == selectedPage.PageTypeId). Evaluate(). RemoveDeadLinks(); foreach (var pageTypeTreeLink in pageTypeTreeLinks) { var tree = TreeFacade.GetTree(pageTypeTreeLink.TreeId); if (tree.HasAttachmentPoints(selectedPage.GetDataEntityToken())) { continue; } TreeFacade.AddPersistedAttachmentPoint(pageTypeTreeLink.TreeId, typeof(IPage), selectedPage.Id); treeviewRequiresRefreshing = true; } } foreach (var data in dataToAdd.Values) { DataFacade.AddNew(data); } foreach (var data in dataToUpdate.Values) { var publishControlled = data as IPublishControlled; publishControlled.PublicationStatus = GenericPublishProcessController.Draft; DataFacade.Update(data); } treeviewRequiresRefreshing |= (originalPage.Title != selectedPage.Title) || (originalPage.Description != selectedPage.Description) || (originalPage.PublicationStatus != selectedPage.PublicationStatus); // NOTE: updating originalPage object, in order to make XML & SQL provider work in the same way originalPage.TemplateId = selectedPage.TemplateId; originalPage.PageTypeId = selectedPage.PageTypeId; originalPage.Title = selectedPage.Title; originalPage.MenuTitle = selectedPage.MenuTitle; originalPage.UrlTitle = selectedPage.UrlTitle; originalPage.FriendlyUrl = selectedPage.FriendlyUrl; originalPage.Description = selectedPage.Description; originalPage.PublicationStatus = selectedPage.PublicationStatus; originalPage.SourceCultureName = selectedPage.SourceCultureName; DataFacade.Update(originalPage); var contentDictionary = GetBinding <Dictionary <string, string> >("NamedXhtmlFragments"); var existingContents = DataFacade.GetData <IPagePlaceholderContent>(f => f.PageId == selectedPage.Id).ToList(); foreach (var existingContent in existingContents) { if (contentDictionary.ContainsKey(existingContent.PlaceHolderId)) { existingContent.Content = contentDictionary[existingContent.PlaceHolderId]; existingContent.PublicationStatus = GenericPublishProcessController.Draft; DataFacade.Update(existingContent); } else { DataFacade.Delete(existingContent); } } foreach (var contentDictionaryElement in contentDictionary.Where(f => existingContents.Any(existing => existing.PlaceHolderId == f.Key) == false)) { var newContent = DataFacade.BuildNew <IPagePlaceholderContent>(); newContent.PageId = selectedPage.Id; newContent.PlaceHolderId = contentDictionaryElement.Key; newContent.Content = contentDictionaryElement.Value; newContent.SourceCultureName = UserSettings.ActiveLocaleCultureInfo.Name; newContent.PublicationStatus = GenericPublishProcessController.Draft; DataFacade.AddNew(newContent); } } transactionScope.Complete(); } if (publishWorkflowInstance != null) { publishWorkflowInstance.Start(); WorkflowFacade.RunWorkflow(publishWorkflowInstance); } if (unpublishWorkflowInstance != null) { unpublishWorkflowInstance.Start(); WorkflowFacade.RunWorkflow(unpublishWorkflowInstance); } if (_doPublish) { if (publishWorkflowInstance == null || PublishDate < DateTime.Now) { var actionToken = new GenericPublishProcessController.PublishActionToken(); var serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId); ActionExecutorFacade.Execute(EntityToken, actionToken, serviceContainer); treeviewRequiresRefreshing = false; } else { var title = StringResourceSystemFacade.GetString("Composite.Management", "Website.Forms.Administrative.EditPage.PublishDatePreventPublishTitle"); var message = StringResourceSystemFacade.GetString("Composite.Management", "Website.Forms.Administrative.EditPage.PublishDatePreventPublish"); ShowMessage(DialogType.Warning, title, message); } } if (treeviewRequiresRefreshing) { updateTreeRefresher.PostRefreshMesseges(selectedPage.GetDataEntityToken()); } UpdateBinding("OldPublicationStatus", selectedPage.PublicationStatus); if (viewLabelUpdated) { RerenderView(); } } catch (Exception ex) { var mostSpecificException = ex; while (mostSpecificException.InnerException != null) { mostSpecificException = mostSpecificException.InnerException; } ShowMessage(DialogType.Error, "Save failed", string.Format("Save failed: {0}", mostSpecificException.Message)); Log.LogError("Page save", ex); } finally { SetSaveStatus(dataValidated); } }