[翻译]
matiaszumbo.著ASP.NET WorkFlow with parameters
[代码使用]
在Global.asax定义:
void Application_Start(object sender, EventArgs e)
{
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)
{
System.Workflow.Runtime.WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as System.Workflow.Runtime.WorkflowRuntime;
workflowRuntime.StopRuntime();
数
wr = Application["WorkflowRuntime"] as WorkflowRuntime;
manualScheduler = wr.GetService(typeof(ManualWorkflowSchedulerService)) as ManualWorkflowSchedulerService;
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("Valor", Int32.Parse(this.valor.Text));
wr.WorkflowCompleted += new EventHandler(wr_WorkflowCompleted);
wr.WorkflowTerminated += new EventHandler(wr_WorkflowTerminated);
Type type = typeof(WorkflowLibrary1.Workflow1);
WorkflowInstance wi = wr.CreateWorkflow(type, parameters);
wi.Start();
manualScheduler.RunWorkflow(wi.InstanceId);
工作流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";
}
}
}
}
CIO之家 www.ciozj.com 公众号:imciow