2011-11-09 17 views
2

私は自分のコードでワークフローを構築していますが、シンプルな(While)条件を追加する方法がわかりません。どのように運行されているのか、インターネット上で検索してみるといいですが、運はありません。WF4コード内のアクティビティ条件

これは私が何をしようとしています何の簡易版である:

ActivityBuilder ab = new ActivityBuilder(); 
ab.Implementation = new Sequence() 
{ 
    Variables = 
    { 
    new Variable<int>("StepNo", 0) 
    }, 

    Activities = 
    { 
    new While() 
    { 
     Condition = <the_condition> 

     Body = 
     { 
     //Some logic here and the StepNo is increased 
     } 
    } 
    } 
} 

while条件は「StepNo < 10」のようなものでなければなりません。どのような考えがこれを作ることができますか?また、活動である

expression activitiesなし
+0

[プロWF:.NET 4.0のWindowsワークフロー]をピックアップします(http://www.amazon .com/Pro-WF-Windows-Workflow-Experts/dp/1430227214)を参照してください。 – TrueWill

答えて

4
var stepNo = new Variable<int>("stepNo", 0); 

var activity = new Sequence 
{ 
    Variables = 
    { 
     stepNo 
    }, 

    Activities = 
    { 
     new While 
     { 
      Condition = new LessThan<int,int,bool> 
      { 
       Left = stepNo, 
       Right = 10 
      }, 

      Body = new Sequence 
      { 
       Activities = 
       { 
        new Assign<int> 
        { 
         To = stepNo, 
         Value = new Add<int, int, int> 
         { 
          Left = stepNo, 
          Right = 1 
         } 
        }, 

        new WriteLine 
        { 
         Text = new VisualBasicValue<string>("\"Step: \" & stepNo") 
        } 
       } 
      } 
     } 
    } 
}; 

またはバージョンだけVisualBasicValueと、:

var stepNo = new Variable<int>("stepNo", 0); 

var activity = new Sequence 
{ 
    Variables = 
    { 
     stepNo 
    }, 

    Activities = 
    { 
     new While 
     { 
      Condition = new VisualBasicValue<bool>("stepNo < 10"), 

      Body = new Sequence 
      { 
       Activities = 
       { 
        new Assign<int> 
        { 
         To = stepNo, 
         Value = new VisualBasicValue<int>("stepNo + 1") 
        }, 

        new WriteLine 
        { 
         Text = new VisualBasicValue<string>("\"Step: \" & stepNo") 
        } 
       } 
      } 
     } 
    } 
}; 
+0

こんにちは@Jota、[この質問のOP](http://stackoverflow.com/questions/16926041/while-activity-code-condition-in-wf4)あなたに非常に似た問題を抱えている、あなたはこれを見てみましょうもしあなたが瞬間を得たら?ありがとう。 – halfer

関連する問題