Tridion RepositoryLocalObject.GetBluePrintChain方法(BluePrintChainFilter)在共享项上引发异常

Nic*_*kov 5 tridion tridion-2011

我正在尝试获取继承RepositoryLocalObject(例如Component)的父项列表.因此,如果我有一个包含组件tcm:1-80的pub ID 1和一个子pub pub ID 2,那么这个组件在子pub中共享为tcm:2-80.所以我想得到tcm:2-80的父母,或树上的任何东西向上移动.

我已经在组件的本地副本上尝试了GetBluePrintChain()方法,它可以正常工作.但是,在共享组件上,它返回InvalidActionException:"此项目是共享的".该文档提到在共享项上抛出此异常.但这有什么意义呢?显然,如果任何具有超出其自身蓝图链的项目将被共享(或者是本地副本).所以对我来说,让这个方法在具有蓝图链的东西上抛出异常是没有意义的.这似乎是矛盾的.

我的问题与获取组件的根发布有些相关,但它有所不同.我需要理解为什么在共享项上抛出此异常.有人可以解释并分享一个用例来支持它吗?

Fra*_*len 4

据我所知,这些GetBluePrintChain方法旨在当您站在蓝图顶部时向下查看蓝图。因此,在您的情况下,您应该在其所属的发布上下文中获取该项目,然后调用GetBluePrintChain.

Item item = package.GetByName("Component");
Component component = new Component(item.GetAsXmlDocument().DocumentElement,
                                    engine.GetSession());
TcmUri id = TemplateUtilities.CreateTcmUriForPublication(
        component.OwningRepository.Id.ItemId, component.Id);

var blueprintchain = ((Component)engine.GetObject(id)).GetBluePrintChain();

package.PushItem(package.CreateStringItem(ContentType.Text, 
                                          blueprintchain.ToString()));
package.PushItem(package.CreateStringItem(ContentType.Text,
                             ""+System.Linq.Enumerable.Count(blueprintchain)));
foreach (var item in blueprintchain)
{
    package.PushItem(package.CreateTridionItem(ContentType.Component, item));
}
Run Code Online (Sandbox Code Playgroud)

我刚刚在两种情况下将上面的 C# 片段作为 TBB 运行:

  1. 在共享组件的子出版物中
  2. 在本地化组件的子出版物中

在情况 1 中,blueprintchain将包含单个项目:共享组件。在情况 2 中,blueprintchain将包含两个项目:共享组件和本地化组件。