Created
March 8, 2011 16:44
-
-
Save tkellogg/860519 to your computer and use it in GitHub Desktop.
Abstract workflow factory & example usage (SiteVisitWorkflow) for ObjectFlow
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using kpa.mko.dal; | |
using kpa.common.workflow; | |
using Rainbow.ObjectFlow.Stateful; | |
using kpa.common.container; | |
using kpa.common.interfaces; | |
namespace kpa.mko.bll.workflow | |
{ | |
public class SiteVisitWorkflow : WorkflowFactory<SiteVisit> | |
{ | |
/// <summary> | |
/// The key | |
/// </summary> | |
public const string WorkflowCode = "kpa.mko.SiteVisit.Approval"; | |
private static int? workflowFk; | |
public static int WorkflowFk | |
{ | |
get | |
{ | |
if (!workflowFk.HasValue) | |
workflowFk = Workflow.GetByName(WorkflowCode).WorkflowId; | |
return workflowFk.Value; | |
} | |
} | |
protected override Rainbow.ObjectFlow.Stateful.IStatefulWorkflow<SiteVisit> Define() | |
{ | |
return new StatefulWorkflow<SiteVisit>(WorkflowFk) | |
.Yield(WorkflowState.SiteVisit.Approvals.InProgress) | |
.Yield(WorkflowState.SiteVisit.Approvals.District) | |
.Yield(WorkflowState.SiteVisit.Approvals.Company) | |
.Yield(WorkflowState.SiteVisit.Approvals.Finance); | |
} | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Castle.DynamicProxy; | |
using Rainbow.ObjectFlow.Stateful; | |
namespace kpa.common.workflow | |
{ | |
/// <summary> | |
/// Describes a workflow process or sub-process that an object can go through. Actual | |
/// processes will descend from this class. | |
/// </summary> | |
public abstract class WorkflowFactory<T> : kpa.common.workflow.IWorkflowFactory<T> | |
where T : class, IStatefulObject | |
{ | |
private IStatefulWorkflow<T> workflow; | |
/// <summary> | |
/// This is where you define your workflow | |
/// </summary> | |
/// <remarks>We'll pass this a DP to record the steps that must happen and proxy | |
/// the steps to an actual WorkFlow object. This way we have a full ordering built | |
/// up in memory so we can easily jump steps and start part-way through."/></remarks> | |
protected abstract IStatefulWorkflow<T> Define(); | |
/// <summary> | |
/// For resuming a workflow that has already begun or starting a workflow on a new | |
/// object. | |
/// </summary> | |
/// <param name="initializer"></param> | |
/// <returns></returns> | |
public virtual T Process(T initializer) | |
{ | |
if (workflow == null) | |
workflow = Define(); | |
return workflow.Start(initializer); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment