Created
December 24, 2012 07:05
-
-
Save JerryBian/4368166 to your computer and use it in GitHub Desktop.
a sample for WF.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
WorkflowInvoker.Invoke(CreateWorkflow()); | |
Console.ReadKey(); | |
} | |
private static Activity CreateWorkflow() | |
{ | |
Variable<int> numberBells = new Variable<int>() | |
{ | |
Name = "numberBells", | |
Default = DateTime.Now.Hour | |
}; | |
Variable<int> counter = new Variable<int>() | |
{ | |
Name = "counter", | |
Default = 1 | |
}; | |
return new Sequence() | |
{ | |
DisplayName = "Main Sequence", | |
Variables = { numberBells, counter }, | |
Activities = | |
{ | |
new WriteLine(){ | |
DisplayName="Hello", | |
Text="Hello World." | |
}, | |
new If(){ | |
DisplayName="Adjust for PM", | |
Condition=ExpressionServices.Convert<bool>(env=>numberBells.Get(env)>12), | |
Then=new Assign<int>(){ | |
DisplayName="Adjust Bells", | |
To=new OutArgument<int>(numberBells), | |
Value=new InArgument<int>(env=>numberBells.Get(env)-12) | |
} | |
}, | |
new While(){ | |
DisplayName="Sound Bells", | |
Condition=ExpressionServices.Convert<bool>(env=>counter.Get(env)<=numberBells.Get(env)), | |
Body=new Sequence(){ | |
DisplayName="Sound Bell", | |
Activities={ | |
new WriteLine(){ | |
Text=new InArgument<string>(env=>counter.Get(env | |
).ToString()) | |
}, | |
new Assign<int>(){ | |
DisplayName="Increment Counter", | |
To=new OutArgument<int>(counter), | |
Value=new InArgument<int>(env=>counter.Get(env)+1) | |
}, | |
new Delay(){ | |
Duration=TimeSpan.FromSeconds(1) | |
} | |
} | |
} | |
}, | |
new WriteLine(){ | |
DisplayName="Display Time", | |
Text="The time is "+DateTime.Now.ToString() | |
}, | |
new If(){ | |
DisplayName="Greeting", | |
Condition=ExpressionServices.Convert<bool>(env=>DateTime.Now.Hour>=18), | |
Then=new WriteLine(){Text="Good Evening."}, | |
Else=new WriteLine(){Text="Good Day."} | |
} | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
also, you should involve following three namespaces:
using System.Activities;
using System.Activities.Expressions;
using System.Activities.Statements;