Posts Tagged ‘WF’

If your Activities OutArgument is something complex,say List<string> for eg,then you need to initialize it first & If you don’t do so,you will get an exception The property ‘Collection’ of ‘AddToCollection<String>’ is not initialized.

For assigning default value to the variable,you can use the assign activity & initialize it to New List(Of String).Though your language is C#,if you look at,you will understand that the initialization to variable is a VB expression ! It’s not a big deal to write an expression in VB ,still I wonder why is it so when the project is C# :)If you know the answer,please share  that in the comments section below 🙂

Advertisements

WorkflowInvoker class provides a means for invoking a workflow as if it were a method call.

Namespace:System.Activities
Assembly:System.Activities (in System.Activities.dll)

A custom activity example which we will call using WorkFlowInvoker :

public sealed class SendEmailActivity : CodeActivity
{

[RequiredArgument]
public InArgument Subject { get; set; }

[RequiredArgument]
public InArgument Body { get; set; }

[RequiredArgument]
public InArgument To { get; set; }

[RequiredArgument]
public InArgument From { get; set; }

protected override void Execute(CodeActivityContext context)
{
// Obtain the runtime value of the Subject input argument
string text = context.GetValue(this.Subject);
}
}

Invokes SendEmailActivity :
public void TestSendEmailActivity()
{

WorkflowInvoker invoker = new WorkflowInvoker(
new SendEmailActivity
{
From = "Anupama_roy@testmail.com",
To = "Anupama_roy@testmail.com",
Subject = "Hello",
Body="How are you?"

});

invoker.Invoke();

}