private static void ResolvePlaceholders(XDocument document, IEnumerable <IPagePlaceholderContent> placeholderContents)
        {
            using (TimerProfilerFacade.CreateTimerProfiler())
            {
                var placeHolders =
                    (from placeholder in document.Descendants(RenderingElementNames.PlaceHolder)
                     let idAttribute = placeholder.Attribute(RenderingElementNames.PlaceHolderIdAttribute)
                                       where idAttribute != null
                                       select new { Element = placeholder, IdAttribute = idAttribute }).ToList();

                foreach (var placeholder in placeHolders)
                {
                    string placeHolderId = placeholder.IdAttribute.Value;
                    placeholder.IdAttribute.Remove();

                    IPagePlaceholderContent placeHolderContent =
                        placeholderContents.FirstOrDefault(f => f.PlaceHolderId == placeHolderId);

                    XhtmlDocument xhtmlDocument = ParsePlaceholderContent(placeHolderContent);
                    placeholder.Element.ReplaceWith(xhtmlDocument.Root);

                    //try
                    //{
                    //    placeholder.Element.Add(new XAttribute(RenderingElementNames.PlaceHolderIdAttribute, placeHolderId));
                    //}
                    //catch (Exception ex)
                    //{
                    //    throw new InvalidOperationException($"Failed to set id '{placeHolderId}' on element", ex);
                    //}
                }
            }
        }
        private void editPreviewCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            try
            {
                XhtmlDocument templateDocument = GetTemplateDocumentFromBindings();

                IVisualFunction function      = this.GetBinding <IVisualFunction>("Function");
                Type            interfaceType = TypeManager.GetType(function.TypeManagerName);

                DataTypeDescriptor typeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType);

                this.LogMessage(Composite.Core.Logging.LogLevel.Info, DataScopeManager.CurrentDataScope.Name);

                FunctionContextContainer fcc = PageRenderer.GetPageRenderFunctionContextContainer();

                XhtmlDocument result = RenderingHelper.RenderCompleteDataList(function, templateDocument, typeDescriptor, fcc);

                IPage previewPage = DataFacade.BuildNew <IPage>();
                previewPage.Id    = GetRootPageId();
                previewPage.Title = function.Name;
                previewPage.DataSourceId.DataScopeIdentifier = DataScopeIdentifier.Administrated;
                previewPage.DataSourceId.LocaleScope         = LocalizationScopeManager.CurrentLocalizationScope;

                previewPage.TemplateId = this.GetBinding <Guid>("PreviewTemplateId");

                var pageTemplate = PageTemplateFacade.GetPageTemplate(previewPage.TemplateId);
                IPagePlaceholderContent placeHolderContent = DataFacade.BuildNew <IPagePlaceholderContent>();
                placeHolderContent.Content       = string.Concat((result.Body.Elements().Select(b => b.ToString())).ToArray());
                placeHolderContent.PlaceHolderId = pageTemplate.DefaultPlaceholderId;

                string output = PagePreviewBuilder.RenderPreview(previewPage, new List <IPagePlaceholderContent> {
                    placeHolderContent
                });

                var serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);

                var webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>();
                webRenderService.SetNewPageOutput(new LiteralControl(output));
            }
            catch (Exception ex)
            {
                FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
                Control errOutput        = new LiteralControl("<pre>" + ex + "</pre>");
                var     webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>();
                webRenderService.SetNewPageOutput(errOutput);
            }
        }
        /// <exclude />
        public static XhtmlDocument ParsePlaceholderContent(IPagePlaceholderContent placeholderContent)
        {
            if (string.IsNullOrEmpty(placeholderContent?.Content))
            {
                return(new XhtmlDocument());
            }

            if (placeholderContent.Content.StartsWith("<html"))
            {
                try
                {
                    return(XhtmlDocument.Parse(placeholderContent.Content));
                }
                catch (Exception) { }
            }

            return(XhtmlDocument.Parse($"<html xmlns='{Namespaces.Xhtml}'><head/><body>{placeholderContent.Content}</body></html>"));
        }
