WF4.0 基础篇 (十八) Flowchar

本节主要介绍WF4 中 Flowchart的使用

 

本文例子下载:

http://files.cnblogs.com/foundation/FlowcharSample.rar

本文例子说明

image.png

image.png

 


Flowchart 说明


Flowchart

类名

System.Activities.Statements.Flowchart

文件

System.Activities.dll

结构说明

继承 NativeActivity

是一个 sealed类

override 了 [CacheMetadata方法] 与 [Execute方法]

[Variables]属性 的类型为[ Collection<Variable>]

[StartNode]属性 的类型为[FlowNode]

[Nodes]属性 的类型为[Collection<FlowNode>]

功能说明


 

 

image.png

 

FlowDecision

类名

System.Activities.Statements.FlowDecision

文件

System.Activities.dll

结构说明

继承 FlowNode

是一个 sealed类

[Condition]属性 的类型为[Activity<bool>]

[False]属性 的类型为[FlowNode]

[True]属性 的类型为[FlowNode]

功能说明


 

image.png

 

 

 

FlowSwitch

类名

System.Activities.Statements.FlowSwitch

文件

System.Activities.dll

结构说明

继承 FlowNode

是一个 sealed类

[Expression]属性 的类型为[Activity<object>]

[Default]属性 的类型为[FlowNode]

[Cases]属性 的类型为[IDictionary<object, FlowNode>]

功能说明


 

 

image.png

 

FlowStep

 

类名

System.Activities.Statements.FlowStep

文件

System.Activities.dll

结构说明

继承 FlowNode

是一个 sealed类

[Action]属性 的类型为[Activity]

[Next]属性 的类型为[FlowNode]

功能说明


 

image.png

 



Flowchart基本使用

工作流

image.png

宿主

//===================================================

 

WorkflowApplication instance = null;

 

private void button_triggering_Click(object sender, RoutedEventArgs e)

{

string bookName = textBox_bookmark.Text;

string inputValue = textBox_value.Text;

 

if (instance != null)

{

if (instance.GetBookmarks().Count(p => p.BookmarkName == bookName) == 1)

{

instance.ResumeBookmark(bookName, inputValue);

}

else

{

foreach (var v in instance.GetBookmarks())

{

System.Console.WriteLine("-------请从下面选项中选择一BookmarkName---------------------------");

System.Console.WriteLine("BookmarkName:{0}:,OwnerDisplayName:{1}", v.BookmarkName, v.OwnerDisplayName);

System.Console.WriteLine("================================");

}

}

}

else

{

MessageBox.Show("没有创建实例");

}

 

}

 

void workflowCompleted(WorkflowApplicationCompletedEventArgs e)

{

instance = null;

System.Console.WriteLine("workflowCompleted:{0}", e.CompletionState.ToString());

}

 

void aborted(WorkflowApplicationAbortedEventArgs e)

{

instance = null;

System.Console.WriteLine("aborted ,Reason:{0}", e.Reason.Message);

}

 

UnhandledExceptionAction unhandledExceptionl(WorkflowApplicationUnhandledExceptionEventArgs e)

{

System.Console.WriteLine("unhandledException:{0}", e.UnhandledException.Message);

return UnhandledExceptionAction.Cancel;

}

void workflowIdel(WorkflowApplicationIdleEventArgs e)

{

System.Console.WriteLine("Idle:{0}", e.InstanceId);

 

System.Console.WriteLine("--------BookmarkName---------------------------");

foreach (var item in e.Bookmarks)

{

System.Console.WriteLine("{0}", item.BookmarkName);

}

System.Console.WriteLine("================================");

}

//==================================================

 

private void button_baseFlowchartWorkflow_Click(object sender, RoutedEventArgs e)

{

instance = new WorkflowApplication(new FlowcharLibrary.baseFlowchartWorkflow());

 

instance.Completed = new Action<WorkflowApplicationCompletedEventArgs>(workflowCompleted);

instance.OnUnhandledException = unhandledExceptionl;

instance.Aborted = aborted;

instance.Idle = workflowIdel;

instance.Run();

 

}

结果

image.png

 

FlowDecision 例子

工作流

image.png

bookmark

public sealed class bookmark<T> : NativeActivity<T>

{

public InArgument<string> bookmarkName { getset; }

 

protected override bool CanInduceIdle

{

get

return true; }

}

protected override void Execute(NativeActivityContext context)

{

string bookmark = context.GetValue(bookmarkName);

context.CreateBookmark(bookmark, new BookmarkCallback(bookmarkCallback));

System.Console.WriteLine("创建bookmark:{0}", bookmark);

}

void bookmarkCallback(NativeActivityContext context, Bookmark bookmark, object obj)

{

 

if (typeof(T) == typeof(Int32))

{

this.Result.Set(context, int.Parse(obj.ToString()) );

return;

}

 

if (typeof(T) == typeof(string))

{

this.Result.Set(context, obj.ToString());

return;

}

 

this.Result.Set(context,obj);

}

}

宿主

//===================================================

 

WorkflowApplication instance = null;

 

private void button_triggering_Click(object sender, RoutedEventArgs e)

