Global in workflow

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Workflow.Activities;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
using System.Collections.Specialized;
namespace WebService1
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

            System.Workflow.Runtime.WorkflowRuntime workflowRuntime = new System.Workflow.Runtime.WorkflowRuntime("WorkflowRuntime");

           // System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService sqlPersistenceService = new System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService("Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI");
           // workflowRuntime.AddService(sqlPersistenceService);

            workflowRuntime.WorkflowAborted += new EventHandler<System.Workflow.Runtime.WorkflowEventArgs>(workflowRuntime_WorkflowAborted);
            workflowRuntime.WorkflowIdled += new EventHandler<System.Workflow.Runtime.WorkflowEventArgs>(workflowRuntime_WorkflowIdled);
            workflowRuntime.WorkflowTerminated += new EventHandler<System.Workflow.Runtime.WorkflowTerminatedEventArgs>(workflowRuntime_WorkflowTerminated);
            workflowRuntime.WorkflowUnloaded += new EventHandler<System.Workflow.Runtime.WorkflowEventArgs>(workflowRuntime_WorkflowUnloaded);
            workflowRuntime.WorkflowSuspended += new EventHandler<System.Workflow.Runtime.WorkflowSuspendedEventArgs>(workflowRuntime_WorkflowSuspended);
            workflowRuntime.WorkflowCompleted += new EventHandler<System.Workflow.Runtime.WorkflowCompletedEventArgs>(workflowRuntime_WorkflowCompleted);

            NameValueCollection parms = new NameValueCollection();
            parms.Add("UnloadOnIdle", "true");
            parms.Add("ConnectionString", ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
            workflowRuntime.AddService(new SqlWorkflowPersistenceService(parms));
            //string conn = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
            //workflowRuntime.AddService(new SqlWorkflowPersistenceService(conn));

            Application["WorkflowRuntime"] = workflowRuntime;

            workflowRuntime.StartRuntime();
        }

        void workflowRuntime_WorkflowCompleted(object sender, System.Workflow.Runtime.WorkflowCompletedEventArgs e)
        {
            Console.WriteLine("完成");
        }

        void workflowRuntime_WorkflowSuspended(object sender, System.Workflow.Runtime.WorkflowSuspendedEventArgs e)
        {
            Console.WriteLine("挂起");
        }

        void workflowRuntime_WorkflowUnloaded(object sender, System.Workflow.Runtime.WorkflowEventArgs e)
        {
            Console.WriteLine("卸载");
        }

        void workflowRuntime_WorkflowTerminated(object sender, System.Workflow.Runtime.WorkflowTerminatedEventArgs e)
        {
            Console.WriteLine("中止");
        }

        void workflowRuntime_WorkflowIdled(object sender, System.Workflow.Runtime.WorkflowEventArgs e)
        {
            Console.WriteLine("空闲");
        }

        void workflowRuntime_WorkflowAborted(object sender, System.Workflow.Runtime.WorkflowEventArgs e)
        {
            Console.WriteLine("意外");
        }

        protected void Application_End(object sender, EventArgs e)
        {

            System.Workflow.Runtime.WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as System.Workflow.Runtime.WorkflowRuntime;
            workflowRuntime.StopRuntime();
        }
    }
}

posted @ 2010-01-27 10:48  Ken-Cai  阅读(184)  评论(0编辑  收藏  举报