6

イベントにサブスクライブされたイベントハンドラーを持つTcmExtension名前を作成しました。このイベントの目的は、関連するワークフローサブジェクトのすべての依存関係(つまりページ)を公開するようにスケジュールすることです。WorkflowEventSystemFinishProcess

私が抱えている問題は、イベントが適切なタイミングでトリガーされ(ワークフロープロセスが完了した)、公開がスケジュールされているはずのすべてのアイテムがトリガーされても、PublishSchedulerイベントによって作成されたオブジェクトが消えないように見えることです。スコープであるため、WorkflowEventSystemオブジェクトもそうではありません。

これらのオブジェクトが永遠に存続する原因となるイベントシステムの動作について、私が見逃しているものはありますか?私が関連するコードと考えるものを以下に含めました(いくつかの部分を要約しました)。助けてくれてありがとう。

実際のTcmExtensionのほとんどは次のとおりです。

public class WorkflowEventSystem : TcmExtension
{
    public WorkflowEventSystem()
    {
        this.Subscribe();
    }

    public void Subscribe()
    {
        EventSystem.Subscribe<ProcessInstance, FinishProcessEventArgs>(ScheduleForPublish, EventPhases.All);
    }
}

ScheduleForPublishPublishSchedulerオブジェクト(私が作成したクラス)を作成します:

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);
    }    
}
4

1 に答える 1

10

クラスのライフサイクル管理TcmExtensionは非常に簡単です。

  1. Subscribe指定したオブジェクトを呼び出すと、TcmExtensionサブスクリプションの内部リストに追加されます

  2. 後で呼び出すとUnsubscribe、同じTcmExtensionオブジェクトがサブスクリプションのリストから削除されます

Unsubscribe電話をかけることWorkflowEventSystemは決してないので、削除されることはなく、.NETによってガベージコレクションされることもありません。また、作成WorkflowEventSystemしたインスタンスへの参照を保持しているため、そのPublishSchedulerインスタンスもクリーンアップされることはありません。

カスタムの適切な定型文TcmExtensionは次のとおりです。

public class WorkflowEventSystem : TcmExtension, IDisposable
{
    EventSubscription _subscription;

    public WorkflowEventSystem()
    {
        this.Subscribe();
    }

    public void Subscribe()
    {
         _subscription = EventSystem.Subscribe<ProcessInstance, 
             FinishProcessEventArgs>(ScheduleForPublish, EventPhases.All);
    }

    public void Dispose()
    {
        _subscription.Unsubscribe();
    }
}

Nunoはまた、この記事でより長い例(複数のサブスクライバーの処理)を示しました:http: //nunolinhares.blogspot.nl/2012/07/validating-content-on-save-part-1-of.html

于 2012-08-28T04:26:58.967 に答える