-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModMain.vb
More file actions
316 lines (171 loc) · 8.34 KB
/
ModMain.vb
File metadata and controls
316 lines (171 loc) · 8.34 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
Imports System.IO
Imports System
Imports System.Globalization
Imports System.Threading
Module ModMain
Public TPInput As New ClsTPInput
Public PropLanguage As String = "en" 'Default main language
Public Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New FrmMain())
End Sub
Public Function FunChecks(input As ClsTPInput) As ClsChecksResult
Dim result As New ClsChecksResult
result.PropCheckOk = True
'Check if spreadsheet exists
If Not File.Exists(input.PropSpreadsheet) Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "Spreadsheet is not defined or does not exists."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
'Check if taxonomy name exists
If String.IsNullOrEmpty(input.PropTaxonomyName) Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "A taxonomy name is not defined."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
'Check if prefix exists
If String.IsNullOrEmpty(input.PropPrefix) Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "A prefix is not defined."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
'Check if URL exists
If String.IsNullOrEmpty(input.PropURL) Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "An URL is not defined."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
'Check if URL is valid
If Not String.IsNullOrEmpty(input.PropURL) Then
Dim URIresult As Uri = Nothing
'See if we can create an valid URI
If (Uri.TryCreate(input.PropURL, UriKind.Absolute, URIresult)) = True Then
'See if it starts with http:// or https://.
If (URIresult.Scheme = Uri.UriSchemeHttp Or URIresult.Scheme = Uri.UriSchemeHttps) = False Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "URL must contain http:// or https://."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
Else
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "URL is not valid."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
End If
'Check if save location for TP exists
If Not Directory.Exists(TPInput.PropSaveLocation) Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "TP location is not defined or does not exists."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
'Check if description for taxonomyPackage exists
If String.IsNullOrEmpty(TPInput.PropTPDescription) Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "Description for taxonomyPackage is not defined."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
'Check if version for taxonomyPackage exists
If String.IsNullOrEmpty(TPInput.PropTPVersion) Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "Version for taxonomyPackage is not defined."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
'Check if publisher for taxonomyPackage exists
If String.IsNullOrEmpty(TPInput.PropTPPublisher) Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "Publisher for taxonomyPackage is not defined."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
'Check if publisher URL for taxonomyPackage exists
If String.IsNullOrEmpty(TPInput.PropTPPublisherURL) Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "Publisher URL for taxonomyPackage is not defined."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
'Check if publisher country for taxonomyPackage exists
If String.IsNullOrEmpty(TPInput.PropTPPublisherCountry) Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "Publisher country for taxonomyPackage is not defined."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
'Check if input file entrypoints for taxonompyPackage exists
If Not input.PropTPEntrypointsLocation = "#NONE" Then 'Otherwise use worksheet 'Entrypoints' to define entrypoints
If Not File.Exists(input.PropTPEntrypointsLocation) Then
result.PropCheckOk = False
Dim StrErrorMessage As New ClsCheckErrorMessage
StrErrorMessage.PropCheckErrorMessage = "The input file for the entrypoints (taxonomyPackage) is not defined or does not exists."
result.PropCheckErrorMessages.Add(StrErrorMessage)
End If
End If
Return result
End Function
Public Class ClsChecksResult
Public Property PropCheckOk As Boolean
Public Property PropCheckErrorMessages As New List(Of ClsCheckErrorMessage)
End Class
Public Class ClsCheckErrorMessage
Public Property PropCheckErrorMessage As String
End Class
Public Class ClsTPInput
Public Property PropSpreadsheet As String
Public Property PropPrefix As String
Public Property PropURL As String
Public Property PropDate As String
Public Property PropSaveLocation As String
Public Property PropTaxonomyName As String
Public Property PropTPDescription As String
Public Property PropTPVersion As String
Public Property PropTPPublisher As String
Public Property PropTPPublisherURL As String
Public Property PropTPPublisherCountry As String
Public Property PropTPPublicationDate As String
Public Property PropTPEntrypointsLocation As String
Public Property PropTPPublicationDateTime As Date
End Class
Public Function FunRemovePrefixFromURL(StrURL As String) As String
StrURL = StrURL.Remove(0, StrURL.IndexOf(":") + 3)
Return StrURL
End Function
Public Class entryPoints
Public Property entryPoint As New List(Of LstEntrypoint)
End Class
Public Class LstEntrypoint
Public Property name As String
Public Property description As String
Public Property version As String
Public Property entryPointDocument As String()
Public Property languages As New List(Of LstLanguage)
End Class
Public Class LstLanguage
Public Property language As String
End Class
''' <summary>
''' Class used to temporarily change the culture code (language) to en-US.
''' Needed to communicate in the correct language - for example for the publication date in the annotation
''' </summary>
Public Class ClsChangeLanguageToEnglish
Implements IDisposable
Private CultureOld As CultureInfo
Public Sub New()
CultureOld = CultureInfo.CurrentCulture
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Thread.CurrentThread.CurrentCulture = CultureOld
End Sub
End Class
End Module