-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigFileFactory.VBS
164 lines (141 loc) · 14 KB
/
ConfigFileFactory.VBS
1
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
'-------------------------------------------------------------------------------
'-- VBS script file
'-- Created on 08/02/2016 17:55:47
'-- Author:
'-- Comment:
'-------------------------------------------------------------------------------
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Class ConfigFileFactory
Private NodeName, CorridorNodeName, ConfigPath, DialogNodeName
Private Sub Class_Initialize()
NodeName = "ChannelMetaData"
CorridorNodeName = "CorridorsMetaData"
DialogNodeName = "DialogMetaData"
End Sub
Public Default Function Init(testTypeId)
Select Case testTypeid
Case 1
ConfigPath = APPPATH & "crashworthiness\Frontal\ConfigFiles\ModerateConfig.xml"
Case 6
ConfigPath = APPPATH & "crashworthiness\Frontal\ConfigFiles\SmallOverlapConfig.xml"
Case 11
ConfigPath = APPPATH & "crashworthiness\Frontal\ConfigFiles\RightSideSmallOverlapConfig.xml"
Case 999
ConfigPath = APPPATH & "crashworthiness\Frontal\ConfigFiles\CustomConfig.xml"
End Select
Set Init = Me
End Function
Public Function GetChannelList(channelGroupName)
Set GetChannelList = GetNodeNameList(NodeName, channelGroupName)
End Function
Public Function GetCorridorList(channelGroupName)
Set GetCorridorList = GetNodeNameList(CorridorNodeName, channelGroupName)
End Function
Private Function GetNodeNameList(parentNodeName, channelGroupName)
Dim xDoc : Set xDoc = CreateObject("MSXML2.DOMDocument.6.0")
Dim settingsGroup : settingsGroup = parentNodeName
Dim channelSlugList : Set channelSlugList = CreateObject("System.Collections.ArrayList")
If Not xDoc.load(ConfigPath) Then
Set xDoc = Nothing
Call LogError("Unable to load crashworthiness configurationfile, config.xml.")
Exit Function
End If
Dim childNodeSettingsGroup, childNodeSetting, groupTagValue, groupTag
For Each childNodeSettingsGroup In xDoc.documentElement.childNodes
If childNodeSettingsGroup.nodeName = settingsGroup Then
For Each childNodeSetting In childNodeSettingsGroup.childNodes
If childNodeSetting.nodeName <> "#comment" Then
groupTag = childNodeSetting.getAttribute("groupTag")
If groupTag = channelGroupName Then
channelSlugList.Add(childNodeSetting.nodeName)
End If
End If
Next
End If
Next
Set GetNodeNameList = channelSlugList
Set xDoc = Nothing
End Function
Public Function GetConfigValue(settingsGroup, nodeName, attributeName)
Dim xDoc : Set xDoc = CreateObject("MSXML2.DOMDocument.6.0")
If Not xDoc.load(ConfigPath) Then
Set xDoc = Nothing
Call LogError("Unable to load crashworthiness configurationfile, config.xml.")
Exit Function
End If
Dim childNodeSettingsGroup, childNodeSetting
For Each childNodeSettingsGroup In xDoc.documentElement.childNodes
If childNodeSettingsGroup.nodeName = settingsGroup Then
For Each childNodeSetting In childNodeSettingsGroup.childNodes
If childNodeSetting.nodeName = nodeName Then
GetConfigValue = childNodeSetting.getAttribute(AttributeName)
Exit Function
End If
Next
End If
Next
Set xDoc = Nothing
End Function
Public Function GetExportList(channelSlug)
Dim exportList : Set exportList = CreateObject("System.Collections.ArrayList")
Dim xDoc : Set xDoc = CreateObject("MSXML2.DOMDocument.6.0")
If Not xDoc.load(ConfigPath) Then
Set xDoc = Nothing
Call LogError("Unable to load crashworthiness configurationfile, config.xml.")
Exit Function
End If
Dim childNodeSettingsGroup, childNodeSetting, exportNode, exportData
For Each childNodeSettingsGroup In xDoc.documentElement.childNodes
If childNodeSettingsGroup.nodeName = NodeName Then
For Each childNodeSetting In childNodeSettingsGroup.childNodes
If childNodeSetting.nodeName = channelSlug Then
For Each exportNode In childNodeSetting.childNodes
Set exportData = New ExportDTO
exportData.Cell = exportNode.getAttribute("cell")
exportData.PropertyName = exportNode.getAttribute("property")
exportData.RoundValue = exportNode.getAttribute("round")
exportData.Divisor = exportNode.getAttribute("divisor")
exportData.UseFilteredChannel = cbool(exportNode.getAttribute("useFilteredChannel"))
Call exportList.Add(exportData)
Set exportData = Nothing
Next
End If
Next
End If
Next
Set GetExportList = exportList
Set xDoc = Nothing
End Function
Public Function GetDialogExportList
Dim exportList : Set exportList = CreateObject("System.Collections.ArrayList")
Dim xDoc : Set xDoc = CreateObject("MSXML2.DOMDocument.6.0")
If Not xDoc.load(ConfigPath) Then
Set xDoc = Nothing
Call LogError("Unable to load crashworthiness configurationfile, config.xml.")
Exit Function
End If
Dim childNodeSettingsGroup, childNodeSetting, exportNode, exportData
For Each childNodeSettingsGroup In xDoc.documentElement.childNodes
If childNodeSettingsGroup.nodeName = DialogNodeName Then
For Each childNodeSetting In childNodeSettingsGroup.childNodes
Set exportData = New ExportDTO
exportData.Cell = childNodeSetting.getAttribute("cell")
exportData.PropertyName = childNodeSetting.getAttribute("property")
Call exportList.Add(exportData)
Set exportData = Nothing
Next
End If
Next
Set GetDialogExportList = exportList
Set xDoc = Nothing
End Function
End Class
Public Function GetConfigFileFactory(testTypeId)
Set GetConfigFileFactory = (New ConfigFileFactory)(testTypeId)
End Function
Public Function GetFrontalConfigFileFactory
Set GetFrontalConfigFileFactory = (New ConfigFileFactory)(1)
End Function
Class ExportDTO
Dim Cell, PropertyName, RoundValue, Divisor, UseFilteredChannel
End Class