{

string bookName = textBox_bookmark.Text;

string inputValue = textBox_value.Text;

 

if (instance != null)

{

if (instance.GetBookmarks().Count(p => p.BookmarkName == bookName) == 1)

{

instance.ResumeBookmark(bookName, inputValue);

}

else

{

foreach (var v in instance.GetBookmarks())

{

System.Console.WriteLine("-------请从下面选项中选择一BookmarkName---------------------------");

System.Console.WriteLine("BookmarkName:{0}:,OwnerDisplayName:{1}", v.BookmarkName, v.OwnerDisplayName);

System.Console.WriteLine("================================");

}

}

}

else

{

MessageBox.Show("没有创建实例");

}

 

}

 

void workflowCompleted(WorkflowApplicationCompletedEventArgs e)

{

instance = null;

System.Console.WriteLine("workflowCompleted:{0}", e.CompletionState.ToString());

}

 

void aborted(WorkflowApplicationAbortedEventArgs e)

{

instance = null;

System.Console.WriteLine("aborted ,Reason:{0}", e.Reason.Message);

}

 

UnhandledExceptionAction unhandledExceptionl(WorkflowApplicationUnhandledExceptionEventArgs e)

{

System.Console.WriteLine("unhandledException:{0}", e.UnhandledException.Message);

return UnhandledExceptionAction.Cancel;

}

void workflowIdel(WorkflowApplicationIdleEventArgs e)

{

System.Console.WriteLine("Idle:{0}", e.InstanceId);

 

System.Console.WriteLine("--------BookmarkName---------------------------");

foreach (var item in e.Bookmarks)

{

System.Console.WriteLine("{0}", item.BookmarkName);

}

System.Console.WriteLine("================================");

}

//==================================================

private void button_FlowDecisionWorkflow_Click(object sender, RoutedEventArgs e)

{

instance = new WorkflowApplication(new FlowcharLibrary.FlowDecisionWorkflow());

 

instance.Completed = new Action<WorkflowApplicationCompletedEventArgs>(workflowCompleted);

instance.OnUnhandledException = unhandledExceptionl;

instance.Aborted = aborted;

instance.Idle = workflowIdel;

instance.Run();

}

 

结果

image.png

 

FlowSwitch 例子

工作流

image.png

bookmark

public sealed class bookmark<T> : NativeActivity<T>

{

public InArgument<string> bookmarkName { getset; }

 

protected override bool CanInduceIdle

{

get

return true; }

}

protected override void Execute(NativeActivityContext context)

{

string bookmark = context.GetValue(bookmarkName);

context.CreateBookmark(bookmark, new BookmarkCallback(bookmarkCallback));

System.Console.WriteLine("创建bookmark:{0}", bookmark);

}

void bookmarkCallback(NativeActivityContext context, Bookmark bookmark, object obj)

{

 

if (typeof(T) == typeof(Int32))

{

this.Result.Set(context, int.Parse(obj.ToString()) );

return;

}

 

if (typeof(T) == typeof(string))

{

this.Result.Set(context, obj.ToString());

return;

}

 

this.Result.Set(context,obj);

}

}

宿主

//===================================================

 

WorkflowApplication instance = null;

 

private void button_triggering_Click(object sender, RoutedEventArgs e)

{

string bookName = textBox_bookmark.Text;

string inputValue = textBox_value.Text;

 

if (instance != null)

{

if (instance.GetBookmarks().Count(p => p.BookmarkName == bookName) == 1)

{

instance.ResumeBookmark(bookName, inputValue);

}

else

{

foreach (var v in instance.GetBookmarks())

{

System.Console.WriteLine("-------请从下面选项中选择一BookmarkName---------------------------");

System.Console.WriteLine("BookmarkName:{0}:,OwnerDisplayName:{1}", v.BookmarkName, v.OwnerDisplayName);

System.Console.WriteLine("================================");

}

}

}

else

{

MessageBox.Show("没有创建实例");

}

 

}

 

void workflowCompleted(WorkflowApplicationCompletedEventArgs e)

{

instance = null;

System.Console.WriteLine("workflowCompleted:{0}", e.CompletionState.ToString());

}

 

void aborted(WorkflowApplicationAbortedEventArgs e)

{

instance = null;

System.Console.WriteLine("aborted ,Reason:{0}", e.Reason.Message);

}

 

UnhandledExceptionAction unhandledExceptionl(WorkflowApplicationUnhandledExceptionEventArgs e)

{

System.Console.WriteLine("unhandledException:{0}", e.UnhandledException.Message);

return UnhandledExceptionAction.Cancel;

}

void workflowIdel(WorkflowApplicationIdleEventArgs e)

{

System.Console.WriteLine("Idle:{0}", e.InstanceId);

 

System.Console.WriteLine("--------BookmarkName---------------------------");

foreach (var item in e.Bookmarks)

{

System.Console.WriteLine("{0}", item.BookmarkName);

}

System.Console.WriteLine("================================");

}

//==================================================

 

private void button_FlowSwitchWorkflow_Click(object sender, RoutedEventArgs e)

{

instance = new WorkflowApplication(new FlowcharLibrary.FlowSwitchWorkflow());

 

instance.Completed = new Action<WorkflowApplicationCompletedEventArgs>(workflowCompleted);

instance.OnUnhandledException = unhandledExceptionl;

instance.Aborted = aborted;

instance.Idle = workflowIdel;

instance.Run();

}

结果

image.png

 

image.png

 

转载自:https://www.cnblogs.com/foundation/archive/2010/01/08/1642615.html


本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2024年4月    »
1234567
891011121314
15161718192021
22232425262728
2930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864