程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> WF 4.0基礎篇(十八) Flowchar

WF 4.0基礎篇(十八) Flowchar

編輯:關於.NET

本文例子說明

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

結果

本文例子下載:http://files.cnblogs.com/foundation/FlowcharSample.rar

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved