|
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
using System.Workflow.Activities;
#endregion
namespace FirstWFStateMachine
{
class Program
{
static void Main(string[] args)
{
using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
Console.WriteLine(e.Exception.Message);
waitHandle.Set();
};
ExternalDataExchangeService ExDateExchService = new ExternalDataExchangeService();
workflowRuntime.AddService(ExDateExchService);
POService poServiceInstance = new POService();
ExDateExchService.AddService(poServiceInstance);
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(FirstWFStateMachine.POWorkflow));
instance.Start();
PO newPO = new PO();
Console.WriteLine("Please Enter Item Code to be sent Purchase Order of");
string ItemCode = Console.ReadLine();
Console.WriteLine("Please Enter Due Delivery Date of Purchase Order of");
DateTime DueDeliveryDate = Convert.ToDateTime(Console.ReadLine());
newPO.ItemCode = ItemCode;
newPO.PODueDeliveryDate = DueDeliveryDate;
poServiceInstance.CreatePO(instance.InstanceId, newPO);
Console.WriteLine("New PO created for item: " + newPO.ItemCode + " with Due Delivery Date: " + newPO.PODueDeliveryDate.Date);
Console.WriteLine("Do you want to approve Purchase Order");
while ( (Console.ReadLine().ToLower()) != "y")
{
Console.WriteLine("Current status of Purchase Order : Created");
Console.WriteLine("Waiting to be Authorised");
DumpStateMachine(workflowRuntime, instance.InstanceId);
Console.WriteLine("Do you want to approve Purchase Order");
}
poServiceInstance.AuthorisePO(instance.InstanceId, newPO);
Console.WriteLine("Do you want to send Purchase Order");
while ((Console.ReadLine().ToLower()) != "y")
{
Console.WriteLine("Current status of Purchase Order : Created");
Console.WriteLine("Waiting to be Sent");
DumpStateMachine(workflowRuntime, instance.InstanceId);
Console.WriteLine("Do you want to send Purchase Order");
}
poServiceInstance.SendPO(instance.InstanceId, newPO);
DumpStateMachine(workflowRuntime, instance.InstanceId);
System.Console.ReadKey();
waitHandle.WaitOne();
}
}
private static void DumpStateMachine(WorkflowRuntime runtime, Guid instanceID)
{
StateMachineWorkflowInstance instance =
new StateMachineWorkflowInstance(runtime, instanceID);
Console.WriteLine("Workflow ID: {0}", instanceID);
Console.WriteLine("Current State: {0}",
instance.CurrentStateName);
Console.WriteLine("Possible Transitions: {0}",
instance.PossibleStateTransitions.Count);
foreach (string name in instance.PossibleStateTransitions)
{
Console.WriteLine("\t{0}", name);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.