| |
view plain | print |
| 1 |
|
| 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 |
|
| 11 |
Private _disposed As Boolean = False |
| 12 |
|
| 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 |
|
| 61 |
Public Overrides Sub ValidateParams() |
| 62 |
|
| 63 |
Dim _validationExceptions As New ValidationExceptions |
| 64 |
|
| 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 |
|
| 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 |
| 91 |
Dim info As New System.IO.FileInfo(Me.Variable("FilePath").ToString) |
| 92 |
Try |
| 93 |
If info.Exists Then |
| 94 |
|
| 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 |
|
| 101 |
|
| 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 |
|
| 129 |
End If |
| 130 |
Me._disposed = True |
| 131 |
Finally |
| 132 |
|
| 133 |
MyBase.Dispose(disposing) |
| 134 |
End Try |
| 135 |
End If |
| 136 |
End Sub |
| 137 |
#End Region |
| 138 |
End Class |