首页 新闻 会员 周边 捐助

哪位大师帮我看下WF4.0 为什么DoWhile不循环呢?

0
悬赏园豆:80 [已关闭问题] 关闭于 2014-12-04 16:02
    [Designer(typeof(CompositeDesigner))]
    public class MyCompsiteActivity : NativeActivity
    {

        public Variable<int> Index = new Variable<int>();

      public Activity DoWhileActivity { get; set; }
        public MyCompsiteActivity()
        {

            DoWhileActivity = CreateDoWhile();
        }

        protected override void CacheMetadata(NativeActivityMetadata metadata)
        {



            metadata.AddChild(DoWhileActivity);

            metadata.AddImplementationVariable(this.Index);

            base.CacheMetadata(metadata);
        }

        protected override void Execute(NativeActivityContext context)
        {
            context.ScheduleActivity(this.DoWhileActivity, onActivityCompleted);
            //ScheduleActivities(context);
            
        }

        void ScheduleActivities(NativeActivityContext context)
        {

        }
        void onActivityCompleted(NativeActivityContext context, ActivityInstance instance)
        {
            ScheduleActivities(context);
        }

        private Activity CreateDoWhile()
        {
            Variable<bool> VResult = new Variable<bool>("VResult", false);
            return new DoWhile()
            {
                DisplayName = "DoWhile",
                Variables = { VResult },
                Condition = ExpressionServices.Convert<bool>(env => VResult.Get(env)),
                Body = new Sequence()
                {
                    DisplayName = "DoWhile Body",
                    Activities = 
                    {
                        new If()
                        {
                            DisplayName = "If Then Else",
                            //Code to be added here in Level 2
                            Condition = ExpressionServices.Convert<bool>(env => VResult.Get(env)),
                            Then = new IFThenActivity() { DisplayName="Set Resut True", InOutResult=VResult},
                            Else = new IFElseActivity(){ DisplayName="Double Click End Key"}
                        }
                    }

                }
            };
        }
    }
    public sealed class IFElseActivity : CodeActivity
    {
      
        protected override void Execute(CodeActivityContext context)
        {
            Console.WriteLine("Double Press End Keys!");
        }
    }
  public sealed class IFThenActivity : CodeActivity
    {
        public InOutArgument<bool> InOutResult { get; set; }
        protected override void Execute(CodeActivityContext context)
        {

            Console.WriteLine("Set InOutResult True!");

            bool s1 = context.GetValue(this.InOutResult);
            Console.WriteLine("Preset is :"+s1);
            context.SetValue(this.InOutResult, true);
            Console.WriteLine("Postset is :" + s1);
        }
    }
问题补充:
    class Program
    {
        static void Main(string[] args)
        {
            WorkflowInvoker.Invoke(new Workflow2());
            Console.Read();
        }
    }这个问题解决啦就是条件的地方有问题。
但是我还有个问题,怎么禁止修改DoWhileActivity的属性 、禁止在DoWhile里面的Sequence里面再次添加Activity那?必须是默认创建的。谢谢各位啦!!
亲福的主页 亲福 | 初学一级 | 园豆:40
提问于:2013-09-16 17:03
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册