1. Home
  2. Docs
  3. Llamachant Framework Modules
  4. Additional Modules
  5. Workflow Service Engine

Workflow Service Engine

The Workflow Engine Service is used to process workflow definitions created by our LlamachantFramework.Workflow module.  The engine allows you to embed the processing logic into any application. We suggest one of the following:

  • Windows Service
  • Azure Function (Timer Based)
  • Console Application that is invoked by Task Scheduler

Getting Started

  1. Install the LlamachantFramework.Workflow.Service from nuget into your solution
  2. Create an instance of your XAF Application
  3. Initialize the WorkflowService.Instance
  4. Configure your custom Email Service (Optional)
  5. Process the workflows

Sample Windows Service

				
					public partial class MyWorkflowService : ServiceBase
    {
        //You can utilize the built in WorkflowQueueController to handle timing for you
        WorkflowQueueController queue = new WorkflowQueueController();

        public MyWorkflowService()
        {
            InitializeComponent();

            Tracing.Initialize();
            MyWindowsFormsApplication app = new MyWindowsFormsApplication();
            app.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            app.SplashScreen = null;
            app.Setup();

            IObjectSpace space = app.ObjectSpaceProvider.CreateUpdatingObjectSpace(false);
            AuthenticationStandardLogonParameters p = (AuthenticationStandardLogonParameters)app.Security.LogonParameters;
            p.UserName = "Admin";

            app.GetSecurityStrategy().Logon(space);

            WorkflowService.Instance.Initialize(app, new FileSystemLogger(@"C:\Logs\"));
            //Set this to your custom IWorkflowEmailService if necessary
            //WorkflowService.Instance.EmailService = new DummyEmailService();
        }

        protected override void OnStart(string[] args)
        {
            //Set the number of seconds between checks for new workflows (60 seconds recommended)
            queue.SetInterval(60); 
            queue.Start();
        }

        protected override void OnStop()
        {
            queue.Stop();
        }
    }
				
			

Sample Console Application

				
					public class MyConsoleApp
    {
        public static void Main(string[] args)
        {
            Tracing.Initialize();
            LlamaFrameworkTestMyWindowsFormsApplication app = new MyWindowsFormsApplication();
            app.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            app.SplashScreen = null;
            app.Setup();

            IObjectSpace space = app.ObjectSpaceProvider.CreateUpdatingObjectSpace(false);
            AuthenticationStandardLogonParameters p = (AuthenticationStandardLogonParameters)app.Security.LogonParameters;
            p.UserName = "Admin";

            app.GetSecurityStrategy().Logon(space);

            WorkflowService.Instance.Initialize(app, new FileSystemLogger(@"C:\Logs\"));
            //Set this to your custom IWorkflowEmailService if necessary
            //WorkflowService.Instance.EmailService = new DummyEmailService();

            WorkflowService.Instance.RunWorkflow();
        }
    }
				
			

Managing Workflow Definition Dates

Handle the ProgressWorkflowDefinitionDate event in the WorkflowService.Instance to push the NextRunDate field out further. This is useful if you want to skip holidays or weekends.

				
					WorkflowService.Instance.ProgressWorkflowDefinitionDate += (s, args) =>
{
    while(e.NextRunDate.DayOfWeek == DayOfWeek.Saturday || e.NextRunDate.DayOfWeek== DayOfWeek.Sunday)
                e.NextRunDate = e.NextRunDate.AddDays(1);
};
				
			

Calculate if workflow processing is required

				
					WorkflowService.Instance.CalculateNeedsProcessing += (s, args) =>
{
    bool blankemail = e.ObjectToProcess is Client c && String.IsNullOrEmpty(c.EmailAddress) && e.WorkflowDefinition.Name == "My Workflow Definition";
    
    e.Process = !blankemail;
};
				
			
Was this article helpful to you? Yes 2 No 1

How can we help?