私は次のようなオンライン ショッピング カートをモデル化するショッピング カート コンソール WF アプリケーションを開発しています:
コンソールから入力を読み取るブックマーク アクティビティを使用しています。したがって、3 つのブックマーク アクティビティは、以前は , を読んItemID
でいましQty
た。ContinueShopping
活動中。アイテムIDを入力した後、はいを入力すると、買い物を続けるアクティビティで。コンソールでは何も起こりません。
次のアクティビティに「数量を入力してください」と尋ねるべきですか? rt? どうした。ガイドしてください。
Xaml:
<Activity mc:Ignorable="sads sap" x:Class="OnlineShoppingCartWorkFlow.ShoppingCartWorkflow" local:ShoppingCartWorkflow.IsContinueArg="Y" local:ShoppingCartWorkflow.OrderIDArg="0"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:local="clr-namespace:OnlineShoppingCartWorkFlow"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System"
xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:s1="clr-namespace:System;assembly=System"
xmlns:s2="clr-namespace:System;assembly=System.Xml"
xmlns:s3="clr-namespace:System;assembly=System.Core"
xmlns:s4="clr-namespace:System;assembly=System.ServiceModel"
xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities"
xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System"
xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel"
xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core"
xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib"
xmlns:sd="clr-namespace:System.Data;assembly=System.Data"
xmlns:sl="clr-namespace:System.Linq;assembly=System.Core"
xmlns:st="clr-namespace:System.Text;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Members>
<x:Property Name="IsContinueArg" Type="InArgument(x:String)" />
<x:Property Name="OrderIDArg" Type="InArgument(x:String)" />
<x:Property Name="QtyArg" Type="InArgument(x:String)" />
</x:Members>
<sap:VirtualizedContainerService.HintSize>632,1674</sap:VirtualizedContainerService.HintSize>
<mva:VisualBasic.Settings>Assembly references and imported namespaces for internal implementation</mva:VisualBasic.Settings>
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="ShouldCollapseAll">False</x:Boolean>
<x:Boolean x:Key="ShouldExpandAll">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<Sequence DisplayName="Sequence1" sad:XamlDebuggerXmlReader.FileName="G:\Development\Shopping Cart\WFShoppingCart\WFShoppingCart\WFShopping.xaml" sap:VirtualizedContainerService.HintSize="592,1634">
<Sequence.Variables>
<Variable x:TypeArguments="scg3:List(local:Product)" Default="[New List(Of Product)]" Name="varStockList" />
<Variable x:TypeArguments="scg3:List(local:Product)" Default="[New List(Of Product)]" Name="varShoppingCart" />
</Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<Assign DisplayName="Get Stock & Assign" sap:VirtualizedContainerService.HintSize="570,60">
<Assign.To>
<OutArgument x:TypeArguments="scg3:List(local:Product)">[varStockList]</OutArgument>
</Assign.To>
<Assign.Value>
<InArgument x:TypeArguments="scg3:List(local:Product)">[New Product().GetStock()]</InArgument>
</Assign.Value>
</Assign>
<Sequence DisplayName="SequenceWhile" sap:VirtualizedContainerService.HintSize="570,1410">
<Sequence.Variables>
<Variable x:TypeArguments="x:Int32" Default="0" Name="varBillAmount" />
</Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<While DisplayName="While Continue Shopping" sap:VirtualizedContainerService.HintSize="548,1185">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">False</x:Boolean>
<x:Boolean x:Key="IsPinned">False</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<While.Condition>[IsContinueArg.ToUpper() = "Y"]</While.Condition>
<Sequence DisplayName="SequenceWhileBody" sap:VirtualizedContainerService.HintSize="522,1067">
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<WriteLine sap:VirtualizedContainerService.HintSize="500,61" Text="Enter the ProductID:" />
<local:MyReadLine BookmarkName="IDBookmark" DisplayName="Read OrderID" sap:VirtualizedContainerService.HintSize="500,22" Result="[OrderIDArg]" />
<WriteLine sap:VirtualizedContainerService.HintSize="500,61" Text="Enter the Qty:" />
<local:MyReadLine BookmarkName="QtyBookmark" DisplayName="Read Qty" sap:VirtualizedContainerService.HintSize="500,22" Result="[QtyArg]" />
<If Condition="[varStockList.Exists(Function(x) x.ProductID = Convert.ToInt32(OrderIDArg) And x.Quantity >= Convert.ToInt32(QtyArg))]" DisplayName="Check Stock Availablity" sap:VirtualizedContainerService.HintSize="500,454">
<If.Then>
<Sequence DisplayName="SequenceIfTrue" sap:VirtualizedContainerService.HintSize="264,346">
<Sequence.Variables>
<Variable x:TypeArguments="local:Product" Default="[New Product()]" Name="varAddProduct" />
</Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<Assign DisplayName="Assign Prodcut" sap:VirtualizedContainerService.HintSize="242,60">
<Assign.To>
<OutArgument x:TypeArguments="local:Product">[varAddProduct]</OutArgument>
</Assign.To>
<Assign.Value>
<InArgument x:TypeArguments="local:Product">[varStockList.Find(Function(x) x.ProductID = Convert.ToInt32(OrderIDArg))]</InArgument>
</Assign.Value>
</Assign>
<Assign DisplayName="Assign Qty Of Product" sap:VirtualizedContainerService.HintSize="242,60">
<Assign.To>
<OutArgument x:TypeArguments="x:Int32">[varAddProduct.Quantity]</OutArgument>
</Assign.To>
<Assign.Value>
<InArgument x:TypeArguments="x:Int32">[Convert.ToInt32(QtyArg)]</InArgument>
</Assign.Value>
</Assign>
<AddToCollection x:TypeArguments="local:Product" Collection="[varShoppingCart]" DisplayName="AddToCollectionShoppingCart<Product>" sap:VirtualizedContainerService.HintSize="242,22" Item="[varAddProduct]" />
</Sequence>
</If.Then>
<If.Else>
<WriteLine sap:VirtualizedContainerService.HintSize="211,61" Text="Item is out of stock!" />
</If.Else>
</If>
<WriteLine sap:VirtualizedContainerService.HintSize="500,61" Text="Shopping Continue Y/N?" />
<local:MyReadLine BookmarkName="ContinueBookmark" DisplayName="Read Shopping Continue" sap:VirtualizedContainerService.HintSize="500,22" Result="[IsContinueArg]" />
</Sequence>
</While>
<WriteLine sap:VirtualizedContainerService.HintSize="548,61" Text="["Thank you customer. Your bill amount is Rs:" + varShoppingCart.Sum(Function(x) x.Price * x.Quantity).ToString() + "/ only"]" />
</Sequence>
</Sequence>
</Activity>
NativeActivity から派生した MyReadLine クラスというカスタム アクティビティを使用しています。このアクティビティ読み取り入力
コンソール。そしてブックマーク活動です。
Program.cs ファイル:>
using System;
using System.Linq;
using System.Activities;
using System.Activities.Statements;
using System.Collections.Generic;
using System.Threading;
namespace OnlineShoppingCartWorkFlow
{
class Program
{
static void Main(string[] args)
{
WorkflowApplication wfApp = new WorkflowApplication(new ShoppingCartWorkflow());
AutoResetEvent idleEvent = new AutoResetEvent(false);
wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
idleEvent.Set();
};
wfApp.Run();
idleEvent.WaitOne();
string bookmarkName = "IDBookmark";
BookmarkResumptionResult result = wfApp.ResumeBookmark(bookmarkName, Console.ReadLine());
bookmarkName = "QtyBookmark";
result = wfApp.ResumeBookmark(bookmarkName, Console.ReadLine());
bookmarkName = "ContinueBookmark";
result = wfApp.ResumeBookmark(bookmarkName, Console.ReadLine());
Console.ReadLine();
}
}
}
私のカスタムアクティビティクラス:
using System.Activities;
namespace OnlineShoppingCartWorkFlow
{
public class MyReadLine : NativeActivity<string>
{
[RequiredArgument]
public InArgument<string> BookmarkName { get; set; }
protected override void Execute(NativeActivityContext context)
{
context.CreateBookmark(BookmarkName.Get(context), new BookmarkCallback(OnResumeBookmark));
//context.CreateBookmark(BookmarkName.Get(context), new BookmarkCallback(OnResumeBookmark), BookmarkOptions.MultipleResume);
}
protected override bool CanInduceIdle
{
get
{
{ return true; }
}
}
public void OnResumeBookmark(NativeActivityContext context, Bookmark bookmark, object obj)
{
Result.Set(context, (string)obj);
}
}
}