如何在XAML Windows工作流基础中有条件地使用InvokeMethod

时间:2016-05-23 12:06:45

标签: xaml workflow-foundation-4 workflow-foundation workflow-activity app.xaml

在Windows工作流基础序列工作流中,如何使用基于特定条件调用的调用方法标记?

例如,

<Sequence>
  <Sequence.Variables>
<Variable x:TypeArguments="x:String" Default="[&quot;this is an out param&quot;]" Name="outParam" />
  <Variable x:TypeArguments="x:Int32" Name="resultValue" />
  <Variable x:TypeArguments="msi:TestClass" Default="[New TestClass()]" Name="varTestClass" />
</Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
  <scg:Dictionary x:TypeArguments="x:String, s:Object">
    <x:Boolean x:Key="IsExpanded">True</x:Boolean>
  </scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Instance method call&quot;]" />
<InvokeMethod DisplayName="Instance Method Call" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="InstanceMethod1">
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[New TestClass()]</InArgument>
  </InvokeMethod.TargetObject>
</InvokeMethod>
<InvokeMethod DisplayName="Instance Method Call with Parameters" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="InstanceMethod">
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[New TestClass()]</InArgument>
  </InvokeMethod.TargetObject>
  <InArgument x:TypeArguments="x:String">["My favorite number is"]</InArgument>
  <InArgument x:TypeArguments="x:Int32">42</InArgument>
</InvokeMethod>
</Sequence>

假设,我调用上面的活动,将触发所有的调用方法。

  

但是需要的是,

<Sequence>
  <Sequence.Variables>
<Variable x:TypeArguments="x:String" Default="[&quot;this is an out param&quot;]" Name="outParam" />
  <Variable x:TypeArguments="x:Int32" Name="resultValue" />
  <Variable x:TypeArguments="msi:TestClass" Default="[New TestClass()]" Name="varTestClass" />
</Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
  <scg:Dictionary x:TypeArguments="x:String, s:Object">
    <x:Boolean x:Key="IsExpanded">True</x:Boolean>
  </scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<WriteLine sap:VirtualizedContainerService.HintSize="299.663333333333,59.2766666666667" Text="[&quot;Instance method call&quot;]" />
//If (stateArgument =="created")
//{
<InvokeMethod DisplayName="Instance Method Call" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="InstanceMethod1">
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[New TestClass()]</InArgument>
  </InvokeMethod.TargetObject>
</InvokeMethod>
//}
//else if(stateArguement == "running")
//{
<InvokeMethod DisplayName="Instance Method Call with Parameters" sap:VirtualizedContainerService.HintSize="299.663333333333,127.553333333333" MethodName="InstanceMethod">
  <InvokeMethod.TargetObject>
    <InArgument x:TypeArguments="msi:TestClass">[New TestClass()]</InArgument>
  </InvokeMethod.TargetObject>
  <InArgument x:TypeArguments="x:String">["My favorite number is"]</InArgument>
  <InArgument x:TypeArguments="x:Int32">42</InArgument>
</InvokeMethod>
//}
</Sequence>

有人可以知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您可以使用If活动(在命名空间System.Activities.Statements中)有条件地执行工作流程的各个部分:

<If DisplayName="Invoke something based on a conditional" sap2010:WorkflowViewState.IdRef="If_1">
    <If.Condition>
        <InArgument x:TypeArguments="x:Boolean">
            <mca:CSharpValue x:TypeArguments="x:Boolean">1 == 2</mca:CSharpValue>
        </InArgument>
    </If.Condition>
    <If.Then>
        <InvokeMethod sap2010:WorkflowViewState.IdRef="InvokeMethod_1" MethodName="WriteSomething" TargetType="local:MyStatics" />
    </If.Then>
    <If.Else>
        <InvokeMethod sap2010:WorkflowViewState.IdRef="InvokeMethod_2" MethodName="WriteSomethingElse" TargetType="local:MyStatics" />
    </If.Else>
</If>