2012-11-22 28 views
5

Chúng tôi đang cố gắng hủy đăng ký khỏi sự kiệnSubscripton trong Mã sự kiện của chúng tôi. Chúng tôi đang sử dụng đoạn mã sauSDL Tridion EventSubcription 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(); 
    }} 

Những gì chúng ta đã quan sát thấy là một khi “{} EventSubsciption .Unsubscribe” được gọi, eventing ngừng hoạt động cho các sự kiện tiếp theo mà nó là vụ phải làm việc. Khi các dịch vụ liên quan đến hệ thống sự kiện được khởi động lại, mã sự kiện hoạt động như dự kiến ​​cho lần đầu tiên và không bao giờ được gọi cho các sự kiện tiếp theo (mà nó được cho là hoạt động).

+1

Khi được đối tượng của bạn 'Dispose()' phương pháp được gọi? Theo tôi biết điều này sẽ chỉ xảy ra khi mô-đun mà trình xử lý chạy trong bị tắt (và thậm chí không có khả năng). –

+0

Và nếu bạn không Dispose() nó hoạt động như mong đợi? Sau đó ngừng xử lý? –

Trả lời

1

Thử xóa phương thức Vứt bỏ và xem điều đó có tạo sự khác biệt hay không. Có thể Tridion đã khởi tạo Event Handler khi trường hợp đầu tiên của một sự kiện bị sa thải và sau đó không bao giờ thực hiện lại cho đến khi hệ thống được khởi động lại. Vì vậy, nếu bạn hủy đăng ký và hủy bỏ, sau đó lớp học của bạn sẽ không được khởi tạo lại. Nó cũng có thể là một cái gì đó khác trong môi trường của bạn đang can thiệp. Thật khó để nói, nhưng hãy thử bằng cách loại bỏ các Vứt bỏ đầu tiên.

Handler soạn sẵn của tôi trông như thế này:

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ác vấn đề liên quan