Skip to content

Instantly share code, notes, and snippets.

@tkellogg
Created March 8, 2011 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkellogg/860519 to your computer and use it in GitHub Desktop.
Save tkellogg/860519 to your computer and use it in GitHub Desktop.
Abstract workflow factory & example usage (SiteVisitWorkflow) for ObjectFlow
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);
}
}
}
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