2012-11-22 12 views
5

イベントコードのeventSubscriptonから退会しようとしています。私たちは、私たちが観察したことは一度「{} EventSubsciption .Unsubscribeが」と呼ばれていることである次のコードSDL Tridion EventSubscription UnSubscribe問題

[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(); 
    }} 

を使用している、イベンティングは、動作すると想定されるため、後続のイベントのために働いて停止します。イベントシステム関連のサービスが再起動されると、イベントコードは最初に期待どおりに機能し、その後のイベント(それが動作していたはずのイベント)で呼び出されることはありません。

+1

?私が知る限り、これは、ハンドラが実行されるモジュールがシャットダウンされているときにのみ発生します(潜在的にはそうではありません)。 –

+0

Dispose()を実行しないと、期待通りに機能しますか?その後、処分をやめる? –

答えて

1

Disposeメソッドを削除し、違いがあるかどうかを確認してください。 Tridionは、イベントの最初のインスタンスが起動されたときにEvent Handlerをインスタンス化し、システムが再起動されるまで再度イベントハンドラを実行しない可能性があります。したがって、退会して処分すると、あなたのクラスは再びインスタンス化されません。環境内の他の何かが干渉している可能性もあります。言うのは難しいですが、まずDisposeを取り除いてみてください。

マイ定型ハンドラは次のようになります。あなたのオブジェクトの `の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! 
     } 

    } 
} 
関連する問題