WF4.0 基础篇 (十八) Flowchar

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

本文例子下载:

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

本文例子说明

WF4.0 基础篇 (十八) Flowchar

WF4.0 基础篇 (十八) Flowchar

Flowchart 说明

Flowchart

类名

System.Activities.Statements.Flowchart

文件

System.Activities.dll

结构说明

继承 NativeActivity

是一个 sealed类

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

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

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

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

功能说明

 

WF4.0 基础篇 (十八) Flowchar

FlowDecision

类名

System.Activities.Statements.FlowDecision

文件

System.Activities.dll

结构说明

继承 FlowNode

是一个 sealed类

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

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

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

功能说明

 

WF4.0 基础篇 (十八) Flowchar

FlowSwitch

类名

System.Activities.Statements.FlowSwitch

文件

System.Activities.dll

结构说明

继承 FlowNode

是一个 sealed类

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

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

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

功能说明

 

WF4.0 基础篇 (十八) Flowchar

FlowStep

类名

System.Activities.Statements.FlowStep

文件

System.Activities.dll

结构说明

继承 FlowNode

是一个 sealed类

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

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

功能说明

 

WF4.0 基础篇 (十八) Flowchar

Flowchart基本使用

工作流

WF4.0 基础篇 (十八) Flowchar

宿主

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

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

}

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

}

结果

WF4.0 基础篇 (十八) Flowchar

FlowDecision 例子

工作流

WF4.0 基础篇 (十八) Flowchar

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

}

结果

WF4.0 基础篇 (十八) Flowchar

FlowSwitch 例子

工作流

WF4.0 基础篇 (十八) Flowchar

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

}

结果

WF4.0 基础篇 (十八) Flowchar

WF4.0 基础篇 (十八) Flowchar

 
上一篇:25个增强iOS应用程序性能的提示和技巧(0基础篇)


下一篇:Avizo应用 - Home和Set Home