Example #4
0
        public string SavePageContent(string pageId, string placeholderId, string content)
        {
            Guid   pageGuid    = Guid.Parse(pageId);
            string contentHtml = HttpUtility.UrlDecode(content);

            contentHtml = HttpUtility.HtmlDecode(contentHtml.Replace("&amp;", "&amp;amp;").Replace("&lt;", "&amp;lt;").Replace("&gt;", "&amp;gt;"));

            string   xhtmlDocumentWrapper = string.Format("<html xmlns='http://www.w3.org/1999/xhtml'><head></head><body>{0}</body></html>", contentHtml);
            XElement xElement             = XElement.Parse(xhtmlDocumentWrapper);

            RemoveInvalidElements(xElement);

            contentHtml = string.Concat((xElement.Elements().Select(b => b.ToString())).ToArray());
            foreach (PublicationScope scope in Enum.GetValues(typeof(PublicationScope)))
            {
                using (DataConnection connection = new DataConnection(scope))
                {
                    var phHolder = Composite.Data.PageManager.GetPlaceholderContent(pageGuid).Where(ph => ph.PlaceHolderId == placeholderId).SingleOrDefault();
                    if (phHolder != null)
                    {
                        phHolder.Content = contentHtml;
                        connection.Update <IPagePlaceholderContent>(phHolder);
                    }
                    else
                    {
                        var page         = connection.Get <IPage>().Where(p => p.Id == pageGuid).SingleOrDefault();
                        var templateInfo = TemplateInfo.GetRenderingPlaceHolders(page.TemplateId);
                        foreach (var ph in templateInfo.Placeholders)
                        {
                            if (ph.Key == placeholderId)
                            {
                                IPagePlaceholderContent newPh = connection.CreateNew <IPagePlaceholderContent>();
                                newPh.PageId        = pageGuid;
                                newPh.PlaceHolderId = placeholderId;
                                newPh.Content       = contentHtml;
                                connection.Add <IPagePlaceholderContent>(newPh);
                            }
                        }
                    }
                }
            }
            return("Success");
        }
