WF4虽然在代码中的活动状态 [英] WF4 While activity condition in code

查看:189
本文介绍了WF4虽然在代码中的活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立在我的代码工作流,我不知道我怎么可以添加一个简单的(虽然)的条件。 ,试图弄清楚如何,但它没有运气,在互联网上搜索,但没有运气在任



这是什么,我试图做一个简化的版本:

  ActivityBuilder AB =新ActivityBuilder(); 
ab.Implementation =新序列()
{
变量=
{
新变量< INT>(StepNo,0)
},

=活动
{
新尽管()
{
条件= LT; the_condition>

体=
{
//这里的一些逻辑和StepNo增加
}
}
}
$} b $ b

while条件应该是像StepNo小于10。任何想法怎么能这样作?


解决方案

  VAR stepNo =新变量< INT>(stepNo,0); 

VAR活动=新序列
{
变量=
{
stepNo
},

活动=
{
新虽然
{
条件=新每种不超过< INT,INT,BOOL>
{
左= stepNo,
右键= 10
},

体=新序列
{
活动=
{
新分配< INT>
{
要= stepNo,
值=新添加< INT,INT,INT>
{
左= stepNo,
右键= 1
}
},

新的WriteLine
{
文本=新VisualBasicValue<串>(\步骤:\&放大器; stepNo)
}
}
}
}
}
};

或者没有的表达活动但只的 VisualBasicValue ,这也是一个活动:

  VAR stepNo =新变量< INT>(stepNo,0); 

VAR活动=新序列
{
变量=
{
stepNo
},

活动=
{
新虽然
{
条件=新VisualBasicValue<布尔>(stepNo小于10),

体=新序列
{
=活动
{
新分配< INT>
{
要= stepNo,
值=新VisualBasicValue< INT>(stepNo + 1)
},

新的WriteLine
{
文本=新VisualBasicValue<串>(\步骤:\&放大器; stepNo)
}
}
}
}
}
};


I am building a workflow in my code, and I don't know how I can add a simple (While) condition. Tried to figure out how, but no luck with it, search on the internet but no luck either.

This is a simplified version of what I am trying to do:

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

The While condition should be something like "StepNo < 10". Any idea how can this be made?

解决方案

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") 
                    }
                }
            }
        }
    }
};

Or a version without expression activities but only with VisualBasicValue, which is also an activity:

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") 
                    }
                }
            }
        }
    }
};

这篇关于WF4虽然在代码中的活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