Ejemplo n.º 1
0
        private static void GetRelatedPages(string componentUri, int level)
        {
            //Only collect pages that have publishdate before 15 april 2015
            DateTime dt = new DateTime(2015, 4, 15);

            UsingItemsFilterData filter = new UsingItemsFilterData
            {
                ItemTypes        = new[] { Tridion.ContentManager.CoreService.Client.ItemType.Component, Tridion.ContentManager.CoreService.Client.ItemType.Page },
                IncludedVersions = VersionCondition.OnlyLatestVersions
            };

            foreach (System.Xml.Linq.XElement node in core.GetListXml(componentUri, filter).Nodes())
            {
                string nodeId = node.Attribute("ID").Value;
                string path   = node.Attribute("Path").Value;
                int    type   = int.Parse(node.Attribute("Type").Value);

                if (type == 64)
                {
                    //Is a page
                    if (!pages.Keys.Contains(nodeId))
                    {
                        //Get publish info of last publish action
                        var pubInfo = core.GetListPublishInfo(nodeId).LastOrDefault();
                        if (pubInfo != null && pubInfo.PublishedAt < dt)
                        {
                            var    page    = core.Read(nodeId, readOpts) as PageData;
                            var    locInfo = ((PublishLocationInfo)page.LocationInfo);
                            string url     = locInfo.PublishLocationUrl;
                            pages.Add(nodeId, url);
                            //publish
                            var liveTarget = new[] { "tcm:0-141-65538" };
                            //core.Publish(new[] { nodeId }, new PublishInstructionData { ResolveInstruction = new ResolveInstructionData() { IncludeChildPublications = true }, RenderInstruction = new RenderInstructionData() }, liveTarget, PublishPriority.Low, null);
                        }
                        //ignore when page is never been published
                    }
                }
                else if (level < 3)
                {
                    GetRelatedPages(nodeId, level + 1);
                }
            }
        }