Example #5
0
        private static void ResolvePlaceholders(XDocument document, IEnumerable <IPagePlaceholderContent> placeholderContents)
        {
            using (TimerProfilerFacade.CreateTimerProfiler())
            {
                List <XElement> placeHolders = document.Descendants(RenderingElementNames.PlaceHolder).ToList();

                if (placeHolders.Any())
                {
                    foreach (XElement placeHolder in placeHolders.Where(f => f.Attribute(RenderingElementNames.PlaceHolderIdAttribute) != null))
                    {
                        IPagePlaceholderContent placeHolderContent =
                            placeholderContents
                            .FirstOrDefault(f => f.PlaceHolderId == placeHolder.Attribute(RenderingElementNames.PlaceHolderIdAttribute).Value);

                        string placeHolderId = null;

                        XAttribute idAttribute = placeHolder.Attribute("id");
                        if (idAttribute != null)
                        {
                            placeHolderId = idAttribute.Value;
                            idAttribute.Remove();
                        }

                        XhtmlDocument xhtmlDocument = ParsePlaceholderContent(placeHolderContent);
                        placeHolder.ReplaceWith(xhtmlDocument.Root);


                        if (placeHolderId != null)
                        {
                            try
                            {
                                placeHolder.Add(new XAttribute("id", placeHolderId));
                            }
                            catch (Exception ex)
                            {
                                throw new InvalidOperationException($"Failed to set id '{placeHolderId}' on element", ex);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Replaces &lt;rendering:placeholder  ... /&gt; tags with provided placeholder contents. Used by <see cref="XmlPageRenderer"/>.
        /// </summary>
        /// <param name="document">The document to be updated.</param>
        /// <param name="placeholderContents">The placeholder content to be used.</param>
        internal static void ResolvePlaceholders(XDocument document, IEnumerable <IPagePlaceholderContent> placeholderContents)
        {
            using (TimerProfilerFacade.CreateTimerProfiler())
            {
                var placeHolders =
                    (from placeholder in document.Descendants(RenderingElementNames.PlaceHolder)
                     let idAttribute = placeholder.Attribute(RenderingElementNames.PlaceHolderIdAttribute)
                                       where idAttribute != null
                                       select new { Element = placeholder, IdAttribute = idAttribute }).ToList();

                foreach (var placeholder in placeHolders)
                {
                    string placeHolderId = placeholder.IdAttribute.Value;
                    placeholder.IdAttribute.Remove();

                    IPagePlaceholderContent placeHolderContent =
                        placeholderContents.FirstOrDefault(f => f.PlaceHolderId == placeHolderId);

                    XhtmlDocument xhtmlDocument = ParsePlaceholderContent(placeHolderContent);
                    placeholder.Element.ReplaceWith(xhtmlDocument.Root);
                }
            }
        }
        /// <summary>
        /// Creates page type related data for a newly created IPage, based on a given page type id.
        /// Including: default placeholder content, page folders, page applications.
        /// </summary>
        /// <param name="page"></param>
        public static void AddPageTypeRelatedData(IPage page)
        {
            Guid pageTypeId = page.PageTypeId;

            Verify.That(pageTypeId != Guid.Empty, "PageTypeId field should not be Guid.Empty");

            // Adding default page content
            IEnumerable <IPageTypeDefaultPageContent> pageTypeDefaultPageContents =
                DataFacade.GetData <IPageTypeDefaultPageContent>().
                Where(f => f.PageTypeId == pageTypeId).
                Evaluate();

            foreach (IPageTypeDefaultPageContent pageTypeDefaultPageContent in pageTypeDefaultPageContents)
            {
                IPagePlaceholderContent pagePlaceholderContent = DataFacade.BuildNew <IPagePlaceholderContent>();
                pagePlaceholderContent.PageId        = page.Id;
                pagePlaceholderContent.VersionId     = page.VersionId;
                pagePlaceholderContent.PlaceHolderId = pageTypeDefaultPageContent.PlaceHolderId;
                pagePlaceholderContent.Content       = pageTypeDefaultPageContent.Content;
                DataFacade.AddNew <IPagePlaceholderContent>(pagePlaceholderContent);
            }

            AddPageTypePageFoldersAndApplications(page);
        }
Example #8
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));
        }
        private void initializeCodeActivity_Copy_ExecuteCode(object sender, EventArgs e)
        {
            var castedEntityToken = (DataEntityToken)this.EntityToken;

            IPage newPage;

            using (var transactionScope = TransactionsFacade.CreateNewScope())
            {
                CultureInfo sourceCultureInfo = UserSettings.ForeignLocaleCultureInfo;

                IPage sourcePage;
                List <IPagePlaceholderContent> sourcePagePlaceholders;
                List <IData> sourceMetaDataSet;

                using (new DataScope(sourceCultureInfo))
                {
                    var  pageFromEntityToken = (IPage)castedEntityToken.Data;
                    Guid sourcePageId        = pageFromEntityToken.Id;
                    Guid sourcePageVersionId = pageFromEntityToken.VersionId;

                    using (new DataScope(DataScopeIdentifier.Administrated))
                    {
                        sourcePage = DataFacade.GetData <IPage>(f => f.Id == sourcePageId).Single();
                        sourcePage = sourcePage.GetTranslationSource();

                        using (new DataScope(sourcePage.DataSourceId.DataScopeIdentifier))
                        {
                            sourcePagePlaceholders = DataFacade
                                                     .GetData <IPagePlaceholderContent>(f => f.PageId == sourcePageId && f.VersionId == sourcePageVersionId)
                                                     .ToList();
                            sourceMetaDataSet = sourcePage.GetMetaData().ToList();
                        }
                    }
                }


                CultureInfo targetCultureInfo = UserSettings.ActiveLocaleCultureInfo;

                using (new DataScope(targetCultureInfo))
                {
                    newPage = DataFacade.BuildNew <IPage>();
                    sourcePage.ProjectedCopyTo(newPage);

                    newPage.SourceCultureName = targetCultureInfo.Name;
                    newPage.PublicationStatus = GenericPublishProcessController.Draft;
                    newPage = DataFacade.AddNew <IPage>(newPage);

                    foreach (IPagePlaceholderContent sourcePagePlaceholderContent in sourcePagePlaceholders)
                    {
                        IPagePlaceholderContent newPagePlaceholderContent = DataFacade.BuildNew <IPagePlaceholderContent>();
                        sourcePagePlaceholderContent.ProjectedCopyTo(newPagePlaceholderContent);

                        newPagePlaceholderContent.SourceCultureName = targetCultureInfo.Name;
                        newPagePlaceholderContent.PublicationStatus = GenericPublishProcessController.Draft;
                        DataFacade.AddNew <IPagePlaceholderContent>(newPagePlaceholderContent);
                    }

                    foreach (IData metaData in sourceMetaDataSet)
                    {
                        ILocalizedControlled localizedData = metaData as ILocalizedControlled;

                        if (localizedData == null)
                        {
                            continue;
                        }

                        IEnumerable <ReferenceFailingPropertyInfo> referenceFailingPropertyInfos = DataLocalizationFacade.GetReferencingLocalizeFailingProperties(localizedData).Evaluate();

                        if (!referenceFailingPropertyInfos.Any())
                        {
                            IData newMetaData = DataFacade.BuildNew(metaData.DataSourceId.InterfaceType);
                            metaData.ProjectedCopyTo(newMetaData);

                            ILocalizedControlled localizedControlled = newMetaData as ILocalizedControlled;
                            localizedControlled.SourceCultureName = targetCultureInfo.Name;

                            IPublishControlled publishControlled = newMetaData as IPublishControlled;
                            publishControlled.PublicationStatus = GenericPublishProcessController.Draft;

                            DataFacade.AddNew(newMetaData);
                        }
                        else
                        {
                            foreach (ReferenceFailingPropertyInfo referenceFailingPropertyInfo in referenceFailingPropertyInfos)
                            {
                                Log.LogVerbose("LocalizePageWorkflow",
                                               "Meta data of type '{0}' is not localized because the field '{1}' is referring some not yet localzed data"
                                               .FormatWith(metaData.DataSourceId.InterfaceType, referenceFailingPropertyInfo.DataFieldDescriptor.Name));
                            }
                        }
                    }
                }

                EntityTokenCacheFacade.ClearCache(sourcePage.GetDataEntityToken());
                EntityTokenCacheFacade.ClearCache(newPage.GetDataEntityToken());

                foreach (var folderType in PageFolderFacade.GetDefinedFolderTypes(newPage))
                {
                    EntityTokenCacheFacade.ClearCache(new AssociatedDataElementProviderHelperEntityToken(
                                                          TypeManager.SerializeType(typeof(IPage)),
                                                          PageElementProvider.DefaultConfigurationName,
                                                          newPage.Id.ToString(),
                                                          TypeManager.SerializeType(folderType)));
                }


                transactionScope.Complete();
            }

            ParentTreeRefresher parentTreeRefresher = this.CreateParentTreeRefresher();

            parentTreeRefresher.PostRefreshMesseges(newPage.GetDataEntityToken(), 2);

            this.ExecuteWorklow(newPage.GetDataEntityToken(), typeof(EditPageWorkflow));
        }
Example #10
0
        public static void BindPlaceholder(object templateModel, PropertyInfo property, IPagePlaceholderContent content)
        {
            var rootDocument = PageRenderer.ParsePlaceholderContent(content);

            PageRenderer.ResolveRelativePaths(rootDocument);

            if (property.ReflectedType != null && !property.ReflectedType.IsInstanceOfType(templateModel))
            {
                var name = property.Name;
                property = templateModel.GetType().GetProperty(property.Name);

                Verify.IsNotNull(property, "Failed to find placeholder property '{0}'", new object[] { name });
            }

            property.SetValue(templateModel, rootDocument);
        }
        protected virtual void EnsureSubCategoryPages(TreeNode <Category> subCategory, CategoryPageData pageData)
        {
            var isLandingPage = subCategory.GetLevel() <= CategoriesConfiguration.LandingPageMaxLevel;
            var pageTypeId    = isLandingPage ? CategoryPages.CategoryLandingPageTypeId : CategoryPages.CategoryPageTypeId;

            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                IPage source = null;

                var sourceData = pageData.Default;
                if (!CategoryExist(subCategory.Value, sourceData))
                {
                    using (var connection = new DataConnection(PublicationScope.Unpublished, pageData.Default.Culture))
                    {
                        // Get default page content
                        // TODO: Do it only once

                        var pageTypeDefaultPageContents =
                            DataFacade.GetData <IPageTypeDefaultPageContent>().
                            Where(f => f.PageTypeId == pageTypeId).
                            Evaluate();

                        // Add page to parent
                        var catPage = connection.CreateNew <IPage>();
                        FillCategoryPage(catPage, pageTypeId, subCategory, connection.CurrentLocale);
                        var parentParentId = subCategory.GetLevel() == 1
                                                        ? RootPageId
                                                        : GenerateCategoryPageId(subCategory.Parent.Value.Id);

                        catPage.AddPageAtBottom(parentParentId);

                        // Add ComposerCategoryPage MetaData info
                        AddCategoryPageInfo(subCategory, connection, catPage, isLandingPage, false);

                        // Add default page content
                        foreach (IPageTypeDefaultPageContent pageTypeDefaultPageContent in pageTypeDefaultPageContents)
                        {
                            IPagePlaceholderContent pagePlaceholderContent = DataFacade.BuildNew <IPagePlaceholderContent>();
                            pagePlaceholderContent.PageId        = catPage.Id;
                            pagePlaceholderContent.PlaceHolderId = pageTypeDefaultPageContent.PlaceHolderId;
                            pagePlaceholderContent.Content       = pageTypeDefaultPageContent.Content;
                            DataFacade.AddNew <IPagePlaceholderContent>(pagePlaceholderContent);
                        }

                        // Update page again to force publish
                        var addedPage = DataFacade.GetData <IPage>(p => p.Id == catPage.Id);

                        DataFacade.Update(addedPage);
                    }
                }

                foreach (var localizedData in pageData.Others)
                {
                    if (!CategoryExist(subCategory.Value, localizedData))
                    {
                        using (var locConnection = new DataConnection(PublicationScope.Unpublished, localizedData.Culture))
                        {
                            if (source == null)
                            {
                                var sourceId = GenerateCategoryPageId(subCategory.Value.Id);
                                using (var connection = new DataConnection(PublicationScope.Unpublished, pageData.Default.Culture))
                                {
                                    source = connection.Get <IPage>().FirstOrDefault(p => p.Id == sourceId);
                                }
                                if (source == null)
                                {
                                    //TODO: Log
                                    continue;
                                }
                                var localizedPage = CompositeLanguageFacade.TranslatePage(source, pageData.Default.Culture, localizedData.Culture);
                                FillCategoryPage(localizedPage, pageTypeId, subCategory, localizedData.Culture);
                                AddCategoryPageInfo(subCategory, locConnection, localizedPage, isLandingPage, false);
                                locConnection.Update(localizedPage);
                            }
                        }
                    }
                }
                transaction.Complete();
            }

            if (subCategory.Children == null)
            {
                return;
            }

            if (isLandingPage)
            {
                CreateCategoryAllProductsPage(subCategory, pageData);
            }

            foreach (var child in subCategory.Children)
            {
                EnsureSubCategoryPages(child, pageData);
            }
        }
        private void undoCodeActivity_Undo_ExecuteCode(object sender, EventArgs e)
        {
            DataEntityToken dataEntityToken = (DataEntityToken)this.EntityToken;

            List <string> propertyNamesToIgnore = new List <string> {
                "PublicationStatus"
            };

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                IPage administrativePage = (IPage)dataEntityToken.Data;
                IPage publicPage         = DataFacade.GetDataFromOtherScope <IPage>(administrativePage, DataScopeIdentifier.Public).Single();

                List <IData> administrativeCompositions = administrativePage.GetMetaData(DataScopeIdentifier.Administrated).ToList();
                List <IData> publicCompositions         = publicPage.GetMetaData(DataScopeIdentifier.Public).ToList();

                Guid pageId    = administrativePage.Id;
                Guid versionId = administrativePage.VersionId;

                List <IPagePlaceholderContent> administrativePlaceholders;
                using (new DataScope(DataScopeIdentifier.Administrated))
                {
                    administrativePlaceholders =
                        (from ph in DataFacade.GetData <IPagePlaceholderContent>(false)
                         where ph.PageId == pageId && ph.VersionId == versionId
                         select ph).ToList();
                }

                List <IPagePlaceholderContent> publicPlaceholders;
                using (new DataScope(DataScopeIdentifier.Public))
                {
                    publicPlaceholders =
                        (from ph in DataFacade.GetData <IPagePlaceholderContent>(false)
                         where ph.PageId == pageId && ph.VersionId == versionId
                         select ph).ToList();
                }

                using (ProcessControllerFacade.NoProcessControllers)
                {
                    publicPage.FullCopyChangedTo(administrativePage, propertyNamesToIgnore);
                    DataFacade.Update(administrativePage);

                    foreach (IData publicComposition in publicCompositions)
                    {
                        IData administrativeComposition =
                            (from com in administrativeCompositions
                             where com.DataSourceId.DataId.CompareTo(publicComposition.DataSourceId.DataId, false)
                             select com).Single();

                        publicComposition.FullCopyChangedTo(administrativeComposition, propertyNamesToIgnore);
                        DataFacade.Update(administrativeComposition);
                    }

                    foreach (IPagePlaceholderContent publicPagePlaceholderContent in publicPlaceholders)
                    {
                        IPagePlaceholderContent administrativePagePlaceholderContent =
                            (from pc in administrativePlaceholders
                             where pc.PlaceHolderId == publicPagePlaceholderContent.PlaceHolderId
                             select pc).Single();

                        publicPagePlaceholderContent.FullCopyChangedTo(administrativePagePlaceholderContent, propertyNamesToIgnore);
                        DataFacade.Update(administrativePagePlaceholderContent);
                    }
                }

                transactionScope.Complete();
            }
        }
Example #13
0
        public XElement RenderDocument(IPagePlaceholderContent content)
        {
            var doc = XElement.Parse(content.Content);

            return(RenderDocument(doc));
        }
Example #14
0
        public static IPage TranslatePage(IPage sourcePage, CultureInfo sourceCultureInfo, CultureInfo targetCultureInfo)
        {
            IPage newPage;

            using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                List <IPagePlaceholderContent> sourcePagePlaceholders;
                List <IData> sourceMetaDataSet;

                using (new DataScope(sourceCultureInfo))
                {
                    using (new DataScope(DataScopeIdentifier.Administrated))
                    {
                        sourcePage = sourcePage.GetTranslationSource();

                        using (new DataScope(sourcePage.DataSourceId.DataScopeIdentifier))
                        {
                            sourcePagePlaceholders = DataFacade.GetData <IPagePlaceholderContent>(f => f.PageId == sourcePage.Id).ToList();
                            sourceMetaDataSet      = sourcePage.GetMetaData().ToList();
                        }
                    }
                }

                using (new DataScope(targetCultureInfo))
                {
                    newPage = DataFacade.BuildNew <IPage>();
                    sourcePage.ProjectedCopyTo(newPage);

                    newPage.SourceCultureName = targetCultureInfo.Name;
                    newPage.PublicationStatus = GenericPublishProcessController.Draft;
                    newPage = DataFacade.AddNew <IPage>(newPage);

                    foreach (IPagePlaceholderContent sourcePagePlaceholderContent in sourcePagePlaceholders)
                    {
                        IPagePlaceholderContent newPagePlaceholderContent = DataFacade.BuildNew <IPagePlaceholderContent>();
                        sourcePagePlaceholderContent.ProjectedCopyTo(newPagePlaceholderContent);

                        newPagePlaceholderContent.SourceCultureName = targetCultureInfo.Name;
                        newPagePlaceholderContent.PublicationStatus = GenericPublishProcessController.Draft;
                        DataFacade.AddNew <IPagePlaceholderContent>(newPagePlaceholderContent);
                    }

                    foreach (IData metaData in sourceMetaDataSet)
                    {
                        ILocalizedControlled localizedData = metaData as ILocalizedControlled;

                        if (localizedData == null)
                        {
                            continue;
                        }

                        IEnumerable <ReferenceFailingPropertyInfo> referenceFailingPropertyInfos = DataLocalizationFacade.GetReferencingLocalizeFailingProperties(localizedData).Evaluate();

                        if (!referenceFailingPropertyInfos.Any())
                        {
                            IData newMetaData = DataFacade.BuildNew(metaData.DataSourceId.InterfaceType);
                            metaData.ProjectedCopyTo(newMetaData);

                            ILocalizedControlled localizedControlled = newMetaData as ILocalizedControlled;
                            localizedControlled.SourceCultureName = targetCultureInfo.Name;

                            IPublishControlled publishControlled = newMetaData as IPublishControlled;
                            publishControlled.PublicationStatus = GenericPublishProcessController.Draft;

                            DataFacade.AddNew(newMetaData);
                        }
                        else
                        {
                            foreach (ReferenceFailingPropertyInfo referenceFailingPropertyInfo in referenceFailingPropertyInfos)
                            {
                                Log.LogVerbose("LocalizePageWorkflow",
                                               "Meta data of type '{0}' is not localized because the field '{1}' is referring some not yet localzed data"
                                               .FormatWith(metaData.DataSourceId.InterfaceType, referenceFailingPropertyInfo.DataFieldDescriptor.Name));
                            }
                        }
                    }
                }



                transactionScope.Complete();
            }
            return(newPage);
        }