using
System;
using
System.Collections.Generic;
using
System.Threading;
using
System.Workflow.Runtime;
namespace
WFCostFactory
{
class
Program
{
static
WorkflowRuntime wfRuntime =
null
;
static
AutoResetEvent wHandle =
null
;
static
void
Main(
string
[] args)
{
using
(wfRuntime =
new
WorkflowRuntime())
{
wHandle =
new
AutoResetEvent(
false
);
#region Event Tanımlamaları
wfRuntime.Started +=
new
EventHandler<WorkflowRuntimeEventArgs>(wfRuntime_Started);
wfRuntime.ServicesExceptionNotHandled +=
new
EventHandler<ServicesExceptionNotHandledEventArgs>(wfRuntime_ServicesExceptionNotHandled);
wfRuntime.Stopped +=
new
EventHandler<WorkflowRuntimeEventArgs>(wfRuntime_Stopped);
wfRuntime.WorkflowAborted +=
new
EventHandler<WorkflowEventArgs>(wfRuntime_WorkflowAborted);
wfRuntime.WorkflowCreated +=
new
EventHandler<WorkflowEventArgs>(wfRuntime_WorkflowCreated);
wfRuntime.WorkflowIdled +=
new
EventHandler<WorkflowEventArgs>(wfRuntime_WorkflowIdled);
wfRuntime.WorkflowLoaded +=
new
EventHandler<WorkflowEventArgs>(wfRuntime_WorkflowLoaded);
wfRuntime.WorkflowPersisted +=
new
EventHandler<WorkflowEventArgs>(wfRuntime_WorkflowPersisted);
wfRuntime.WorkflowResumed +=
new
EventHandler<WorkflowEventArgs>(wfRuntime_WorkflowResumed);
wfRuntime.WorkflowStarted +=
new
EventHandler<WorkflowEventArgs>(wfRuntime_WorkflowStarted);
wfRuntime.WorkflowSuspended +=
new
EventHandler<WorkflowSuspendedEventArgs>(wfRuntime_WorkflowSuspended);
wfRuntime.WorkflowTerminated +=
new
EventHandler<WorkflowTerminatedEventArgs>(wfRuntime_WorkflowTerminated);
wfRuntime.WorkflowUnloaded +=
new
EventHandler<WorkflowEventArgs>(wfRuntime_WorkflowUnloaded);
wfRuntime.WorkflowCompleted+=
new
EventHandler<WorkflowCompletedEventArgs>(wfRuntime_WorkflowCompleted);
#endregion
WorkflowInstance instance = wfRuntime.CreateWorkflow(
typeof
(WFCostFactory.Costflow)
,
new
Dictionary<
string
,
object
>
{
{
"TotalDays"
,20}
,{
"WorkT"
,WorkType.Corporate}
}
);
instance.Start();
wHandle.WaitOne();
}
}
static
void
wfRuntime_WorkflowUnloaded(
object
sender, WorkflowEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, InstanceId : {2}"
, DateTime.Now,
"WorkflowUnloaded"
, e.WorkflowInstance.InstanceId.ToString());
}
static
void
wfRuntime_WorkflowTerminated(
object
sender, WorkflowTerminatedEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, InstanceId : {2} Exception Message : {3}"
, DateTime.Now,
"WorkflowTerminated"
, e.WorkflowInstance.InstanceId.ToString(), e.Exception.Message);
wHandle.Set();
}
static
void
wfRuntime_WorkflowSuspended(
object
sender, WorkflowSuspendedEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, InstanceId : {2}"
, DateTime.Now,
"WorkflowSuspended"
, e.WorkflowInstance.InstanceId.ToString());
}
static
void
wfRuntime_WorkflowStarted(
object
sender, WorkflowEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, InstanceId : {2}"
, DateTime.Now,
"WorkflowStarted"
, e.WorkflowInstance.InstanceId.ToString());
}
static
void
wfRuntime_WorkflowResumed(
object
sender, WorkflowEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, InstanceId : {2}"
, DateTime.Now,
"WorkflowResumed"
, e.WorkflowInstance.InstanceId.ToString());
}
static
void
wfRuntime_WorkflowPersisted(
object
sender, WorkflowEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, InstanceId : {2}"
, DateTime.Now,
"WorkflowPersisted"
, e.WorkflowInstance.InstanceId.ToString());
}
static
void
wfRuntime_WorkflowLoaded(
object
sender, WorkflowEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, InstanceId : {2}"
, DateTime.Now,
"WorkflowLoaded"
, e.WorkflowInstance.InstanceId.ToString());
}
static
void
wfRuntime_WorkflowIdled(
object
sender, WorkflowEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, InstanceId : {2}"
, DateTime.Now,
"WorkflowIdled"
, e.WorkflowInstance.InstanceId.ToString());
}
static
void
wfRuntime_WorkflowCreated(
object
sender, WorkflowEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, InstanceId : {2}"
, DateTime.Now,
"WorkflowCreated"
, e.WorkflowInstance.InstanceId.ToString());
}
static
void
wfRuntime_WorkflowCompleted(
object
sender, WorkflowCompletedEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, InstanceId : {2}"
, DateTime.Now,
"WorkflowCompleted"
, e.WorkflowInstance.InstanceId.ToString());
Console.WriteLine(
"Maliyet : {0}"
, e.OutputParameters[
"CostValue"
].ToString());
wHandle.Set();
}
static
void
wfRuntime_WorkflowAborted(
object
sender, WorkflowEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, InstanceId : {2}"
, DateTime.Now,
"WorkflowAborted"
, e.WorkflowInstance.InstanceId);
}
static
void
wfRuntime_Stopped(
object
sender, WorkflowRuntimeEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, IsStarted : {2}"
, DateTime.Now,
"WFRuntime_Stopped"
, e.IsStarted.ToString());
}
static
void
wfRuntime_ServicesExceptionNotHandled(
object
sender, ServicesExceptionNotHandledEventArgs e)
{
Console.WriteLine(
"{0} : InstanceId : {1} Event : {2}, Exception Message : {3}"
, DateTime.Now, e.WorkflowInstanceId.ToString(),
"WF Runtime_ServicesExceptionNotHandled"
,e.Exception.Message);
}
static
void
wfRuntime_Started(
object
sender, WorkflowRuntimeEventArgs e)
{
Console.WriteLine(
"{0} : Event : {1}, IsStarted : {2}"
, DateTime.Now,
"WFRuntime_Started"
, e.IsStarted.ToString());
}
}
}