本文例子說明
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