2011-11-09 42 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」。任何想法如何做到這一點?

+0

拿起[臨WF:Windows工作流在.NET 4.0(HTTP://www.amazon .COM /臨-WF-Windows的工作流專家/ 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") 
        } 
       } 
      } 
     } 
    } 
}; 

還是一個版本,而不expression activities但只有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