WF4.0 基础篇 (十八) Flowchart
2013-10-13 16:31
567 查看
本节主要介绍WF4 中 Flowchart的使用
本文例子下载:
http://files.cnblogs.com/foundation/FlowcharSample.rar
本文例子说明
本文例子下载:
http://files.cnblogs.com/foundation/FlowcharSample.rar
本文例子说明
Flowchart 说明
Flowchart
类名 | System.Activities.Statements.Flowchart |
文件 | System.Activities.dll |
结构说明 | 继承 NativeActivity 是一个 sealed类 override 了 [CacheMetadata方法] 与 [Execute方法] [Variables]属性 的类型为[ Collection<Variable>] [StartNode]属性 的类型为[FlowNode] [Nodes]属性 的类型为[Collection<FlowNode>] |
功能说明 |
FlowDecision
类名 | System.Activities.Statements.FlowDecision |
文件 | System.Activities.dll |
结构说明 | 继承 FlowNode 是一个 sealed类 [Condition]属性 的类型为[Activity<bool>] [False]属性 的类型为[FlowNode] [True]属性 的类型为[FlowNode] |
功能说明 |
FlowSwitch
类名 | System.Activities.Statements.FlowSwitch |
文件 | System.Activities.dll |
结构说明 | 继承 FlowNode 是一个 sealed类 [Expression]属性 的类型为[Activity<object>] [Default]属性 的类型为[FlowNode] [Cases]属性 的类型为[IDictionary<object, FlowNode>] |
功能说明 |
FlowStep
类名 | System.Activities.Statements.FlowStep |
文件 | System.Activities.dll |
结构说明 | 继承 FlowNode 是一个 sealed类 [Action]属性 的类型为[Activity] [Next]属性 的类型为[FlowNode] |
功能说明 |
例
Flowchart基本使用
工作流 | |
宿主 | //=================================================== 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(); } |
结果 |
FlowDecision 例子
工作流 | |
bookmark | public sealed class bookmark<T> : NativeActivity<T> { public InArgument<string> bookmarkName { get; set; } 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(); } |
结果 |
FlowSwitch 例子
工作流 | |
bookmark | public sealed class bookmark<T> : NativeActivity<T> { public InArgument<string> bookmarkName { get; set; } 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(); } |
结果 |
相关文章推荐
- java导入ecxl数据
- JSTL的fn函数
- Windows系统使用minGW+msys 编译ffmpeg 0.5的全过程详述
- WF4.0 基础篇 (十七) Bookmark
- 日日日日日日日
- c++ 虚函数的实现机制:笔记
- Xcode学习笔记---Xcode3与Xcode4的区别
- Android之Service与IntentService的比较
- MFC窗口最小化到托盘
- 嵌入式开发基础环境搭建
- MFC窗口最小化到托盘
- jsp study 4 操作符
- 个人感觉不错的英文歌
- ubuntu12.04 开机自动挂载磁盘分区
- 在博客文章插入“可运行"js代码-博客园
- 优秀程序员必须了解的32个算法
- Eclipse中最有用的快捷键组合
- poj 1947 Rebuilding Roads ---树形DP
- C常见问题之字符串的数组形式与指针形式的区别
- #中国IT界的第一本漂流日记 传递IT正能量# 【分享得“IT漂友”勋章】