开发者

How does ActivityContext, LocationReferenceEnvironment, Arguments and Variables work in WF4?

开发者 https://www.devze.com 2023-02-28 21:25 出处:网络
I understand that flow control and context are separated on WF4 but I\'m asking you how can I control the context of a given workflow.

I understand that flow control and context are separated on WF4 but I'm asking you how can I control the context of a given workflow.

WorkflowApplication have a HostEnvironment property which, accordingly to documentation gets or sets the root environment for the workflow instance’s arguments and variables.

What's the difference between LocationReferenceEnvironment and the ActivityContext itself? Who creates and controls the context? As I understand it each activity has its own context but not all activities have variables, for example.

I want the maximum control over the context of a given workflow but I'm having trouble understanding the inner workings of all this stuff. Can someone explain it to me and/or pointing me s开发者_如何学运维ome good articles preferably from programming's point of view. Unfortunately MSDN , and more specifically .NET Framework Class Library, are scarce on good WF4 documentation.


I don't think there is any documentation on the internals here. Not sure if it would do you a lot of good, most if not all of this stuff is internal to WF4 and can't be changed even if you wanted to.

Basically a location reference is a place to store data, something exposed by a variable in your workflow. By default you can only add variables to composite activities. There is no technical reason here it's just that a variable is used to share data between multiple activities so adding them to an activity that doesn't have children, or only a single, doesn't buy you anything. That said you are free to do so in your own activities if you want to.

What are you trying to accomplish that you need maximum control over the activity context?

Update: Not sure if this helps but this is how you can create VB expressions in code:

var wf = new Sequence()
{
    Variables =
    {
        new Variable<string>("var1", "Some value"),
        new Variable<int>("var2", c=> Environment.TickCount),
    },
    Activities =
    {
        new WriteLine() {
            Text = new VisualBasicValue<string>("\"String value: \" & var1 ")
        },
        new WriteLine() {
            Text = new VisualBasicValue<string>("\"Int value: \" & var2 ")
        }

    }
};

WorkflowInvoker.Invoke(wf);
0

精彩评论

暂无评论...
验证码 换一张
取 消