我正在使用Tridion 2011的事件系统在取消发布组件时执行一些其他操作。我正在使用发现here的代码来发布相关组件。
我正在按如下方式注册我的事件处理程序:
EventSystem.Subscribe<Component, UnPublishEventArgs>(
RemoveAndRepublish, EventPhases.Initiated);
...,而我的处理程序方法如下:
public void RemoveAndRepublish(Component cmp, UnPublishEventArgs args,
EventPhases phase)
{
// ... code to locate related component, and perform required actions...
var instruction = new PublishInstruction(cmp.Session)
{
DeployAt = DateTime.Now,
RenderInstruction = new RenderInstruction(cmp.Session)
{
RenderMode = RenderMode.Publish
},
ResolveInstruction = new ResolveInstruction(cmp.Session)
{
IncludeComponentLinks = true
},
RollbackOnFailure = true,
StartAt = DateTime.MinValue
};
var target = args.Targets.FirstOrDefault();
PublishEngine.Publish(new[] {related}, instruction, new[] {target});
}
我的问题是
UnPublishEventArgs.Targets
属性是IList<PublishingTarget>
,在运行时它实际上是List<TargetType>
,我需要获取PublicationTarget
对象才能调用PublishEngine.Publish(...)
。我的问题是:有没有办法从UnPublish事件获取当前(un-)PublicationTarget?
谁能提供任何帮助?
最佳答案
您需要自己从TargetType中找出PublicationTarget。根据项目的TargetType和Publication,您将需要遍历PublicationTargets以查看它们是否允许您的Publication向其发布。 (最终)这将为您提供PublicationTargets的列表。不幸的是,这是很多工作:(
所有这些,您真的需要PublicationTarget吗?如果需要从相同的“发布/目标”组合重新发布或取消发布项目,则应该能够将相同的TargetType数组解析为PublishEngine.Publish(...)
方法。
当我搜索文档时,在PublishEngine()上看到以下重写:
PublishEngine.Publish Method (IEnumerable<(Of <(<'IdentifiableObject>)>)>, PublishInstruction, IEnumerable<(Of <(<'TargetType>)>)>, PublishPriority)
public static ICollection<PublishTransaction> Publish(
IEnumerable<IdentifiableObject> items,
PublishInstruction publishInstruction,
IEnumerable<TargetType> targetTypes,
PublishPriority priority
)