工作流程的基本要素是什么?

发布于 2024-09-19 13:12:06 字数 208 浏览 3 评论 0原文

长版本:用 C# 实现的工作流程的基本元素/组件是什么(不使用 WF 3.5 或 WF 4 的任何部分)?

注意I:我想实现主从通信,其中服务器端始终是被动的(从属),并且我的工作流程主要执行与这种通信方案相关的任务。

注二:由于在我的项目中决定不使用 WF 4(恕我直言,这是一个正确的决定),因此我需要一些设计指南来实现(简单的)工作流工具箱。

谢谢

Long version: What would be the essential elements/components of a workflow to be implemented in C# (without using any part of WF 3.5 or WF 4)?

Note I: I want to implement a master-slave communication where server-side is always passive(slave) and my workflow mainly performs tasks related to such communication scheme.

Note II: Since in my project it is decided that we will not use WF 4 (IMHO a right decision), I need some design guide-lines in implementing a (simple) workflow toolbox.

Thanks

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

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

发布评论

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

评论(1

幸福丶如此 2024-09-26 13:12:06

如果您不想使用工作流基础,您可以创建工作流作为 GOF 状态模式的实现。

简单的实现:

public class Workflow
{
  internal IState Current { get; set; }

  public void Start()
  {
     Current = new StartState();
     Current.Start(this);
  }

  public void DoSomething()
  {
     Current.DoSomething(this);
  }

  public void DoSomethingElse()
  {
     Current.DoSomethingElse(this);
  }
}

public interface IState
{
  Start(Workflow context);
  DoSomething(Workflow context);
  DoSeomethingElse(Workflow context);
}

public abstract BaseState : IState
{
  public virtual void Start(Workflow context)
  {
    throw new InvalidStateOperationException(); 
  }

  public virtual void DoSomething(Workflow context)
  {
    throw new InvalidStateOperationException(); 
  }

  public virtual void DoSomethingElse(Workflow context)
  {
    throw new InvalidStateOperationException(); 
  }
}

public class StartState : BaseState
{
  public override void Start(Worklfow context)
  {
    // Do something
    context.Current = new OtherState();
  }
}

这只是非常基本的实现。您可以进一步扩展它。您可以添加其他方法集,例如 CanDoSomething,您可以维护创建的 State 实例的集合,因为 State 实例是无状态的,因此您不需要每次移动到该状态时都创建新的实例等。

If you don't want to use Workflow foundation you can create your workflow as implementation of GOF State pattern.

Simple implementation:

public class Workflow
{
  internal IState Current { get; set; }

  public void Start()
  {
     Current = new StartState();
     Current.Start(this);
  }

  public void DoSomething()
  {
     Current.DoSomething(this);
  }

  public void DoSomethingElse()
  {
     Current.DoSomethingElse(this);
  }
}

public interface IState
{
  Start(Workflow context);
  DoSomething(Workflow context);
  DoSeomethingElse(Workflow context);
}

public abstract BaseState : IState
{
  public virtual void Start(Workflow context)
  {
    throw new InvalidStateOperationException(); 
  }

  public virtual void DoSomething(Workflow context)
  {
    throw new InvalidStateOperationException(); 
  }

  public virtual void DoSomethingElse(Workflow context)
  {
    throw new InvalidStateOperationException(); 
  }
}

public class StartState : BaseState
{
  public override void Start(Worklfow context)
  {
    // Do something
    context.Current = new OtherState();
  }
}

This is juse very basic implementation. You can futher extend it. You can add other set of methods like CanDoSomething, you can maintain collection of created State instances because State instance is stateless so you don't need to create new instnace each time you move to the state etc.

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