閱讀: 602 評(píng)論: 0 作者: 生魚片 發(fā)表于 2009-12-07 21:24 原文鏈接
標(biāo)題的兩者并沒有什么關(guān)系,只是內(nèi)容都比較短就放到一起了。
1.在工作流中存儲(chǔ)ModelItems的視圖狀態(tài)。
例子, 我們創(chuàng)建一個(gè)自定義活動(dòng)的活動(dòng)設(shè)計(jì)器ActivityDesigner1.XAML,如下:
<sap:ActivityDesigner x:Class="CaryActivityLibrary1.ActivityDesigner1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">
<Grid>
<StackPanel Name="stackPanel1" VerticalAlignment="Top" >
<TextBox Name="commentBlock" />
<Button Content="
<Button Content="
</StackPanel>
</Grid>
</sap:ActivityDesigner>
對(duì)應(yīng)的代碼如下:
private void loadViewState_Click(object sender, RoutedEventArgs e)
{
ViewStateService vss = this.Context.Services.GetService<ViewStateService>();
commentBlock.Text = vss.RetrieveViewState(this.ModelItem, "comment") as string;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ViewStateService vss = this.Context.Services.GetService<ViewStateService>();
vss.StoreViewStateWithUndo(this.ModelItem, "comment", commentBlock.Text);
}
我們?cè)诠ぷ髁髦惺褂迷摶顒?dòng),輸入一些信息后提交ViewState,你會(huì)看到工作流中增加了如下部分:
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:String x:Key="comment">123456</x:String>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
補(bǔ)償是提供給前面已經(jīng)成功的操作一個(gè)補(bǔ)償?shù)臋C(jī)會(huì),WF4提供了下面活動(dòng)支持補(bǔ)償:
1. CompensableActivity活動(dòng),該活動(dòng)調(diào)用后會(huì)返回一個(gè)CompensationToken類型的Result屬性,
2. Compensate活動(dòng)和Confirm活動(dòng)用于顯示的調(diào)用CompensableActivity活動(dòng)的confirmation handler 和 compensation handler部分。這兩個(gè)活動(dòng)都有一個(gè)Target屬性用于指定CompensableActivity活動(dòng)的Result屬性。
3. CompensableActivity活動(dòng)的CompenationHandler當(dāng)工作流有異常時(shí)調(diào)用,ConfirmationHandler為工作流正常執(zhí)行完成后調(diào)用不是CompensableActivity活動(dòng)執(zhí)行完成就立即調(diào)用,CancellationHandler為活動(dòng)取消時(shí)調(diào)用。
參考資源:
1.http://blogs.msdn.com/mwinkle/archive/2009/12/06/wf4-viewstateservice.aspx
2.http://msdn.microsoft.com/en-us/library/system.activities.presentation.view.viewstateservice_members(VS.100).aspx
3.http://msdn.microsoft.com/en-us/library/dd489415(VS.100).aspx
新聞?lì)l道:Mono發(fā)布2.4.3版本,支持C# 4.0的所有功能
推薦鏈接:Windows 7專題發(fā)布
網(wǎng)站導(dǎo)航:博客園首頁(yè) 個(gè)人主頁(yè) 新聞 社區(qū) 博問 閃存 知識(shí)庫(kù)
文章來源:http://www.cnblogs.com/carysun/archive/2009/12/07/wf4-viewstateservice-compensate.html