您应该能够查看作为自定义解析器中ResolvePurpose
的ResolveInstruction
参数之一获得的 。这些方面的东西:
public void Resolve(IdentifiableObject item, ResolveInstruction instruction, PublishContext context, ISet<ResolvedItem> resolvedItems)
{
if (instruction.Purpose == ResolvePurpose.Publish || instruction.Purpose == ResolvePurpose.RePublish)
{
// We are publishing
}
else if(instruction.Purpose == ResolvePurpose.UnPublish)
{
// We are unpublishing
}
// Don't know if this one exists in 2009, it exists in 2011 SP1
else if(instruction.Purpose == ResolvePurpose.UnknownByClient)
{
// The server is doing something that I don't understand (yet?)
}
}
编辑
我拒绝不找到一种方法来完成这项工作......
事实上,在 Tridion 2009 中,您没有Purpose
on resolve 指令。您Action
在 Publish Transaction 中确实有一个,但这个并没有直接在解析器中公开。以下是我发现我是发布还是取消发布的方法 - 如果您认为这太过分了,但我的非生产 VM 上的性能非常好。
- 找到我们正在解决的当前项目
- 加载状态为“进行中”的 PublishTransaction 列表
- 查找当前项目的交易
- 通过查看
Action
属性确定动作
Filter filter = new Filter();
filter.Conditions["InfoType"] = 2; // Get transactions in Progress
foreach (XmlNode node in item.Session.GetList(typeof(PublishTransaction), filter))
{
if(node.Attributes["ItemID"].Value.Equals(item.Id.ToString()))
{
// we have a winner
string action;
if (node.Attributes["Action"].Value.Equals("0"))
action = "Publish";
if (node.Attributes["Action"].Value.Equals("1"))
action = "Unpublish";
}
}