public static Dynamic.Region BuildRegion(TCM.Regions.IRegion tcmRegion, Engine engine, BuildManager manager, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields)
        {
            Dynamic.Region r = new Dynamic.Region
            {
                Name           = tcmRegion.RegionName,
                Schema         = manager.BuildSchema(tcmRegion.RegionSchema),
                MetadataFields = new Dynamic.FieldSet()
            };
            if (linkLevels > 0)
            {
                try
                {
                    if (tcmRegion.Metadata != null && tcmRegion.RegionSchema != null)
                    {
                        var tcmMetadataFields = new Tridion.ContentManager.ContentManagement.Fields.ItemFields(tcmRegion.Metadata, tcmRegion.RegionSchema);
                        r.MetadataFields = manager.BuildFields(tcmMetadataFields);
                    }
                }
                catch (Exception)
                {
                    // fail silently if there is no metadata schema
                }
            }

            r.ComponentPresentations = new List <Dynamic.ComponentPresentation>();
            foreach (TCM.ComponentPresentation cp in tcmRegion.ComponentPresentations)
            {
                Dynamic.ComponentPresentation dynCp = manager.BuildComponentPresentation(cp, engine, linkLevels - 1, resolveWidthAndHeight);
                r.ComponentPresentations.Add(dynCp);
            }

            manager.AddXpathToFields(r.MetadataFields, "Metadata");

            // adding nested regions
            r.Regions = new List <Dynamic.Region>();
            foreach (TCM.Regions.IRegion nestedTcmRegion in tcmRegion.Regions)
            {
                Dynamic.Region nestedRegion = manager.BuildRegion(nestedTcmRegion, engine);
                r.Regions.Add(nestedRegion);
            }

            return(r);
        }
        public static Dynamic.Page BuildPage(TCM.Page tcmPage, Engine engine, BuildManager manager, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields)
        {
            Dynamic.Page p = new Dynamic.Page
            {
                Title          = tcmPage.Title,
                Id             = tcmPage.Id.ToString(),
                Filename       = tcmPage.FileName,
                PageTemplate   = manager.BuildPageTemplate(tcmPage.PageTemplate),
                Schema         = manager.BuildSchema(tcmPage.MetadataSchema),
                Version        = tcmPage.Version,
                RevisionDate   = tcmPage.RevisionDate,
                MetadataFields = new Dynamic.FieldSet()
            };
            if (linkLevels > 0)
            {
                try
                {
                    if (tcmPage.Metadata != null && tcmPage.MetadataSchema != null)
                    {
                        var tcmMetadataFields = new Tridion.ContentManager.ContentManagement.Fields.ItemFields(tcmPage.Metadata, tcmPage.MetadataSchema);
                        p.MetadataFields = manager.BuildFields(tcmMetadataFields);
                    }
                }
                catch (Exception)
                {
                    // 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);
            }
#if REGIONS
            // add regions
            p.Regions = new List <Dynamic.Region>();
            foreach (TCM.Regions.IRegion tcmRegion in tcmPage.Regions)
            {
                Dynamic.Region region = manager.BuildRegion(tcmRegion, engine);
                p.Regions.Add(region);
            }
#endif
            p.StructureGroup = manager.BuildOrganizationalItem((TCM.StructureGroup)tcmPage.OrganizationalItem);

            if (!manager.BuildProperties.OmitContextPublications)
            {
                p.Publication = manager.BuildPublication(tcmPage.ContextRepository);
            }
            if (!manager.BuildProperties.OmitOwningPublications)
            {
                p.OwningPublication = manager.BuildPublication(tcmPage.OwningRepository);
            }
            if (!manager.BuildProperties.OmitCategories)
            {
                p.Categories = manager.BuildCategories(tcmPage);
            }
            manager.AddXpathToFields(p.MetadataFields, "Metadata");
            return(p);
        }