Click here to Skip to main content
Licence 
First Posted 19 Dec 2006
Views 26,519
Bookmarked 11 times

ASP.NET WorkFlow with parameters

By | 19 Dec 2006 | Article
Use workflows with parameters in asp.net

Sample Image - AspNet_WorkFlow.jpg

Introduction

Simple Web Site ASP.NET using Microsoft Worflow Fundation. Parameters - Web Page - WorfFlow.

Using the code

Definicion Runtime in Global.asax


void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup

        System.Workflow.Runtime.WorkflowRuntime workflowRuntime = new System.Workflow.Runtime.WorkflowRuntime();
        System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService manualService = new System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService();



        workflowRuntime.AddService(manualService);

        workflowRuntime.StartRuntime();

        Application["WorkflowRuntime"] = workflowRuntime;

    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
        System.Workflow.Runtime.WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as System.Workflow.Runtime.WorkflowRuntime;
        workflowRuntime.StopRuntime();
    }

Parameters

        //Datos del Global.asax
        wr = Application["WorkflowRuntime"] as WorkflowRuntime;
        manualScheduler = wr.GetService(typeof(ManualWorkflowSchedulerService)) as ManualWorkflowSchedulerService;

        //parametros al workflow
        Dictionary<string, object> parameters = new Dictionary<string, object>();
        parameters.Add("Valor", Int32.Parse(this.valor.Text));


        //Eventos del WorkFlow
        wr.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(wr_WorkflowCompleted);
        wr.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(wr_WorkflowTerminated);

        Type type = typeof(WorkflowLibrary1.Workflow1);
        WorkflowInstance wi = wr.CreateWorkflow(type, parameters);
        wi.Start();

        //Ejecutar workflow
        manualScheduler.RunWorkflow(wi.InstanceId);

WorkFlow

namespace WorkflowLibrary1
{
    public sealed partial class Workflow1: SequentialWorkflowActivity
    {
        public Workflow1()
        {
            InitializeComponent();
        }

      private string m_Resultado="Rechazado";
      private int m_Valor;
      private DateTime m_FechaHora = DateTime.Now;

       public string Resultado
       {
           get { return m_Resultado; }
       }

       public int Valor
       {
           get { return m_Valor; }
           set { m_Valor = value; }
       }

       public DateTime FechaHora
       {
           get { return m_FechaHora; }
       }



        private void ExecuteCodeActivity1(object sender, EventArgs e)
        {
            if (m_Valor > 100)
            {
                m_Resultado = "Aceptado";
            }
        }


    }

}

WorkFlow

Simple use worflow in ASP.net. Using Parameters

History

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

matiaszumbo



Argentina Argentina

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalthanks for your sample Pinmemberxuexiaohu20:23 20 Dec '09  
GeneralMy vote of 1 Pinmemberleefwu17:52 11 Aug '09  
GeneralMy vote of 2 PinmemberEgorRubansky0:51 12 Dec '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 19 Dec 2006
Article Copyright 2006 by matiaszumbo
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid