VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > Objective-C编程 >
  • 通过AEC解读WF的核心原理(13)实现Visio风格的Activity

制作者:剑锋冷月 单位:无忧统计网,www.51stat.net
 

  本系列以ActivityExecutionContext 对像为主线,通过以自定义Activity为例子演示了控制Activity内部执行的一些技巧。如果真正的读懂了本文,就能更好的理解WF工具栏中自带Activity的,并重新实现其功能。

  实际上,如果开发业务工作流,直接用WF工具栏中自带Activity拼装会使流程显得很臃肿,而状态机与顺序工作流其实也不过是WF为我们提供的两个简单的Activity执行控制模板而以,WF只的两个Activity,(System.Workflow.ComponentModel.Activity与System.Workflow.ComponentModel.CompositeActivity),它们是活动树上的叶节点与支节点,当你直正理解了这些你会发现让人眼花缭乱的WF背后是如此清爽幽雅,WF仿佛在一个全新的空间再现了计算机工作原理,指令、地址、数据、出栈、入栈.........

  最后以一个简单的例子结束本系例:

  实现Visio设计风格的Activity

  先看一下我的一个项目中的效果

通过AEC解读WF的核心原理(十三完)实现Visio设计风格的Activity

  下面是一个按连接线顺序调用的例子

  http://files.cnblogs.com/wxwinter/AEC13.rar

  结点Activity

通过AEC解读WF的核心原理(十三完)实现Visio设计风格的Activity

public class 结点: Activity
  {
public Activity 上一结点
{ set; get; }
public Activity 下一结点
{ set; get; }
  
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
System.Console.WriteLine(this.Name);
return ActivityExecutionStatus.Closed;
}
  }

编缉推荐阅读以下文章

  • 通过AEC解读WF的核心原理(十二)WorkflowQueue的提前提交
  • 通过AEC解读WF的核心原理(十一)WF与Windows操作系统的对比
  • 通过AEC解读WF的核心原理(十)取消与取消处理器
  • 通过AEC解读WF的核心原理(九)实现IEventActivity
  • 通过AEC解读WF的核心原理(八)实现Switch功能的Activity
  • 通过AEC解读WF的核心原理(七)一个实现Goto功能的Activity
  • 通过AEC解读WF的核心原理(六)创建复本ForEach循环
  • 通过AEC解读WF的核心原理(五)实现一个从下向上执行的顺序容器
  • 通过AEC解读WF的核心原理(四)AEC在内部执行childActivity
  • 通过AEC解读WF的核心原理(三)Execute方法Activity的入口
 

  容器Designer

public class wxwinterDesigner : FreeformActivityDesigner
{
public wxwinterDesigner()
{
this.ConnectorAdded += new ConnectorEventHandler(wxwinterDesigner_ConnectorAdded);
this.ConnectorChanged += new ConnectorEventHandler(wxwinterDesigner_ConnectorChanged);
this.ConnectorRemoved += new ConnectorEventHandler(wxwinterDesigner_ConnectorRemoved);
}
  
void wxwinterDesigner_ConnectorChanged(object sender, ConnectorEventArgs e)
{
结点 s = e.Connector.Source.AssociatedDesigner.Activity as 结点;
结点 t = e.Connector.Target.AssociatedDesigner.Activity as 结点;
  
s.下一结点 = t;
t.上一结点 = s;
  
}
  
void wxwinterDesigner_ConnectorRemoved(object sender, ConnectorEventArgs e)
{
结点 s = e.Connector.Source.AssociatedDesigner.Activity as 结点;
结点 t = e.Connector.Target.AssociatedDesigner.Activity as 结点;
  
t.上一结点 =null ;
s.下一结点 =null;
}
  
void wxwinterDesigner_ConnectorAdded(object sender, ConnectorEventArgs e)
{
结点 s = e.Connector.Source.AssociatedDesigner.Activity as 结点;
结点 t = e.Connector.Target.AssociatedDesigner.Activity as 结点;
s.下一结点 = t;
t.上一结点 = s;
}
}

  容器Activity

通过AEC解读WF的核心原理(十三完)实现Visio设计风格的Activity

编缉推荐阅读以下文章

  • 通过AEC解读WF的核心原理(十二)WorkflowQueue的提前提交
  • 通过AEC解读WF的核心原理(十一)WF与Windows操作系统的对比
  • 通过AEC解读WF的核心原理(十)取消与取消处理器
  • 通过AEC解读WF的核心原理(九)实现IEventActivity
  • 通过AEC解读WF的核心原理(八)实现Switch功能的Activity
  • 通过AEC解读WF的核心原理(七)一个实现Goto功能的Activity
  • 通过AEC解读WF的核心原理(六)创建复本ForEach循环
  • 通过AEC解读WF的核心原理(五)实现一个从下向上执行的顺序容器
  • 通过AEC解读WF的核心原理(四)AEC在内部执行childActivity
  • 通过AEC解读WF的核心原理(三)Execute方法Activity的入口
 

