public static Dynamic.Page BuildPage(TCM.Page tcmPage, Engine engine, BuildManager manager, int linkLevels, bool resolveWidthAndHeight)
        {
            Dynamic.Page p = new Dynamic.Page();
            p.Title        = tcmPage.Title;
            p.Id           = tcmPage.Id.ToString();
            p.Filename     = tcmPage.FileName;
            p.PageTemplate = manager.BuildPageTemplate(tcmPage.PageTemplate);
            p.Schema       = manager.BuildSchema(tcmPage.MetadataSchema);
            p.Metadata     = new Dynamic.SerializableDictionary <string, Dynamic.Field>();
            if (linkLevels > 0)
            {
                try {
                    if (tcmPage.Metadata != null)
                    {
                        var tcmMetadataFields = new Tridion.ContentManager.ContentManagement.Fields.ItemFields(tcmPage.Metadata, tcmPage.MetadataSchema);
                        p.Metadata = manager.BuildFields(tcmMetadataFields, linkLevels, resolveWidthAndHeight);
                    }
                } catch (ItemDoesNotExistException) {
                    // fail silently if there is no metadata schema
                }
            }

            p.ComponentPresentations = new List <Dynamic.ComponentPresentation>();
            foreach (TCM.ComponentPresentation cp in tcmPage.ComponentPresentations)
            {
                Dynamic.ComponentPresentation dynCp = manager.BuildComponentPresentation(cp, engine, linkLevels - 1, resolveWidthAndHeight);
                p.ComponentPresentations.Add(dynCp);
            }
            p.StructureGroup = manager.BuildOrganizationalItem((TCM.StructureGroup)tcmPage.OrganizationalItem);
            p.Publication    = manager.BuildPublication(tcmPage.ContextRepository);
            p.Categories     = manager.BuildCategories(tcmPage);

            return(p);
        }
Exemplo n.º 2
0
        public static Dynamic.ComponentPresentation BuildComponentPresentation(TCM.ComponentPresentation tcmComponentPresentation, Engine engine, int linkLevels, bool resolveWidthAndHeight, BuildManager manager)
        {
            Dynamic.ComponentPresentation cp = new Dynamic.ComponentPresentation();


            // render the component presentation using its own CT
            // but first, set a parameter in the context so that the CT will know it is beng called
            // from a DynamicDelivery page template
            if (engine.PublishingContext.RenderContext != null && !engine.PublishingContext.RenderContext.ContextVariables.Contains(PageTemplateBase.VariableNameCalledFromDynamicDelivery))
            {
                engine.PublishingContext.RenderContext.ContextVariables.Add(PageTemplateBase.VariableNameCalledFromDynamicDelivery, PageTemplateBase.VariableValueCalledFromDynamicDelivery);
            }

            string renderedContent = engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id);

            engine.PublishingContext.RenderContext.ContextVariables.Remove(PageTemplateBase.VariableNameCalledFromDynamicDelivery);

            renderedContent = TridionUtils.StripTcdlTags(renderedContent);

            if (tcmComponentPresentation.ComponentTemplate.IsRepositoryPublishable)
            {
                // ignore the rendered CP, because it is already available in the broker
                // instead, we will render a very simple version without any links
                cp.Component = manager.BuildComponent(tcmComponentPresentation.Component, 0, false); // linkLevels = 0 means: only summarize the component
            }
            else
            {
                TextReader tr = new StringReader(renderedContent);
                if (serializer == null)
                {
                    serializer = new XmlSerializerFactory().CreateSerializer(typeof(Dynamic.Component));
                }
                try
                {
                    cp.Component = (Dynamic.Component)serializer.Deserialize(tr);
                }
                catch
                {
                    // the component presentation could not be deserialized, this probably not a Dynamic Delivery template
                    // just store the output as 'RenderedContent' on the CP
                    cp.RenderedContent = renderedContent;
                }
            }
            cp.ComponentTemplate = manager.BuildComponentTemplate(tcmComponentPresentation.ComponentTemplate);
            return(cp);
        }