Knowledge Base
 

  

 

 

Knowledge Base
Previous  BackToCategory  Next  6 of 47
Read values from an XML configuration file and populate the process variables in a process

 

Summary
Requirements
Create a Visual Studio .Net project
Create a class
Add references
Add code to the class
Add custom node to the process
Create a Process
Inserting a Process Variable into the Process
Inserting a Read Configuration node into the Process
Connect the nodes
Save the Process
Run the Process

Summary

This article demonstrates how to read values from an XML configuration file and populate the process variables in a process.


Requirements

  1. Enterprise Enabler version 5.x
  2. Process Designer
  3. Microsoft Visual Studio .Net

Create a Visual Studio .Net project

Open Microsoft Development Environment and then select File » New » Project. This brings up a pop up window. Under Project Types select Visual Basic Projects and under Templates select Empty Project. Enter the Name of the project asReadConfiguration.




Create a class

Go to the Solution Explorer and right click on the project. Then select Add » Add Class. Rename the class asReadConfiguration.vb.

Add references

In the Solution Explorer, right click on References, select Add Reference, and add the following references:SBT.EE.Process.Engine, System, System.Drawing,

and System.XML.




Add code to the class

In the ReadConfiguration, add the following code:

  view plain | print
1 'References 
2 Imports System.ComponentModel 
3 Imports SBT.EE.Process 
4 Imports System.Collections 
5 Imports System.Xml 
6 Imports SBT.EE.Misc_Utils 
7 Public Class ReadConfiguration 
8     Inherits ProcessNode 
9 #Region "Instance Variables" 
10     ' Track whether Dispose has been called. 
11     Private _disposed As Boolean = False 
12     ' variable to hold the process variables 
13     Private _processVariables As New Hashtable 
14 #End Region 
15 #Region "Constructors" 
16     Sub New(ByVal processVariables As Hashtable) 
17         MyBase.New(processVariables) 
18         Me._processVariables = processVariables 
19         Me.Name = "Read Configuration" 
20     End Sub 
21     Sub New(ByVal xmlDef As Xml.XmlNode, ByVal processVariables As Hashtable) 
22         MyBase.New(xmlDef, processVariables) 
23         Me._processVariables = processVariables 
24     End Sub 
25 #End Region 
26 #Region "Properties" 
27     <DescriptionAttribute("Indicates the Name of the Process Node"), ReadOnlyAttribute(True)> _ 
28     Public Overrides Property Name() As String 
29         Get 
30             Return "Read Configuration" 
31         End Get 
32         Set(ByVal Value As String
33             Me("name") = "Read Configuration" 
34         End Set 
35     End Property 
36     Public Overrides ReadOnly Property ClassId() As System.Guid 
37         Get 
38             Return New Guid("dbe20c76-3a8f-44b6-9b19-a6880ca8ea9e"
39         End Get 
40     End Property 
41     Public Overrides ReadOnly Property Icon() As System.Drawing.Icon 
42         Get 
43             Return New System.Drawing.Icon(Me.GetType"ConfigurationSettings.ico"
44         End Get 
45     End Property 
46     Public Overrides ReadOnly Property LocalVariables() As SBT.EE.Process.LocalVariable() 
47         Get 
48             Dim _localVariables(0) As LocalVariable 
49             _localVariables(0) = New LocalVariable("FilePath", TypeCode.String, VariableDirection.Input) 
50             Return _localVariables 
51         End Get 
52     End Property 
53     Public Overrides ReadOnly Property NodeType() As SBT.EE.Process.ProcessNodeType 
54         Get 
55             Return ProcessNodeType.ACTION 
56         End Get 
57     End Property 
58 #End Region 
59 #Region "Helper Methods" 
60     ' subroutine to validate the definition definition 
61     Public Overrides Sub ValidateParams() 
62         ' variable to hold the validation exceptions 
63         Dim _validationExceptions As New ValidationExceptions 
64         ' first validate the base class  
65         Try 
66             MyBase.ValidateParams() 
67         Catch vex As ValidationExceptions 
68             If vex.Count > 0 Then 
69                 Dim _enumerator As IEnumerator = vex.GetEnumerator 
70                 While _enumerator.MoveNext 
71                     _validationExceptions.Add(CType(_enumerator.Current, ValidationData)) 
72                 End While 
73             End If 
74         Catch ex As Exception 
75             _validationExceptions.Add(Me.ID, Me.Name, ProcessItemType.ProcessNode, ex.Message) 
76         End Try 
77         ' check to see is there are any validation exceptions. if yes then throw them 
78         If _validationExceptions.Count > 0 Then 
79             Throw _validationExceptions 
80         End If 
81     End Sub 
82 #End Region 
83 #Region "Runtime" 
84     Public Overrides Sub Execute() 
85         Dim xDoc As New XmlDocument 
86         Dim xNode As XmlNode 
87         Dim str As String = "" 
88         Dim tstr As String() 
89         Dim var As Hashtable 
90         var = MyBase.ProcessVariables 'Me.LocalVariables 
91         Dim info As New System.IO.FileInfo(Me.Variable("FilePath").ToString) 
92         Try 
93             If info.Exists Then 
94                 ' Loads the XML file 
95                 xDoc.Load(Me.Variable("FilePath").ToString) 
96             Else 
97                 MyBase.RaiseEvent(SBT.EE.Process.StatusCode.Error"The XML file does not exist"
98                 Exit Sub 
99             End If 
100             ' Checks to see if the name of the mapper variables exists in the configuration file 
101             ' If it exists, the value is replaced from the configuration file 
102             For Each xNode In xDoc.SelectNodes("processvariables/processvariable"
103                 Dim _processVariableName As String = xNode.Attributes("name").Value 
104                 If Len(_processVariableName) <> 0 Then 
105                     For Each _key As String In Me._processVariables.Keys 
106                         Dim _processVariable As ProcessVariable = CType(_processVariables(_key), ProcessVariable) 
107                         If _processVariable.Name = _processVariableName Then 
108                             _processVariable.value = xNode.Attributes("value").Value 
109                             Exit For 
110                         End If 
111                     Next 
112                 End If 
113             Next 
114             MyBase.RaiseEvent(SBT.EE.Process.StatusCode.Completed, SBT.EE.Process.StatusCode.Completed.ToString) 
115         Catch ex As Exception 
116             MyBase.RaiseEvent(SBT.EE.Process.StatusCode.Error, ex.Message) 
117         Finally 
118             xDoc = Nothing 
119             info = Nothing 
120         End Try 
121     End Sub 
122 #End Region 
123 #Region "Diplosable & Finalize Implementation" 
124     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean
125         If Not (Me._disposed) Then 
126             Try 
127                 If disposing Then 
128                     ' Release the managed resources  
129                 End If 
130                 Me._disposed = True 
131             Finally 
132                 ' Call Dispose on your base class. 
133                 MyBase.Dispose(disposing) 
134             End Try 
135         End If 
136     End Sub 
137 #End Region 
138 End Class 

 

Right click on the project in the Solution Explorer and select Properties. Under Common Properties » General, select Class Library as the Output Type. Now add an existing icon to the project by right clicking on the project and then select Add » Add Existing Item. Then select the icon by browsing to it and click Open. Right click on the icon file in the project and selectProperties. Under Build Action, select Embedded Resource. Now build the project by selecting Build » Build Solution from the main menu.




Add custom node to the process

Select Process » Process Node Manager from the main menu. 



In the Custom Process Nodes window, click Install New button. Then browse to the ReadConfiguration.dll file and click Open. This will install the Read Configuration node.




Create a Process

Open Enterprise Enabler and create a new process by clicking File » New » Process.




Inserting a Process Variable into the process

In the Toolbox menu go to Proc. Variables, select Proc. Variable and drag it into the process designer area. Rename the Proc. Variable to path. Set the initial value of variable to C:\test.xml. Repeat the same process to create variable1, and variable2 variables. Do not set any values to these variables.


Inserting a Read Configuration node into the Process

In the Toolbox menu go to Action Nodes, select the Read Configuration node and drag it into the process designer area.



Select the Read Configuration node and then click the ellipsis in VariableMappings property in the Properties window. Select the FilePath variable and click the Edit button. Select the path 

Process Variable from the window and click the Select button.

Connect the nodes

In the designer window drag the arrow of the connector from the Start node

and drop it on the Read Configuration node. Drag the arrow from the Read Configuration node to the Stop node. The completed process should look like the following figure:



Save the Process

Click anywhere in the empty area on the designer window and rename

the process in the Properties window.



To save the process click the Save button in the Standard toolbar.



Run the Process

Click on the Start the Process button in the Process Designer toolbar to run the process.


Previous  BackToCategory  Next  6 of 47
Copyright © 2010 by Stone Bond Technologies | Phone: +1 (713) 622-8798   |  Privacy Statement   |  Terms of Use