[Designer(typeof(wxwinterDesigner), typeof(IDesigner))]
  public class 容器: SequenceActivity
  {
public 结点 开始结点
{ set; get; }
  
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
if (开始结点 != null)
{
开始结点.Closed += node_Closed;
executionContext.ExecuteActivity(开始结点);
return ActivityExecutionStatus.Executing;
}
else
{
return ActivityExecutionStatus.Closed;
}
}
  
void node_Closed(object sender, ActivityExecutionStatusChangedEventArgs e)
{
ActivityExecutionContext executionContext = sender as ActivityExecutionContext;
结点 node = e.Activity as 结点;
node.Closed -= node_Closed;
  
if (node.下一结点 == null || node.下一结点.ExecutionStatus == ActivityExecutionStatus.Closed)
{
executionContext.CloseActivity();
}
else
{
  
node.下一结点.Closed += node_Closed;
executionContext.ExecuteActivity(node.下一结点);
}
  
}
  }

  宿主

class Program
{
static void Main()
{
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
workflowRuntime.WorkflowCompleted +=new EventHandler<WorkflowCompletedEventArgs>(workflowRuntime_WorkflowCompleted);
workflowRuntime.WorkflowTerminated +=new EventHandler<WorkflowTerminatedEventArgs>(workflowRuntime_WorkflowTerminated);
workflowRuntime.WorkflowIdled+=new EventHandler<WorkflowEventArgs>(workflowRuntime_WorkflowIdled);
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(Workflow1));
instance.Start();
  
System.Console.Read();
  
}
  
static void workflowRuntime_WorkflowIdled(object sender, WorkflowEventArgs e)
{
System.Console.WriteLine("WorkflowIdled");
}
  
static void workflowRuntime_WorkflowTerminated(object sender, WorkflowTerminatedEventArgs e)
{
System.Console.WriteLine("Terminated" + e.Exception.Message);
}
  
static void workflowRuntime_WorkflowCompleted(object sender, WorkflowCompletedEventArgs e)
{
System.Console.WriteLine("WorkflowCompleted");
}
  
}

 

  使用

通过AEC解读WF的核心原理(十三完)实现Visio设计风格的Activity

通过AEC解读WF的核心原理(十三完)实现Visio设计风格的Activity

通过AEC解读WF的核心原理(十三完)实现Visio设计风格的Activity

通过AEC解读WF的核心原理(十三完)实现Visio设计风格的Activity

通过AEC解读WF的核心原理(十三完)实现Visio设计风格的Activity

通过AEC解读WF的核心原理(十三完)实现Visio设计风格的Activity

  运行效果

通过AEC解读WF的核心原理(十三完)实现Visio设计风格的Activity

 

编缉推荐阅读以下文章

  • 通过AEC解读WF的核心原理(十二)WorkflowQueue的提前提交
  • 通过AEC解读WF的核心原理(十一)WF与Windows操作系统的对比
  • 通过AEC解读WF的核心原理(十)取消与取消处理器
  • 通过AEC解读WF的核心原理(九)实现IEventActivity
  • 通过AEC解读WF的核心原理(八)实现Switch功能的Activity
  • 通过AEC解读WF的核心原理(七)一个实现Goto功能的Activity
  • 通过AEC解读WF的核心原理(六)创建复本ForEach循环
  • 通过AEC解读WF的核心原理(五)实现一个从下向上执行的顺序容器
  • 通过AEC解读WF的核心原理(四)AEC在内部执行childActivity
  • 通过AEC解读WF的核心原理(三)Execute方法Activity的入口
 

  容器Designer

public class wxwinterDesigner : FreeformActivityDesigner
{
public wxwinterDesigner()
{
this.ConnectorAdded += new ConnectorEventHandler(wxwinterDesigner_ConnectorAdded);
this.ConnectorChanged += new ConnectorEventHandler(wxwinterDesigner_ConnectorChanged);
this.ConnectorRemoved += new ConnectorEventHandler(wxwinterDesigner_ConnectorRemoved);
}
  
void wxwinterDesigner_ConnectorChanged(object sender, ConnectorEventArgs e)
{
结点 s = e.Connector.Source.AssociatedDesigner.Activity as 结点;
结点 t = e.Connector.Target.AssociatedDesigner.Activity as 结点;
  
s.下一结点 = t;
t.上一结点 = s;
  
}
  
void wxwinterDesigner_ConnectorRemoved(object sender, ConnectorEventArgs e)
{
结点 s = e.Connector.Source.AssociatedDesigner.Activity as 结点;
结点 t = e.Connector.Target.AssociatedDesigner.Activity as 结点;
  
t.上一结点 =null ;
s.下一结点 =null;
}
  
void wxwinterDesigner_ConnectorAdded(object sender, ConnectorEventArgs e)
{
结点 s = e.Connector.Source.AssociatedDesigner.Activity as 结点;
结点 t = e.Connector.Target.AssociatedDesigner.Activity as 结点;
s.下一结点 = t;
t.上一结点 = s;
}
}

  容器Activity

通过AEC解读WF的核心原理(十三完)实现Visio设计风格的Activity


相关教程