WF4.0 基础篇 (十八) Flowchar

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

 

本文例子下载:

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();

}

结果

 

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值