我们正在尝试取消订阅事件代码中的eventSubscripton。我们正在使用以下代码
[TcmExtension("EventHandlerExtension")]
public class EventHandler : TcmExtension, IDisposable
{
private EventSubscription componentSaveSubscription = null;
private EventSubscription componentPublishSubscription = null;
#region Public Methods
/// <summary>
/// Handle for Eventing System
/// </summary>
public EventHandler()
{
Subscribe();
}
/// <summary>
/// Subscribe Events
/// </summary>
public void Subscribe()
{
//News Article Page created when component Save
componentSaveSubscription = EventSystem.Subscribe<Component, SaveEventArgs>(OnComponentSavePost, EventPhases.TransactionCommitted);
//EventSystem.Subscribe<Component, SaveEventArgs>(OnComponentSavePost, EventPhases.TransactionCommitted);
componentPublishSubscription = EventSystem.Subscribe<Component, PublishOrUnPublishEventArgs>(OnComponentPublishOrUnPublishPost, EventPhases.TransactionCommitted);
//EventSystem.Subscribe<StructureGroup, PublishOrUnPublishEventArgs>(OnStructureGroupPublishInitiated, EventPhases.TransactionCommitted);
}
/// <summary>
/// IDisposable Implementation
/// </summary>
public void Dispose()
{
if (componentSaveSubscription != null) componentSaveSubscription.Unsubscribe();
if (componentPublishSubscription != null) componentPublishSubscription.Unsubscribe();
}}
我们观察到的是,一旦调用了“{EventSubsciption} .Unsubscribe”,事件就会停止处理应该处理的后续事件。一旦事件系统相关的服务重新启动,事件代码将仅按预期的方式第一次工作,并且永远不会为后续事件(应该为之工作)调用。
最佳答案
尝试删除Dispose方法,看看是否有区别。 Tridion可能在事件的第一个实例被触发时实例化事件处理程序,然后再也不会再次执行它,直到系统重新启动为止。因此,如果您取消订阅和处置,那么您的类(class)将不会再次实例化。您环境中的其他内容也可能会干扰。很难说,但是先删除Dispose。
我的样板处理程序如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Tridion.ContentManager;
using Tridion.ContentManager.CommunicationManagement;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.ContentManagement.Fields;
using Tridion.ContentManager.Extensibility;
using Tridion.ContentManager.Extensibility.Events;
namespace NicksEventSystem
{
[TcmExtension("NicksEventSystemExtension")]
public class NicksEventHandler : TcmExtension
{
public NicksEventHandler()
{
Subscribe();
}
private void Subscribe()
{
EventSystem.Subscribe<Component, FinishActivityEventArgs>(MyEvent, EventPhases.TransactionCommitted);
}
private void MyEvent(Component wfComponent)
{
//... Do stuff!
}
}
}
关于c# - SDL Tridion EventSubscription取消订阅问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13520442/