2012-11-22 90 views
5

我們正試圖在Eventing Code中取消訂閱eventSubscripton。我們用下面的代碼SDL Tridion EventSubscription UnSubscribe Issue

[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」之稱,事件會停止,這就是它應該工作的後續事件的工作。一旦事件系統相關的服務重新啓動,事件代碼就會按照預期的那樣進行工作,並且永遠不會爲後來的事件(它本應該工作的)調用。

+1

當你的對象的'的Dispose()'方法被調用?據我所知,這應該只發生在處理程序運行的模塊關閉時(甚至可能還沒有)。 –

+0

如果你不Dispose()它按預期工作?那麼停止處置? –

回答

1

嘗試刪除Dispose方法,看看是否有所作爲。 Tridion可能會在事件被觸發的第一個實例中實例化事件處理程序,然後在系統重新啓動之前再也不會執行它。所以如果你取消訂閱和處理,那麼你的類將不會再被實例化。您的環境中的其他內容也可能會造成干擾。很難說,但首先嚐試刪除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! 
     } 

    } 
} 
相關問題