我正在开发一个购物车控制台 WF 应用程序建模在线购物车,如下所示:https ://docs.google.com/drawings/d/15e24iO-OCcQuO7PwqQVJpTOd1RHs4e042S-zyjL1iu0/pub?w=1001&h=728
我正在使用从控制台读取输入的书签活动。所以 3 个书签活动 r 用来阅读ItemID
, Qty
,ContinueShopping
在里面活动。在继续购物活动中,如果我在输入 ItemID 后输入 Yes。控制台上什么也没有发生。
它应该问下一个活动“输入数量”吗?rt?什么问题。请指导我。
xml:
<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);
}
}
}