NetBPM前进了一步,解决了上一个问题
山穷水尽疑无路,柳暗花明又一村。本来以为无法解决NetBPM的问题了,近乎绝望,但是今天中午突然冒出一个想法,否是我没有配置好NetBPM的运行环境呢?因此下午把可以运行的NetBPM的bin目录下的所有文件复制到我的测试项目目录下,同时复制log4net.config到项目目录。然后再跑测试项目,竟然成功了!通过删除文件,发现log4net.config是不要的,当然含Test的dll也是不需要的,其他的还不能完全确定,但MySql.Data.dll和Castle的许多dll是需要的。
我的测试项目目前结构是:
PageLoad事件中调用SetContainer函数初始化NetBPM,Unload事件中调用DisposeContainer函数清场。
页面上放置一个按钮,点击时开始一个新的Holiday request过程,并显示刚刚启动的流程ID。
需要注意的是要开始新的流程前要调用testUtil.LoginUser(actorId);进行登录,否则无法开始新的流程。
接下来要进行更深入的研究了。
最后贴出代码:
WebForm1.aspx
我的测试项目目前结构是:
PageLoad事件中调用SetContainer函数初始化NetBPM,Unload事件中调用DisposeContainer函数清场。
页面上放置一个按钮,点击时开始一个新的Holiday request过程,并显示刚刚启动的流程ID。
需要注意的是要开始新的流程前要调用testUtil.LoginUser(actorId);进行登录,否则无法开始新的流程。
接下来要进行更深入的研究了。
最后贴出代码:
WebForm1.aspx
1<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="TestNBPM.WebForm1" %>
2<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3<HTML>
4 <HEAD>
5 <title>WebForm1</title>
6 <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
7 <meta content="C#" name="CODE_LANGUAGE">
8 <meta content="JavaScript" name="vs_defaultClientScript">
9 <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
10 </HEAD>
11 <body MS_POSITIONING="GridLayout">
12 <form id="Form1" method="post" runat="server">
13 <asp:button id="btStartRequest" style="Z-INDEX: 101; LEFT: 72px; POSITION: absolute; TOP: 8px"
14 runat="server" Text="开始申请"></asp:button><asp:label id="Label1" style="Z-INDEX: 102; LEFT: 160px; POSITION: absolute; TOP: 8px" runat="server">流ID:</asp:label></form>
15 </body>
16</HTML>
17
WebForm1.aspx.cs2<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3<HTML>
4 <HEAD>
5 <title>WebForm1</title>
6 <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
7 <meta content="C#" name="CODE_LANGUAGE">
8 <meta content="JavaScript" name="vs_defaultClientScript">
9 <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
10 </HEAD>
11 <body MS_POSITIONING="GridLayout">
12 <form id="Form1" method="post" runat="server">
13 <asp:button id="btStartRequest" style="Z-INDEX: 101; LEFT: 72px; POSITION: absolute; TOP: 8px"
14 runat="server" Text="开始申请"></asp:button><asp:label id="Label1" style="Z-INDEX: 102; LEFT: 160px; POSITION: absolute; TOP: 8px" runat="server">流ID:</asp:label></form>
15 </body>
16</HTML>
17
1using System;
2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Web;
7using System.Web.SessionState;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11using Castle.Windsor.Configuration.Interpreters;
12using NetBpm;
13using NetBpm.Workflow.Definition;
14using NetBpm.Workflow.Definition.EComp;
15using NetBpm.Workflow.Definition.Attr;
16using NetBpm.Workflow.Execution;
17using NetBpm.Workflow.Execution.EComp;
18using NetBpm.Util.Client;
19using NetBpm.Workflow.Organisation.EComp;
20using NetBpm.Workflow.Scheduler.EComp;
21
22namespace TestNBPM
23{
24 /// <summary>
25 /// WebForm1 的摘要说明。
26 /// </summary>
27 public class WebForm1 : System.Web.UI.Page
28 {
29 protected System.Web.UI.WebControls.Button btStartRequest;
30 protected System.Web.UI.WebControls.Label Label1;
31 protected internal ServiceLocator servicelocator = null;
32 protected internal IDefinitionSessionLocal definitionComponent = null;
33 protected internal IExecutionSessionLocal executionComponent = null;
34 protected internal ISchedulerSessionLocal schedulerComponent = null;
35 protected internal IOrganisationSessionLocal organisationComponent = null;
36 private NetBpmContainer _container = null;
37 protected internal Utilities testUtil = null;
38
39 public void SetContainer()
40 {
41 //configure the container
42 _container = new NetBpmContainer(new XmlInterpreter("app_config.xml"));
43 testUtil = new Utilities();
44 servicelocator = ServiceLocator.Instance;
45 definitionComponent = servicelocator.GetService(typeof (IDefinitionSessionLocal)) as IDefinitionSessionLocal;
46 executionComponent = servicelocator.GetService(typeof (IExecutionSessionLocal)) as IExecutionSessionLocal;
47 schedulerComponent = servicelocator.GetService(typeof (ISchedulerSessionLocal)) as ISchedulerSessionLocal;
48 organisationComponent = servicelocator.GetService(typeof (IOrganisationSessionLocal)) as IOrganisationSessionLocal;
49 testUtil.LoginUser("ae");
50 }
51
52 public void DisposeContainer()
53 {
54 servicelocator.Release(definitionComponent);
55 definitionComponent=null;
56 servicelocator.Release(executionComponent);
57 executionComponent=null;
58 servicelocator.Release(schedulerComponent);
59 schedulerComponent=null;
60 servicelocator.Release(organisationComponent);
61 organisationComponent=null;
62
63 _container.Dispose();
64 _container = null;
65 }
66 private IProcessInstance StartNewHolidayRequest(String actorId, IDictionary attributeValues)
67 {
68 IProcessInstance processInstance = null;
69 testUtil.LoginUser(actorId);
70
71 try
72 {
73 // loginUtil.login( actorId, actorId );
74 // start the process instance
75 IProcessDefinition holidayRequest = definitionComponent.GetProcessDefinition("Holiday request");
76
77 // perform the first activity
78 processInstance = executionComponent.StartProcessInstance(holidayRequest.Id, attributeValues);
79 //Assert.IsNotNull(processInstance);
80 }
81 catch (ExecutionException e)
82 {
83 //Assert.Fail("ExcecutionException while starting a new holiday request: " + e.Message);
84 }
85 finally
86 {
87 // loginUtil.logout();
88 }
89
90 return processInstance;
91 }
92 private void Page_Load(object sender, System.EventArgs e)
93 {
94 SetContainer();
95 }
96 private void WebForm1_Unload(object sender, System.EventArgs e)
97 {
98 DisposeContainer();
99 }
100 Web 窗体设计器生成的代码
122
123 private void btStartRequest_Click(object sender, System.EventArgs e)
124 {
125 IDictionary attributeValues = new Hashtable();
126 attributeValues["start date"] = DateTime.Now;
127 attributeValues["end date"] = new DateTime((DateTime.Now.Ticks - 621355968000000000)/10000 + 9845344);
128 attributeValues["comment"] = "going fishing";
129
130 IProcessInstance processInstance = StartNewHolidayRequest("ae", attributeValues);
131 Int64 flowId = processInstance.RootFlow.Id;
132 Label1.Text = "流ID:" + flowId.ToString();
133 }
134
135 }
136}
137
还有一个Utitilities.cs2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Web;
7using System.Web.SessionState;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11using Castle.Windsor.Configuration.Interpreters;
12using NetBpm;
13using NetBpm.Workflow.Definition;
14using NetBpm.Workflow.Definition.EComp;
15using NetBpm.Workflow.Definition.Attr;
16using NetBpm.Workflow.Execution;
17using NetBpm.Workflow.Execution.EComp;
18using NetBpm.Util.Client;
19using NetBpm.Workflow.Organisation.EComp;
20using NetBpm.Workflow.Scheduler.EComp;
21
22namespace TestNBPM
23{
24 /// <summary>
25 /// WebForm1 的摘要说明。
26 /// </summary>
27 public class WebForm1 : System.Web.UI.Page
28 {
29 protected System.Web.UI.WebControls.Button btStartRequest;
30 protected System.Web.UI.WebControls.Label Label1;
31 protected internal ServiceLocator servicelocator = null;
32 protected internal IDefinitionSessionLocal definitionComponent = null;
33 protected internal IExecutionSessionLocal executionComponent = null;
34 protected internal ISchedulerSessionLocal schedulerComponent = null;
35 protected internal IOrganisationSessionLocal organisationComponent = null;
36 private NetBpmContainer _container = null;
37 protected internal Utilities testUtil = null;
38
39 public void SetContainer()
40 {
41 //configure the container
42 _container = new NetBpmContainer(new XmlInterpreter("app_config.xml"));
43 testUtil = new Utilities();
44 servicelocator = ServiceLocator.Instance;
45 definitionComponent = servicelocator.GetService(typeof (IDefinitionSessionLocal)) as IDefinitionSessionLocal;
46 executionComponent = servicelocator.GetService(typeof (IExecutionSessionLocal)) as IExecutionSessionLocal;
47 schedulerComponent = servicelocator.GetService(typeof (ISchedulerSessionLocal)) as ISchedulerSessionLocal;
48 organisationComponent = servicelocator.GetService(typeof (IOrganisationSessionLocal)) as IOrganisationSessionLocal;
49 testUtil.LoginUser("ae");
50 }
51
52 public void DisposeContainer()
53 {
54 servicelocator.Release(definitionComponent);
55 definitionComponent=null;
56 servicelocator.Release(executionComponent);
57 executionComponent=null;
58 servicelocator.Release(schedulerComponent);
59 schedulerComponent=null;
60 servicelocator.Release(organisationComponent);
61 organisationComponent=null;
62
63 _container.Dispose();
64 _container = null;
65 }
66 private IProcessInstance StartNewHolidayRequest(String actorId, IDictionary attributeValues)
67 {
68 IProcessInstance processInstance = null;
69 testUtil.LoginUser(actorId);
70
71 try
72 {
73 // loginUtil.login( actorId, actorId );
74 // start the process instance
75 IProcessDefinition holidayRequest = definitionComponent.GetProcessDefinition("Holiday request");
76
77 // perform the first activity
78 processInstance = executionComponent.StartProcessInstance(holidayRequest.Id, attributeValues);
79 //Assert.IsNotNull(processInstance);
80 }
81 catch (ExecutionException e)
82 {
83 //Assert.Fail("ExcecutionException while starting a new holiday request: " + e.Message);
84 }
85 finally
86 {
87 // loginUtil.logout();
88 }
89
90 return processInstance;
91 }
92 private void Page_Load(object sender, System.EventArgs e)
93 {
94 SetContainer();
95 }
96 private void WebForm1_Unload(object sender, System.EventArgs e)
97 {
98 DisposeContainer();
99 }
100 Web 窗体设计器生成的代码
122
123 private void btStartRequest_Click(object sender, System.EventArgs e)
124 {
125 IDictionary attributeValues = new Hashtable();
126 attributeValues["start date"] = DateTime.Now;
127 attributeValues["end date"] = new DateTime((DateTime.Now.Ticks - 621355968000000000)/10000 + 9845344);
128 attributeValues["comment"] = "going fishing";
129
130 IProcessInstance processInstance = StartNewHolidayRequest("ae", attributeValues);
131 Int64 flowId = processInstance.RootFlow.Id;
132 Label1.Text = "流ID:" + flowId.ToString();
133 }
134
135 }
136}
137
1using System;
2using System.Collections;
3using System.Threading;
4using NetBpm.Util.Client;
5using NetBpm.Workflow.Execution;
6using NetBpm.Workflow.Execution.EComp;
7using NetBpm.Workflow.Organisation;
8
9namespace TestNBPM
10{
11 /// <summary>
12 /// Utilities 的摘要说明。
13 /// </summary>
14 public class Utilities
15 {
16 public IList PerformActivity(String actorId, Int64 flowId, int levelsUp, IDictionary attributeValues, IExecutionSessionLocal executionComponent)
17 {
18 IList assignedFlows = null;
19 LoginUser(actorId);
20 IFlow flowInList = GetFlow(levelsUp, flowId, executionComponent);
21 assignedFlows = executionComponent.PerformActivity(flowInList.Id, attributeValues);
22 return assignedFlows;
23 }
24
25 /// <summary> finds a flow upon which the current authenticated user has to act.
26 /// It searches the flow in the current authenticated user's tasklist for which the levelsUp-parent has rootFlowId.
27 /// @throws FinderException if the flow could not be found
28 /// </summary>
29 public IFlow GetFlow(int levelsUp, Int64 rootFlowId, IExecutionSessionLocal executionComponent)
30 {
31 IFlow theOne = null;
32
33 IList flows = executionComponent.GetTaskList(new Relations(new String[] {"processInstance.processDefinition", "node", "parent"}));
34 IEnumerator iter = flows.GetEnumerator();
35 while (iter.MoveNext())
36 {
37 IFlow flow = (IFlow) iter.Current;
38 IFlow rootFlow = flow;
39
40 for (int i = 0; i < levelsUp; i++)
41 {
42 rootFlow = rootFlow.Parent;
43 }
44
45 if (rootFlow != null)
46 {
47 if (rootFlow.Id == rootFlowId)
48 {
49 theOne = flow;
50 }
51 }
52 }
53
54 if (theOne == null)
55 {
56 throw new SystemException("No flow in the tasklist could be found that has flow " +
57 rootFlowId + " as " + levelsUp + "-levels-up-parent : " + flows);
58 }
59
60 return theOne;
61 }
62
63 public void DelegateFlow(Int64 flowId, int levelsUp, String actorId, String delegateActorId, IExecutionSessionLocal executionComponent)
64 {
65 LoginUser(actorId);
66 IFlow flowInList = GetFlow(levelsUp, flowId, executionComponent);
67
68 // delegate the activity
69 executionComponent.DelegateActivity(flowInList.Id, delegateActorId);
70 }
71
72 public void CancelFlow(String actorId, Int64 flowId, int levelsUp, IExecutionSessionLocal executionComponent)
73 {
74 LoginUser(actorId);
75 IFlow flowInList = GetFlow(levelsUp, flowId, executionComponent);
76 executionComponent.CancelFlow(flowInList.Id);
77 }
78
79 public void CancelInstance(String actorId, Int64 processInstanceId, IExecutionSessionLocal executionComponent)
80 {
81 LoginUser(actorId);
82 // perform the cancel instance operaction
83 executionComponent.CancelProcessInstance(processInstanceId);
84 }
85
86 public void LoginUser(String actorId)
87 {
88 Thread.CurrentPrincipal = new PrincipalUserAdapter(actorId);
89 }
90
91 }
92}
93
2using System.Collections;
3using System.Threading;
4using NetBpm.Util.Client;
5using NetBpm.Workflow.Execution;
6using NetBpm.Workflow.Execution.EComp;
7using NetBpm.Workflow.Organisation;
8
9namespace TestNBPM
10{
11 /// <summary>
12 /// Utilities 的摘要说明。
13 /// </summary>
14 public class Utilities
15 {
16 public IList PerformActivity(String actorId, Int64 flowId, int levelsUp, IDictionary attributeValues, IExecutionSessionLocal executionComponent)
17 {
18 IList assignedFlows = null;
19 LoginUser(actorId);
20 IFlow flowInList = GetFlow(levelsUp, flowId, executionComponent);
21 assignedFlows = executionComponent.PerformActivity(flowInList.Id, attributeValues);
22 return assignedFlows;
23 }
24
25 /// <summary> finds a flow upon which the current authenticated user has to act.
26 /// It searches the flow in the current authenticated user's tasklist for which the levelsUp-parent has rootFlowId.
27 /// @throws FinderException if the flow could not be found
28 /// </summary>
29 public IFlow GetFlow(int levelsUp, Int64 rootFlowId, IExecutionSessionLocal executionComponent)
30 {
31 IFlow theOne = null;
32
33 IList flows = executionComponent.GetTaskList(new Relations(new String[] {"processInstance.processDefinition", "node", "parent"}));
34 IEnumerator iter = flows.GetEnumerator();
35 while (iter.MoveNext())
36 {
37 IFlow flow = (IFlow) iter.Current;
38 IFlow rootFlow = flow;
39
40 for (int i = 0; i < levelsUp; i++)
41 {
42 rootFlow = rootFlow.Parent;
43 }
44
45 if (rootFlow != null)
46 {
47 if (rootFlow.Id == rootFlowId)
48 {
49 theOne = flow;
50 }
51 }
52 }
53
54 if (theOne == null)
55 {
56 throw new SystemException("No flow in the tasklist could be found that has flow " +
57 rootFlowId + " as " + levelsUp + "-levels-up-parent : " + flows);
58 }
59
60 return theOne;
61 }
62
63 public void DelegateFlow(Int64 flowId, int levelsUp, String actorId, String delegateActorId, IExecutionSessionLocal executionComponent)
64 {
65 LoginUser(actorId);
66 IFlow flowInList = GetFlow(levelsUp, flowId, executionComponent);
67
68 // delegate the activity
69 executionComponent.DelegateActivity(flowInList.Id, delegateActorId);
70 }
71
72 public void CancelFlow(String actorId, Int64 flowId, int levelsUp, IExecutionSessionLocal executionComponent)
73 {
74 LoginUser(actorId);
75 IFlow flowInList = GetFlow(levelsUp, flowId, executionComponent);
76 executionComponent.CancelFlow(flowInList.Id);
77 }
78
79 public void CancelInstance(String actorId, Int64 processInstanceId, IExecutionSessionLocal executionComponent)
80 {
81 LoginUser(actorId);
82 // perform the cancel instance operaction
83 executionComponent.CancelProcessInstance(processInstanceId);
84 }
85
86 public void LoginUser(String actorId)
87 {
88 Thread.CurrentPrincipal = new PrincipalUserAdapter(actorId);
89 }
90
91 }
92}
93