Click here to Skip to main content
12,635,139 members (25,451 online)
Click here to Skip to main content

Stats

23K views
366 downloads
23 bookmarked
Posted

Host and Workflow: Two Worlds to Communicate. Part V

, 4 Oct 2008 CPOL
Part V: Intercommunications with a Workflow instance using Correlation parameter
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
using CommunicationManager;

namespace SendAllEmail
{
    class Program
    {
        static WorkflowRuntime workflowRuntime = null;
        static MailCommunicationManager manager = null;
        static int count = 1;

        
        
        static void Main(string[] args)
        {
            workflowRuntime = new WorkflowRuntime();
            manager = new MailCommunicationManager(workflowRuntime); 
            manager.RegisterCommunicationService();
            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();
            };
            Dictionary<string, object> wfParam = new Dictionary<string, object>();
            wfParam.Add("Customer", "Herr Mustermann");
            WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(CorrelationDemo.MailFactory),wfParam);
            manager.MailCom.SendInfoToHost += new EventHandler<RequestMailEventArgs>(MailCom_SendInfoToHost);
            instance.Start();
            waitHandle.WaitOne();
            Console.ReadLine(); //wait to see the console
        }

        static void MailCom_SendInfoToHost(object sender, RequestMailEventArgs e)
        {
            const string customerMail = "customer@mailcustomer.com";
            const string providerMail = "provider@mailprovider.com";
           
            if (e.OrderNumber != null)
            {
                ThreadPool.QueueUserWorkItem(
                        delegate
                        
                        {
                            count++;
                            Thread.Sleep((3 -count) * 2000);
                            if (e.Typo == "CUSTOMER")
                            {
                                manager.RaiseSendEmailToWorkflow(e.InstanceId, "CUSTOMER", customerMail);
                                return;
                            }
                            if (e.Typo == "PROVIDER")
                            {

                                manager.RaiseSendEmailToWorkflow(e.InstanceId, "PROVIDER", providerMail);
                                return;
                            }
                        });

            
            }
         
        }

 


    }
}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

freedeveloper
Software Developer (Senior) Avalon Development
United States United States
Jose A. Garcia Guirado, Electronic Engineer, graduated in Havana/Cuba 1982, MCTS, MCSD.NET, MCAD.NET, MCSE. Worked in the Institute for Cybernetics and Mathematics of Academy of Science of Cuba for 8 years; since 1995 working as free software architect, developer and adviser, first in Argentina and from 2003 to 2010, in Germany as External consultant in DWS Luxembourg, AIXTRON AG and Shell Deutschland GmbH and from 2010 to 2012 in in Mexico in Twenty Century Fox, and Mexico Stock Exchange (BMV). Actually as freelancer in Florida, USA.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 4 Oct 2008
Article Copyright 2008 by freedeveloper
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid