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.cs
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Web;
7
using System.Web.SessionState;
8
using System.Web.UI;
9
using System.Web.UI.WebControls;
10
using System.Web.UI.HtmlControls;
11
using Castle.Windsor.Configuration.Interpreters;
12
using NetBpm;
13
using NetBpm.Workflow.Definition;
14
using NetBpm.Workflow.Definition.EComp;
15
using NetBpm.Workflow.Definition.Attr;
16
using NetBpm.Workflow.Execution;
17
using NetBpm.Workflow.Execution.EComp;
18
using NetBpm.Util.Client;
19
using NetBpm.Workflow.Organisation.EComp;
20
using NetBpm.Workflow.Scheduler.EComp;
21
22
namespace 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.cs
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

1
using System;
2
using System.Collections;
3
using System.Threading;
4
using NetBpm.Util.Client;
5
using NetBpm.Workflow.Execution;
6
using NetBpm.Workflow.Execution.EComp;
7
using NetBpm.Workflow.Organisation;
8
9
namespace 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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理