Workflow foundation 用代码表示的非常简单的WF工作流 这个问题实际上是为了帮助我理解Windows工作流基础(WF),以及如何使用设计器在XAML中创建工作流,与我在代码中可以做的(我是程序员)相比。

Workflow foundation 用代码表示的非常简单的WF工作流 这个问题实际上是为了帮助我理解Windows工作流基础(WF),以及如何使用设计器在XAML中创建工作流,与我在代码中可以做的(我是程序员)相比。,workflow-foundation,Workflow Foundation,这是: using System; using System.Activities; using System.Activities.Statements; namespace WorkflowConsoleApplication1 { public class CodeDefinedWorkflow : Activity { static void Main(string[] args) { Console.WriteL

这是:

using System;
using System.Activities;
using System.Activities.Statements;

namespace WorkflowConsoleApplication1
{
    public class CodeDefinedWorkflow : Activity
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Invoking the workflow now");
            WorkflowInvoker.Invoke(new CodeDefinedWorkflow());
        }

        public CodeDefinedWorkflow()
        {
            Sequence s = new Sequence
            {
                Activities = {
                                new WriteLine {Text = "Hello"},
                                new Sequence 
                                {
                                    Activities =
                                    {
                                        new WriteLine {Text = "Workflow"},
                                        new WriteLine {Text = "World"}
                                    }
                                }
                             }
            };
        }
    }
}
我希望
WriteLine
活动将文本写入控制台(默认值?)

我肯定缺少添加根
序列
活动的方法。我还尝试将其作为一个属性,并试图找到初始化组件的方法


有谁能启发我吗?

好的,我找到了答案

删除构造函数的内容-并且有一个属性要重写:

    protected override Func<Activity> Implementation
    {
        get
        {
            return () =>
                {
                    Sequence s = new Sequence
                        {
                            Activities = {
                                        new WriteLine {Text = "Hello"},
                                        new Sequence 
                                        {
                                            Activities =
                                            {
                                                new WriteLine {Text = "Workflow"},
                                                new WriteLine {Text = "World"}
                                            }
                                        }
                                     }
                        };
                    return s;
                };

        }
        set
        {
            base.Implementation = value;
        }
    }
protectedoverride Func实现
{
得到
{
return()=>
{
序列s=新序列
{
活动={
新建WriteLine{Text=“Hello”},
新序列
{
活动=
{
新建WriteLine{Text=“Workflow”},
新WriteLine{Text=“World”}
}
}
}
};
返回s;
};
}
设置
{
基础。实施=价值;
}
}

或将构造函数中创建的对象分配给base.Implementation属性