2013-03-24 31 views
0

我開發一個購物車的控制檯WF應用程序建模在線購物車這樣的:https://docs.google.com/drawings/d/15e24iO-OCcQuO7PwqQVJpTOd1RHs4e042S-zyjL1iu0/pub?w=1001&h=728在WF4控制檯應用程序沒有移動到下活動 - 購物車

我使用從控制檯讀取輸入書籤活動。因此,3個書籤活動r用於閱讀ItemID,Qty,ContinueShopping

活動內部。在輸入ItemID後,如果我輸入Yes,則繼續購物活動。控制檯沒有任何事情發生。

它應該詢問下一個活動「輸入數量」? RT?什麼是問題。 Plz指導我。

的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 &amp; 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 &gt;= 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&lt;Product&gt;" 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="[&quot;Thank you customer. Your bill amount is Rs:&quot; + varShoppingCart.Sum(Function(x) x.Price * x.Quantity).ToString() + &quot;/ only&quot;]" /> 
    </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); 
     } 
    } 
} 

回答

0

關於這個問題,通常創建xaml文件中,你改變了路徑(即,當你改變你的項目到另一個文件夾) 在你的codebehing你有:

XamlDebuggerXmlReader.FileName="G:\Development\Shopping Cart\WFShoppingCart\WFShoppingCart\WFShopping.xaml" 

請檢查您的xaml「完整路徑」屬性是否與此相同。 一旦兩者相等,您就可以調試您的活動。