.NET 状态机框架
我工作中的系统基本上是一个消息驱动的状态机。 它接收各种类型的消息,根据消息查找某些上下文/状态,然后根据消息和当前状态决定要做什么。 通常结果是一条消息被发送到系统之外。
有没有好的开源框架可以在 .NET 中实现状态机? 我研究了最新版本的 Windows Workflow,它似乎是一个不错的选择; 然而,我对默认的持久性机制(我们需要报告状态转换数据)、可测试性以及 WF 团队正在重新构建框架这一事实(据说)有一些担忧。
我正在考虑尝试实现一个普通的 GoF“状态”模式,并使用 Spring.NET 将所有内容连接在一起,而不是使用 WF。 是否有任何东西已经做到了这一点,或者类似的东西?
We have a system at my work that is basically a message-driven state machine. It takes in a variety of types of messages, looks up some context/state based on the message, then decides what to do, based on the message and the current state. Normally the result is a message being sent out of the system.
Are there any good open-source frameworks for implementing a state machine in .NET? I've looked into the latest release of Windows Workflow, and it seems like it would be a good option; however, I have some concerns about the default persistence mechanisms (we need to report off the state transition data), testability, and the fact that the WF team is re-architecting the framework as we speak (supposedly).
Instead of WF, I'm thinking of trying to implement a plain-old GoF "State" pattern, and using Spring.NET to wire everything together. Is there anything out there that already does this, or something similar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
根据您的具体要求,您可能会发现状态机编译器足以实现 GoF“状态”模式。 它可以生成 C# 以及点,可以使用 Graphviz 将点转换为多种图像格式。 我在之前的项目中使用过它,发现它足以生成“简单”状态机。 我希望这有帮助。
Depending on your exact requirements you might find the State Machine Compiler is sufficient for implementing the GoF "State" pattern. It can generate C# as well as dot which can be transformed into several image formats using Graphviz. I've used it on a previous project and found it sufficient for generating a 'simple' state machine. I hope this helps.
两个出色的 .NET 状态机
Two great state machines for .NET
看看 NState
https://github.com/benaston/NState
https://nuget.org/packages/NState/。
免责声明:我维护它。
Take a look at NState
https://github.com/benaston/NState
https://nuget.org/packages/NState/.
Disclaimer: I maintain it.
我维护一个开源项目,它实现了(除其他外).NET 的通用有限状态机。 它构建在 QuickGraph 之上,因此您可以免费获得许多图形分析算法。 有关详细信息,请参阅此页面。
I maintain an open-source project which implements (among other things) a generic finite state machine for .NET. It is built on top of QuickGraph, so you get many graph-analysis algorithms for free. See this page for more information.
您可以考虑C# 中的 North State Framework。 尽管它不是开源的,但其许可成本相对较低。 这是我所知道的唯一允许通过状态机组合和继承进行重用的框架。 换句话说,您只需几行代码就可以从基本状态机继承,并添加状态、转换、操作等。您还可以采用现有的状态机类并将其“插入”另一个状态机。 您不会相信,相对于 GOF 或其他模式,使用此框架实现和使用状态机要容易得多。
You might consider the North State Framework in C#. Although it is not open source, it is relatively inexpensive to license. It is the only framework that I know of that allows reuse through state machine composition and inheritance. In other words, you can inherit from a base state machine with only a few lines of code, and add states, transitions, actions, etc. You can also take an existing state machine class and "plug it into" another state machine. You won't believe how much easier it is to implement and work with state machines using this framework, relative to GOF or other patterns.
看一下 StateBuilderDotNet,它是一个状态机代码生成器,它将状态机的 XML 描述转换为状态机的扩展版本C# 状态模式。 它支持所有 UML 语义:状态机可以是分层的、并发的和异步的。 还可以使用图形工具来创建状态机。
免责声明:我是这些软件的作者。
Have a look at StateBuilderDotNet, a state machine code generator that transforms an XML description of a state machine into an extended version of the C# state pattern. It supports all UML semantics: state machine can be hierarchical, concurrent and asynchronous. A graphical tool is also available to create state machines.
Disclaimer: I'm the author of these software.
我创建了 Staty,它是 .NET 的智能状态机。 Staty 采用 C# 可移植类库 (PCL) 编写,是一种富有表现力的事件驱动状态机,具有
它是免费、开源的,可在 NuGet 上获取,并基于 David Lafreniere 的 C++ 状态机,这是 C++ 中最著名的状态机。
I've created Staty which is a smart state-machine for .NET. Written as C# portable class library (PCL), Staty comes as an expressive event-driven state-machine with features like
It's free, open-source, available on NuGet and based on ideas by David Lafreniere's C++ State Machine, which is the most famous state-machine in C++.