我创建了一个具有订阅事件的事件处理程序的TcmExtension
名称。此事件的目的是安排发布相关工作流主题的所有依赖项(即页面)。WorkflowEventSystem
FinishProcess
我遇到的问题是,即使事件在正确的时间触发(工作流程过程已完成),并且应该安排发布的所有项目都是,PublishScheduler
事件创建的对象似乎永远不会消失范围,因此 WorkflowEventSystem 对象也没有。
关于事件系统的工作原理,我是否遗漏了一些东西会导致这些对象永远存在?我在下面包含了我认为相关的代码(总结了一些部分)。谢谢你的帮助。
这是大部分实际的 TcmExtension:
public class WorkflowEventSystem : TcmExtension
{
public WorkflowEventSystem()
{
this.Subscribe();
}
public void Subscribe()
{
EventSystem.Subscribe<ProcessInstance, FinishProcessEventArgs>(ScheduleForPublish, EventPhases.All);
}
}
ScheduleForPublish
创建一个PublishScheduler
对象(我创建的类):
private void ScheduleForPublish(ProcessInstance process, FinishProcessEventArgs e, EventPhases phase)
{
if(phase == EventPhases.TransactionCommitted)
{
PublishScheduler publishScheduler = new PublishScheduler(process);
publishScheduler.ScheduleForPublish(process);
publishScheduler = null; // worth a try
}
}
该ScheduleForPublish
方法看起来与此类似:
public void ScheduleForPublish(ProcessInstance process)
{
using(Session session = new Session("ImpersonationUser"))
{
var publishInstruction = new PublishInstruction(session);
// Set up some publish Instructions
var publicationTargets = new List<PublicationTarget>();
// Add a PublicationTarget here by tcm id
IList<VersionedItem> itemsToPublish = new List<VersionedItem>();
// Add the items we want to publish by calling GetUsingItems(filter)
// on the workflow process' subject
//Publish the items
PublishEngine.Publish(itemsToPublish.Cast<IdentifiableObject>(), publishInstruction, publishTargets);
}
}