从工作流活动发布事件

发布于 2024-12-25 12:15:03 字数 155 浏览 2 评论 0原文

我正在使用 prism 构建 WPF 应用程序,并且我想使用工作流基础(本地和来自服务)。

是否有人了解如何构建使用 EventAggretator 调用的工作流活动,然后让工作流发布事件作为响应?我正在考虑构建一个允许活动发布一对多事件的实现,这对于工作流来说是一个好的场景吗?

I'm building a WPF application using prism and I'd like to use workflow foundation (both locally and from a service).

Does anyone have insight on building workflow activities invoked using the EventAggretator and then have workflow publish events in response? I'm considering building an implementation that would allow an activity to publish one to many events, is this a good scenario for workflow?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑白记忆 2025-01-01 12:15:03

使用事件聚合器实现的一种方法是要求它作为工作流活动的扩展,如下所示。然后,您可以在 WorkflowApplication / WorkflowInvoker 中注册事件聚合器的实例,以便您的活动可以引发事件。我还没有在我的应用程序中使用事件聚合器,所以可能会有一些怪癖。

自定义活动需要事件聚合器并在其执行方法中使用它:

namespace SampleWorkflowAppOne
{
    using System.Activities;
    using Microsoft.Practices.Prism.Events;

    public class PurchaseOrderInventoryCheckActivity : NativeActivity
    {
        protected override void CacheMetadata(NativeActivityMetadata metadata)
        {
            metadata.RequireExtension<IEventAggregator>();
        }

        protected override void Execute(NativeActivityContext context)
        {
            var eventAggregator = context.GetExtension<IEventAggregator>();
            var somethingHappenedEvent = eventAggregator.GetEvent<MyActivityEvent>();
            var myEventInfo = new MyEventInfo() { SomeNumber = 5 };
            somethingHappenedEvent.Publish(myEventInfo);
        }
    }

    public class MyActivityEvent : CompositePresentationEvent<MyEventInfo>
    {
    }

    public class MyEventInfo
    {
        public int SomeNumber { get; set; }
    }
}

注册事件聚合器实例以在您的活动中使用:

using System;
using System.Linq;
using System.Activities;
using System.Activities.Statements;

namespace SampleWorkflowAppOne
{
    using Microsoft.Practices.Prism.Events;

    class Program
    {
        static void Main(string[] args)
        {
            var purchaseOrderValidationWorkflow = new PurchaseOrderValidationWorkflow();
            var eventAggregator = new EventAggregator();
            var wfInvoker = new WorkflowInvoker(purchaseOrderValidationWorkflow);
            wfInvoker.Extensions.Add(eventAggregator);
            wfInvoker.Invoke();
        }
    }
}

希望有所帮助。

编辑:我发现这个视频显示了构建事件驱动+长期运行的工作流程,这可能也有一些帮助。不过我还没看过: http://channel9.msdn.com/事件/构建/BUILD2011/TOOL-801T

One way you can implement using an event aggregator is to require it as an extension to your workflow activities like the following. In your WorkflowApplication / WorkflowInvoker, you can then register an instance of the event aggregator so that your activities can raise the events. I haven't used the event aggregator (yet) in my apps, so there might be some quirks.

Custom Activity that requires an event aggregator and uses it in its Execute method:

namespace SampleWorkflowAppOne
{
    using System.Activities;
    using Microsoft.Practices.Prism.Events;

    public class PurchaseOrderInventoryCheckActivity : NativeActivity
    {
        protected override void CacheMetadata(NativeActivityMetadata metadata)
        {
            metadata.RequireExtension<IEventAggregator>();
        }

        protected override void Execute(NativeActivityContext context)
        {
            var eventAggregator = context.GetExtension<IEventAggregator>();
            var somethingHappenedEvent = eventAggregator.GetEvent<MyActivityEvent>();
            var myEventInfo = new MyEventInfo() { SomeNumber = 5 };
            somethingHappenedEvent.Publish(myEventInfo);
        }
    }

    public class MyActivityEvent : CompositePresentationEvent<MyEventInfo>
    {
    }

    public class MyEventInfo
    {
        public int SomeNumber { get; set; }
    }
}

Registering the event aggregator instance for use in your activities:

using System;
using System.Linq;
using System.Activities;
using System.Activities.Statements;

namespace SampleWorkflowAppOne
{
    using Microsoft.Practices.Prism.Events;

    class Program
    {
        static void Main(string[] args)
        {
            var purchaseOrderValidationWorkflow = new PurchaseOrderValidationWorkflow();
            var eventAggregator = new EventAggregator();
            var wfInvoker = new WorkflowInvoker(purchaseOrderValidationWorkflow);
            wfInvoker.Extensions.Add(eventAggregator);
            wfInvoker.Invoke();
        }
    }
}

Hope that helps.

EDIT: I found this video that shows building an event driven +long running workflow that might be of some help as well. I haven't watched it yet though: http://channel9.msdn.com/Events/Build/BUILD2011/TOOL-801T

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文