How to conditionally use InvokeMethod in an XAML Windows workflow foundation

自作多情 提交于 2019-12-12 04:32:02

问题


In windows workflow foundation sequence workflow, How to use invoke method tags to be invoked based on certain condition?

For example,

<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>

Suppose, I call the above activity, all the invoke methods will be triggered.

But what is needed, is something like,

<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>

Can someone give some idea how to go about this?


回答1:


You can use the If activity (in namespace System.Activities.Statements) for conditionally executing pieces of a workflow:

<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>


来源:https://stackoverflow.com/questions/37390601/how-to-conditionally-use-invokemethod-in-an-xaml-windows-workflow-foundation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!