WorkflowControlActions クラス

Namespace: Microsoft.Azure。Workflows.Sdk

分岐、グループ化、繰り返し、または停止する制御フローアクションを作成するファクトリーメソッドを提供します。 このクラスはを使ってWorkflowActions.BuiltIn.Controlからアクセスできます。

使用状況

// Access control actions via WorkflowActions.BuiltIn.Control
var trigger = WorkflowTriggers.BuiltIn.CreateHttpTrigger();

var scope = WorkflowActions.BuiltIn.Control.Scope(() =>
{
    var step1 = WorkflowActions.BuiltIn.Compose(inputs: () => "Process").WithName("Process");
    return step1;
}).WithName("ProcessingScope");

trigger.Then(scope);
WorkflowFactory.CreateStatefulWorkflow("ControlFlowExample", trigger);

Methods

Scope

ネストされたアクションを単一の IWorkflowActionにまとめるScopeアクションを作成します。

IWorkflowAction Scope(Func<IChainableNode> actions)
名前 Description タイプ 必須
actions ネストされたアクショングラフを構築するファクトリー。 Func<IChainableNode> はい
var scope = WorkflowActions.BuiltIn.Control.Scope(() =>
{
    var step1 = WorkflowActions.BuiltIn.Compose(inputs: () => "Step 1").WithName("Step1");
    var step2 = WorkflowActions.BuiltIn.Compose(inputs: () => "Step 2").WithName("Step2");
    return step1.Then(step2);
}).WithName("MyScope");

Condition

ブール式を評価し、実行を2つのブランチのいずれかにルーティングする条件付きアクションを作成します。

IWorkflowAction Condition(Expression<Func<bool>> expression, Func<IChainableNode> trueBranch, Func<IChainableNode> falseBranch)
名前 Description タイプ 必須
評価のためのブール式。 Expression<Func<bool>> はい
trueBranch 真の分部行動のための工場。 Func<IChainableNode> はい
falseBranch 偽の分岐行動のための工場。 Func<IChainableNode> はい
var condition = WorkflowActions.BuiltIn.Control.Condition(
    expression: () => trigger.TriggerOutput.Body != null,
    trueBranch: () => WorkflowActions.BuiltIn.Compose(inputs: () => "Has body").WithName("True"),
    falseBranch: () => WorkflowActions.BuiltIn.Compose(inputs: () => "No body").WithName("False")
).WithName("CheckBody");

ForEach

コレクションを反復し、各アイテムに対して提供されたアクショングラフを実行するループアクションを作成します。

IWorkflowAction ForEach(Expression<Func<JToken>> items, Func<JToken, IChainableNode> actions)
名前 Description タイプ 必須
items コレクションが反復するための式です。 Expression<Func<Jtoken>> はい
actions ファクトリーが現在のアイテムを受け取り、アクショングラフを返します。 Func<JToken, IChainableNode> はい
var forEach = WorkflowActions.BuiltIn.Control.ForEach(
    items: () => JArray.Parse("[\"one\",\"two\"]"),
    actions: (item) => WorkflowActions.BuiltIn.Compose(inputs: () => $"Item: {item}").WithName("ProcessItem")
).WithName("LoopItems");

Until

提供された式が真に評価されるまで、入れ子状の行動を繰り返すループアクションを作成します。

IWorkflowAction Until(Expression<Func<bool>> expression, Func<IChainableNode> actions)
名前 Description タイプ 必須
ブールの出口条件。 Expression<Func<bool>> はい
actions 繰り返しアクショングラフを構築する工場。 Func<IChainableNode> はい
var counterVar = WorkflowActions.BuiltIn.Variables.InitializeVariable<int>(
    name: () => "counter",
    value: () => 0).WithName("Counter");

var until = WorkflowActions.BuiltIn.Control.Until(
    expression: () => counterVar.Value.Value<int>() >= 10,
    actions: () => WorkflowActions.BuiltIn.Variables.IncrementVariable<int>(
        name: () => "counter", value: () => 1).WithName("Increment")
).WithName("RepeatUntil10");

スイッチ

入力を評価し、実行を対応するSwitchCaseまたはデフォルトの分岐にルーティングするスイッチアクションを作成します。

IWorkflowAction Switch(Expression<Func<JToken>> on, Func<Dictionary<string, SwitchCase>> cases, Func<IChainableNode> defaultCase = null)
名前 Description タイプ 必須
値をオンにする表現。 Expression<Func<Jtoken>> はい
cases 工場出荷時にケースラベルをSwitchCaseのマッピングに返品します。 Func<Dictionary<string、SwitchCase>> はい
defaultCase デフォルトのケースアクションは工場出荷時です。 Func<IChainableNode> いいえ
var switchAction = WorkflowActions.BuiltIn.Control.Switch(
    on: () => trigger.TriggerOutput.Body,
    cases: () => new Dictionary<string, SwitchCase>
    {
        ["case1"] = new SwitchCase("value1",
            WorkflowActions.BuiltIn.Compose(inputs: () => "Case 1").WithName("HandleCase1")),
        ["case2"] = new SwitchCase("value2",
            WorkflowActions.BuiltIn.Compose(inputs: () => "Case 2").WithName("HandleCase2"))
    },
    defaultCase: () => WorkflowActions.BuiltIn.Compose(inputs: () => "Default").WithName("HandleDefault")
).WithName("RouteByValue");

Terminate

指定されたFlowStatusとオプションメッセージでワークフローを停止する終了アクションを作成する。

IWorkflowAction Terminate(Expression<Func<FlowStatus>> status, Expression<Func<string>> message = null)
名前 Description タイプ 必須
状態 解雇ステータスの表現。 Expression<Func<FlowStatus>> はい
メッセージ 終了メッセージの表現。 Expression<Func<string>> いいえ
var terminate = WorkflowActions.BuiltIn.Control.Terminate(
    status: () => FlowStatus.Failed,
    message: () => "Critical error occurred").WithName("StopWorkflow");