Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1436 lines
44 KiB

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  4. Begin VB.Form frmMain
  5. BorderStyle = 1 'Fixed Single
  6. Caption = "KeywordCreator"
  7. ClientHeight = 6825
  8. ClientLeft = 3075
  9. ClientTop = 2340
  10. ClientWidth = 9855
  11. LinkTopic = "Form1"
  12. MaxButton = 0 'False
  13. MinButton = 0 'False
  14. ScaleHeight = 6825
  15. ScaleWidth = 9855
  16. Begin VB.Frame Frame1
  17. Caption = "Operational Mode:"
  18. Height = 735
  19. Left = 210
  20. TabIndex = 17
  21. Top = 2295
  22. Width = 3570
  23. Begin VB.OptionButton optIncremental
  24. Caption = "Validate Only"
  25. Height = 420
  26. Index = 2
  27. Left = 2295
  28. TabIndex = 18
  29. Top = 225
  30. Width = 1155
  31. End
  32. Begin VB.OptionButton optIncremental
  33. Caption = "Reset Pass"
  34. Height = 375
  35. Index = 1
  36. Left = 1275
  37. TabIndex = 11
  38. Top = 240
  39. Width = 945
  40. End
  41. Begin VB.OptionButton optIncremental
  42. Caption = "Additive Pass"
  43. Height = 420
  44. Index = 0
  45. Left = 165
  46. TabIndex = 10
  47. Top = 195
  48. Width = 1155
  49. End
  50. End
  51. Begin VB.TextBox txtLogFile
  52. Height = 375
  53. Left = 135
  54. TabIndex = 8
  55. Top = 1785
  56. Width = 8070
  57. End
  58. Begin VB.CommandButton cmdLogFile
  59. Caption = "&Log File..."
  60. Height = 375
  61. Left = 8280
  62. TabIndex = 9
  63. Top = 1800
  64. Width = 1485
  65. End
  66. Begin VB.TextBox txtCabFile
  67. Height = 375
  68. Left = 135
  69. TabIndex = 2
  70. Top = 570
  71. Width = 8070
  72. End
  73. Begin VB.CommandButton cmdBrowse
  74. Caption = "&Input Cab..."
  75. Height = 375
  76. Left = 8280
  77. TabIndex = 3
  78. Top = 600
  79. Width = 1485
  80. End
  81. Begin VB.TextBox txtSaveCab
  82. Height = 375
  83. Left = 135
  84. TabIndex = 4
  85. Top = 975
  86. Width = 8070
  87. End
  88. Begin VB.CommandButton cmdSave
  89. Caption = "&Output Cab..."
  90. Height = 375
  91. Left = 8280
  92. TabIndex = 5
  93. Top = 990
  94. Width = 1485
  95. End
  96. Begin VB.TextBox txtQueriesFolder
  97. Height = 375
  98. Left = 135
  99. TabIndex = 0
  100. Top = 165
  101. Width = 8070
  102. End
  103. Begin VB.CommandButton cmdBrowseQueries
  104. Caption = "&Queries Folder..."
  105. Height = 375
  106. Left = 8280
  107. TabIndex = 1
  108. Top = 180
  109. Width = 1485
  110. End
  111. Begin VB.TextBox txtBaseCab
  112. Height = 375
  113. Left = 135
  114. TabIndex = 6
  115. Top = 1380
  116. Width = 8070
  117. End
  118. Begin VB.CommandButton cmdBase
  119. Caption = "&Base Cab..."
  120. Height = 375
  121. Left = 8280
  122. TabIndex = 7
  123. Top = 1395
  124. Width = 1485
  125. End
  126. Begin VB.TextBox txtLog
  127. Height = 3120
  128. Left = 30
  129. MultiLine = -1 'True
  130. ScrollBars = 2 'Vertical
  131. TabIndex = 16
  132. TabStop = 0 'False
  133. Top = 3120
  134. Width = 9765
  135. End
  136. Begin MSComctlLib.ProgressBar prgBar
  137. Height = 210
  138. Left = 0
  139. TabIndex = 15
  140. Top = 6360
  141. Visible = 0 'False
  142. Width = 9810
  143. _ExtentX = 17304
  144. _ExtentY = 370
  145. _Version = 393216
  146. Appearance = 1
  147. End
  148. Begin MSComctlLib.StatusBar stbProgress
  149. Align = 2 'Align Bottom
  150. Height = 210
  151. Left = 0
  152. TabIndex = 14
  153. Top = 6615
  154. Width = 9855
  155. _ExtentX = 17383
  156. _ExtentY = 370
  157. Style = 1
  158. _Version = 393216
  159. BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
  160. NumPanels = 1
  161. BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
  162. EndProperty
  163. EndProperty
  164. End
  165. Begin MSComDlg.CommonDialog dlg
  166. Left = -90
  167. Top = -150
  168. _ExtentX = 847
  169. _ExtentY = 847
  170. _Version = 393216
  171. End
  172. Begin VB.CommandButton cmdClose
  173. Caption = "&Close"
  174. Height = 375
  175. Left = 8850
  176. TabIndex = 13
  177. Top = 2640
  178. Width = 855
  179. End
  180. Begin VB.CommandButton cmdGo
  181. Caption = "&OK"
  182. Height = 375
  183. Left = 7920
  184. TabIndex = 12
  185. Top = 2640
  186. Width = 855
  187. End
  188. End
  189. Attribute VB_Name = "frmMain"
  190. Attribute VB_GlobalNameSpace = False
  191. Attribute VB_Creatable = False
  192. Attribute VB_PredeclaredId = True
  193. Attribute VB_Exposed = False
  194. Option Explicit
  195. ' Utility Stuff, all this could go to a COM Object and be distributed
  196. ' like this.
  197. Private m_WsShell As IWshShell ' Used to Shell and Wait for Sub-Processes
  198. Private m_fso As Scripting.FileSystemObject ' For filesystem operations
  199. Private m_fhLog As Scripting.TextStream ' This we use to log the output to a file
  200. Public g_dictStopWords As Scripting.Dictionary
  201. Private dictStopSigns As Scripting.Dictionary
  202. Private strOperatorsAnd As String
  203. Private strOperatorsOr As String
  204. Private strOperatorsNot As String
  205. Private m_dictUriList As Scripting.Dictionary
  206. Private Type oDomHhtEntry
  207. strHhtFile As String
  208. oDomHht As DOMDocument
  209. End Type
  210. Private m_aDomHht() As oDomHhtEntry
  211. Private WithEvents p_frmFolderChooser As frmFolderChooser
  212. Attribute p_frmFolderChooser.VB_VarHelpID = -1
  213. Enum OperationalMode
  214. AdditivePriorityPass = 0
  215. ResetPriorityPass = 1
  216. ValidateOnly = 2
  217. AutoKeywords = 3
  218. End Enum
  219. Private m_OperationalMode As OperationalMode
  220. Enum ProcessingState
  221. PROC_PROCESSING = 2 ^ 0
  222. PROC_STOP_PROCESSING_NOW = 2 ^ 2
  223. PROC_PROCESSING_STOPPED = 2 ^ 3
  224. End Enum
  225. Private Sub Form_Initialize()
  226. Set m_WsShell = CreateObject("Wscript.Shell")
  227. Set m_fso = New Scripting.FileSystemObject
  228. Set m_dictUriList = New Scripting.Dictionary
  229. m_OperationalMode = 0
  230. End Sub
  231. Private Sub Form_Load()
  232. Me.Caption = App.EXEName & " (v" & App.Major & "." & App.Minor & "." & App.Revision & _
  233. "): Prioritized Keyword creation tool"
  234. Me.optIncremental(0).Value = True
  235. cmdGo.Default = True
  236. cmdClose.Cancel = True
  237. Set p_frmFolderChooser = New frmFolderChooser
  238. Dim strCommand As String
  239. strCommand = Trim$(Command$)
  240. If (strCommand = "") Then
  241. Exit Sub
  242. End If
  243. txtQueriesFolder = GetOption(strCommand, "q", True)
  244. txtCabFile = GetOption(strCommand, "i", True)
  245. txtSaveCab = GetOption(strCommand, "o", True)
  246. txtBaseCab = GetOption(strCommand, "b", True)
  247. txtLogFile = GetOption(strCommand, "l", True)
  248. If (OptionExists(strCommand, "1", True)) Then
  249. optIncremental(0).Value = True
  250. ElseIf (OptionExists(strCommand, "2", True)) Then
  251. optIncremental(1).Value = True
  252. ElseIf (OptionExists(strCommand, "3", True)) Then
  253. optIncremental(2).Value = True
  254. End If
  255. cmdGo_Click
  256. cmdClose_Click
  257. Common_Exit:
  258. End Sub
  259. Private Sub optIncremental_Click(Index As Integer)
  260. m_OperationalMode = Index
  261. End Sub
  262. Sub WriteLog(strMsg As String, Optional ByVal bWriteToStatusBar As Boolean = True)
  263. With Me
  264. .txtLog = .txtLog & vbCrLf & strMsg
  265. If (bWriteToStatusBar) Then
  266. .stbProgress.SimpleText = strMsg
  267. End If
  268. If (Len(.txtLog) > 65000) Then
  269. TrimLogTop
  270. End If
  271. End With
  272. If (Not m_fhLog Is Nothing) Then
  273. m_fhLog.WriteLine strMsg
  274. End If
  275. DoEvents
  276. End Sub
  277. Sub WriteStatus(strMsg As String)
  278. With Me
  279. .stbProgress.SimpleText = strMsg
  280. End With
  281. DoEvents
  282. End Sub
  283. Sub TrimLogTop()
  284. Dim lPos As Long
  285. With Me
  286. lPos = InStrRev(Left$(.txtLog, 1000), vbCrLf)
  287. If (lPos > 0) Then
  288. .txtLog = Mid$(.txtLog, lPos + 2)
  289. End If
  290. End With
  291. End Sub
  292. Private Function p_getTemplateName( _
  293. ByVal strBase As String, _
  294. Optional ByVal strFolder As String = "", _
  295. Optional ByVal strExt As String = "", _
  296. Optional ByVal strPreAmble As String = "", _
  297. Optional ByVal strTrailer As String = "", _
  298. Optional ByVal bReturnFullName = False _
  299. ) As String
  300. Dim strCandidateFileName As String
  301. Dim lx As Long: lx = 1
  302. Do
  303. strCandidateFileName = _
  304. IIf(strFolder = "", m_fso.GetParentFolderName(strBase), strFolder) & "\" & _
  305. strPreAmble & _
  306. m_fso.GetBaseName(strBase) & _
  307. strTrailer & IIf(lx > 1, "_" & lx, "") & "." & _
  308. IIf(strExt = "", m_fso.GetExtensionName(strBase), strExt)
  309. lx = lx + 1
  310. Loop While (m_fso.FileExists(strCandidateFileName))
  311. p_getTemplateName = IIf(bReturnFullName, _
  312. strCandidateFileName, _
  313. m_fso.GetFileName(strCandidateFileName) _
  314. )
  315. End Function
  316. Private Sub SetRunningState(ByVal bRunning As Boolean)
  317. With Me
  318. .cmdGo.Enabled = Not bRunning
  319. .cmdBrowse.Enabled = Not bRunning
  320. .cmdSave.Enabled = Not bRunning
  321. .txtQueriesFolder.Enabled = Not bRunning
  322. .txtSaveCab.Enabled = Not bRunning
  323. If (bRunning) Then
  324. .cmdClose.Caption = "&Stop"
  325. Else
  326. .cmdClose.Caption = "&Close"
  327. End If
  328. End With
  329. End Sub
  330. Private Function p_Hex2dec(ByRef strHex As String) As Long
  331. p_Hex2dec = CLng("&H" + strHex)
  332. End Function
  333. Private Function p_Percent2Ascii(ByRef strPercentHex As String) As String
  334. p_Percent2Ascii = ""
  335. On Error GoTo Common_Exit
  336. p_Percent2Ascii = ChrW(p_Hex2dec(Mid$(strPercentHex, 2)))
  337. Common_Exit:
  338. End Function
  339. Private Function p_NormalizeUriNotation(ByRef strUri As String) As String
  340. p_NormalizeUriNotation = ""
  341. Dim pRv As String: pRv = ""
  342. Dim lx As Long
  343. lx = 1
  344. Do While (lx <= Len(strUri))
  345. Dim cThis As String
  346. cThis = Mid$(strUri, lx, 1)
  347. If (Len(strUri) - lx > 2) Then
  348. If (cThis = "%") Then
  349. Dim cChar As String
  350. cChar = p_Percent2Ascii(Mid$(strUri, lx, 3))
  351. If (Len(cChar) > 0) Then
  352. pRv = pRv + cChar
  353. lx = lx + 2 ' The reinitialization at the end bumps us one more up.
  354. Else
  355. pRv = pRv + cThis
  356. End If
  357. Else
  358. pRv = pRv + cThis
  359. End If
  360. Else
  361. pRv = pRv + cThis
  362. End If
  363. lx = lx + 1
  364. Loop
  365. p_NormalizeUriNotation = Trim$(pRv)
  366. Common_Exit:
  367. End Function
  368. Function Cab2Folder(ByVal strCabFile As String)
  369. Cab2Folder = ""
  370. ' We grab a Temporary Filename and create a folder out of it
  371. Dim strFolder As String
  372. strFolder = Environ("TEMP") + "\" + m_fso.GetTempName
  373. m_fso.CreateFolder strFolder
  374. ' We uncab CAB contents into the Source CAB Contents dir.
  375. Dim strcmd As String
  376. strcmd = "cabarc X """ + strCabFile + """ " + strFolder + "\"
  377. m_WsShell.Run strcmd, True, True
  378. Cab2Folder = strFolder
  379. End Function
  380. Sub Folder2Cab( _
  381. ByVal strFolder As String, _
  382. ByVal strCabFile As String _
  383. )
  384. ' We recab using the Destination directory contents
  385. ' cabarc -s 6144 N ..\algo.cab *.*
  386. If (m_fso.FileExists(strCabFile)) Then
  387. m_fso.DeleteFile strCabFile, Force:=True
  388. End If
  389. Dim strcmd As String
  390. strcmd = "cabarc -s 6144 N """ + strCabFile + """ " + strFolder + "\*.*"
  391. m_WsShell.Run strcmd, True, True
  392. End Sub
  393. ' ============ END UTILITY STUFF ========================
  394. ' ============ BoilerPlate Form Code
  395. Private Sub cmdBrowseQueries_Click()
  396. Load p_frmFolderChooser
  397. p_frmFolderChooser.SetFolder 0, txtQueriesFolder.Text
  398. p_frmFolderChooser.Show vbModal
  399. End Sub
  400. Private Sub p_frmFolderChooser_FolderChosen( _
  401. ByVal i_intIndex As Long, _
  402. ByVal strFolder As String _
  403. )
  404. txtQueriesFolder.Text = strFolder
  405. End Sub
  406. Private Sub cmdBase_Click()
  407. dlg.Filter = "All Files (*.*)|*.*|Cab Files (*.cab)|*.cab"
  408. dlg.FilterIndex = 2
  409. dlg.FileName = ""
  410. dlg.ShowOpen
  411. If (Len(dlg.FileName) > 0) Then
  412. Me.txtBaseCab = dlg.FileName
  413. End If
  414. End Sub
  415. Private Sub cmdBrowse_Click()
  416. dlg.Filter = "All Files (*.*)|*.*|Cab Files (*.cab)|*.cab"
  417. dlg.FilterIndex = 2
  418. dlg.FileName = ""
  419. dlg.ShowOpen
  420. If (Len(dlg.FileName) > 0) Then
  421. Me.txtCabFile = dlg.FileName
  422. End If
  423. End Sub
  424. Private Sub cmdSave_Click()
  425. dlg.Filter = "All Files (*.*)|*.*|Cab Files (*.cab)|*.cab"
  426. dlg.FilterIndex = 2
  427. dlg.FileName = p_getTemplateName(Me.txtCabFile, strTrailer:="_out")
  428. dlg.ShowSave
  429. If (Len(dlg.FileName) > 0) Then
  430. Me.txtSaveCab = dlg.FileName
  431. End If
  432. End Sub
  433. Private Sub cmdLogFile_Click()
  434. dlg.Filter = "All Files (*.*)|*.*|Log Files (*.log)|*.log"
  435. dlg.FilterIndex = 2
  436. dlg.FileName = p_getTemplateName(Me.txtCabFile, strExt:="log", strTrailer:="_out")
  437. dlg.ShowSave
  438. If (Len(dlg.FileName) > 0) Then
  439. Me.txtLogFile = dlg.FileName
  440. End If
  441. End Sub
  442. Private Sub cmdClose_Click()
  443. Unload Me
  444. End Sub
  445. Private Sub cmdGo_Click()
  446. With Me
  447. .txtCabFile.Text = Trim$(.txtCabFile.Text)
  448. .txtSaveCab.Text = Trim$(.txtSaveCab.Text)
  449. .txtCabFile.Enabled = False
  450. .txtSaveCab.Enabled = False
  451. .cmdBrowse.Enabled = False
  452. .cmdSave.Enabled = False
  453. .cmdGo.Enabled = False
  454. If (Len(.txtCabFile.Text) > 0) Then
  455. FixCab .txtCabFile.Text, .txtSaveCab.Text, Trim$(.txtBaseCab.Text), .txtLogFile
  456. End If
  457. .txtCabFile.Enabled = True
  458. .txtSaveCab.Enabled = True
  459. .cmdBrowse.Enabled = True
  460. .cmdSave.Enabled = True
  461. .cmdGo.Enabled = True
  462. End With
  463. End Sub
  464. Sub FixCab( _
  465. ByVal strCabFile As String, _
  466. ByVal strSaveCab As String, _
  467. ByVal strBaseCab As String, _
  468. ByVal strLogFile As String _
  469. )
  470. Dim strErrMsg As String: strErrMsg = ""
  471. If (Not m_fso.FileExists(strCabFile)) Then
  472. strErrMsg = "Cannot find " & strCabFile
  473. MsgBox strErrMsg
  474. GoTo Common_Exit
  475. End If
  476. If (Len(strLogFile) = 0) Then
  477. strLogFile = p_getTemplateName(strCabFile, strExt:="log", strTrailer:="_out", bReturnFullName:=True)
  478. Me.txtLogFile = strLogFile
  479. End If
  480. Set m_fhLog = m_fso.CreateTextFile(strLogFile, True, True)
  481. p_LogRunInformation
  482. Dim strCabFolder As String
  483. prgBar.Visible = True
  484. WriteStatus "Uncabbing " & strCabFile
  485. strCabFolder = Cab2Folder(strCabFile)
  486. ' Now we start processing based on the command passed
  487. Select Case (m_OperationalMode)
  488. Case AdditivePriorityPass, ResetPriorityPass
  489. Dim strBaseCabFolder As String
  490. If (strBaseCab <> "") Then
  491. If (Not m_fso.FileExists(strBaseCab)) Then
  492. MsgBox "Cannot find " & strBaseCab
  493. GoTo Common_Exit
  494. End If
  495. prgBar.Visible = True
  496. WriteStatus "Uncabbing " & strBaseCab
  497. strBaseCabFolder = Cab2Folder(strBaseCab)
  498. Else
  499. strBaseCabFolder = strCabFolder
  500. End If
  501. WriteStatus "Extracting Stop Words and Stop Signs"
  502. GetStopWordsAndStopSigns strBaseCabFolder
  503. WriteStatus "Applying Fixes "
  504. Dim bGoodFix As Boolean
  505. bGoodFix = FixPerSe(strCabFolder)
  506. If (Not bGoodFix) Then
  507. MsgBox "Error: Fix Failed", Title:=App.EXEName
  508. Else
  509. WriteStatus "Recabbing " & strCabFile
  510. Folder2Cab strCabFolder, strSaveCab
  511. End If
  512. Case ValidateOnly
  513. p_ValidatePass strCabFolder
  514. Case Else
  515. MsgBox "Not a valid command"
  516. GoTo Common_Exit
  517. End Select
  518. ' Now we delete the Temporary Folders
  519. prgBar.Visible = False
  520. WriteStatus "Deleting Temporary Files"
  521. m_fso.DeleteFolder strCabFolder, Force:=True
  522. m_fhLog.Close: Set m_fhLog = Nothing
  523. Common_Exit:
  524. WriteStatus "Done" + IIf(Len(strErrMsg) > 0, " - " + strErrMsg, "")
  525. End Sub
  526. Sub p_LogRunInformation()
  527. WriteLog Me.Caption, False
  528. WriteLog String$(100, "="), False
  529. WriteLog App.EXEName & " run on " & Now
  530. WriteLog "Operational Mode = " & IIf(m_OperationalMode = AdditivePriorityPass, _
  531. "Additive Priority", _
  532. IIf(m_OperationalMode = ResetPriorityPass, _
  533. "Reset Priority", _
  534. "Validation" _
  535. ) _
  536. ) & " Pass"
  537. With Me
  538. If (Len(.txtQueriesFolder) > 0) Then
  539. WriteLog "Queries Folder = " & .txtQueriesFolder
  540. End If
  541. If (Len(.txtCabFile) > 0) Then
  542. WriteLog "Input Cab File = " & .txtCabFile
  543. End If
  544. If (Len(.txtSaveCab) > 0) Then
  545. WriteLog "Output Cab File = " & .txtSaveCab
  546. End If
  547. If (Len(.txtBaseCab) > 0) Then
  548. WriteLog "Reference Cab File = " & .txtBaseCab
  549. End If
  550. If (Len(.txtLogFile) > 0) Then
  551. WriteLog "Output Log File = " & .txtLogFile
  552. End If
  553. End With
  554. WriteLog String$(100, "="), False
  555. End Sub
  556. Sub GetStopWordsAndStopSigns(ByVal strCabFolder As String)
  557. Dim oElem As IXMLDOMElement ' Used for all element Creation
  558. ' We parse Package_Description.xml to find the HHT Files
  559. Dim oDomPkg As DOMDocument: Set oDomPkg = New DOMDocument
  560. Dim strPkgFile As String: strPkgFile = strCabFolder + "\package_description.xml"
  561. oDomPkg.async = False
  562. oDomPkg.Load strPkgFile
  563. If (oDomPkg.parseError <> 0) Then GoTo Common_Exit
  564. Dim oMetaDataNode As IXMLDOMNode
  565. Set oMetaDataNode = oDomPkg.selectSingleNode("HELPCENTERPACKAGE/METADATA")
  566. strOperatorsAnd = ""
  567. strOperatorsOr = ""
  568. strOperatorsNot = ""
  569. Dim oDomHhtNode As IXMLDOMNode
  570. ' now we go through each HHT and check for fix relevancy.
  571. For Each oDomHhtNode In oMetaDataNode.selectNodes("HHT")
  572. Dim strHhtFile As String
  573. strHhtFile = oDomHhtNode.Attributes.getNamedItem("FILE").Text
  574. ' Let's load the HHT
  575. Dim oDomHht As DOMDocument: Set oDomHht = New DOMDocument
  576. oDomHht.async = False
  577. oDomHht.Load strCabFolder + "\" + strHhtFile
  578. If (oDomHht.parseError <> 0) Then GoTo Common_Exit
  579. p_LoadStopWords oDomHht
  580. p_LoadStopSigns oDomHht
  581. p_LoadVerbalOperators oDomHht
  582. Next
  583. If (dictStopSigns.Count = 0) Then
  584. WriteLog "Warning: Your StopSigns list is empty.", False
  585. WriteLog vbTab + "This may be due to the fact that you are not adding a Base Cab", False
  586. WriteLog vbTab + "or that you are working in a language where StopSigns do not exist", False
  587. End If
  588. If (g_dictStopWords.Count = 0) Then
  589. WriteLog "Warning: Your StopWords list is empty.", False
  590. WriteLog vbTab + "This may be due to the fact that you are not adding a Base Cab", False
  591. WriteLog vbTab + "or that you are working in a language where StopWords do not exist", False
  592. End If
  593. SetVerbalOperators strOperatorsAnd, strOperatorsOr, strOperatorsNot
  594. Common_Exit:
  595. Exit Sub
  596. End Sub
  597. Private Function p_GetHht( _
  598. ByRef oDomHhtNode As IXMLDOMNode, _
  599. ByVal strCabFolder As String, _
  600. Optional ByRef strHhtFile As String = "" _
  601. ) As IXMLDOMNode
  602. Set p_GetHht = Nothing
  603. If (oDomHhtNode Is Nothing) Then GoTo Common_Exit
  604. strHhtFile = oDomHhtNode.Attributes.getNamedItem("FILE").Text
  605. ' Let's load the HHT
  606. Dim oDomHht As DOMDocument: Set oDomHht = New DOMDocument
  607. oDomHht.async = False
  608. oDomHht.Load strCabFolder + "\" + strHhtFile
  609. If (oDomHht.parseError <> 0) Then
  610. p_DisplayParseError oDomHht.parseError
  611. GoTo Common_Exit
  612. End If
  613. Set p_GetHht = oDomHht
  614. Common_Exit:
  615. End Function
  616. Function p_ValidatePass(ByVal strCabFolder As String) As Boolean
  617. p_ValidatePass = True ' because this pass should never fail.
  618. ' We parse Package_Description.xml to find the HHT Files
  619. Dim oDomPkg As DOMDocument: Set oDomPkg = New DOMDocument
  620. Dim strPkgFile As String: strPkgFile = strCabFolder + "\package_description.xml"
  621. oDomPkg.async = False
  622. oDomPkg.Load strPkgFile
  623. If (oDomPkg.parseError <> 0) Then GoTo Common_Exit
  624. ' We first open all HHTs this way we only loop through
  625. ' them in memory next.
  626. p_OpenAllHhts strCabFolder, oDomPkg
  627. If (Not p_MeetsAcceptanceTest) Then
  628. WriteLog "your prioritization numbers exceed acceptance criteria"
  629. WriteLog "you need to prioritize fewer keywords for priority to be effective"
  630. Else
  631. WriteLog "Your prioritization numbers meet acceptance criteria"
  632. End If
  633. Common_Exit:
  634. End Function
  635. Function FixPerSe(ByVal strCabFolder As String) As Boolean
  636. FixPerSe = False
  637. Dim oElem As IXMLDOMElement ' Used for all element Creation
  638. ' We parse Package_Description.xml to find the HHT Files
  639. Dim oDomPkg As DOMDocument: Set oDomPkg = New DOMDocument
  640. Dim strPkgFile As String: strPkgFile = strCabFolder + "\package_description.xml"
  641. oDomPkg.async = False
  642. oDomPkg.Load strPkgFile
  643. If (oDomPkg.parseError <> 0) Then GoTo Common_Exit
  644. Dim oDomHhtNode As IXMLDOMNode
  645. Dim strHhtFile As String
  646. ' We first open all HHTs this way we only loop through
  647. ' them in memory next.
  648. p_OpenAllHhts strCabFolder, oDomPkg
  649. If (m_OperationalMode = ResetPriorityPass) Then
  650. p_ZapAllPriorityEntries
  651. Else
  652. If (Not p_MeetsAcceptanceTest) Then
  653. GoTo Common_Exit
  654. End If
  655. End If
  656. ' Now we create a collection that has all the Uris and its questions
  657. p_BuildUriList
  658. ' now we go through each HHT and check for fix relevancy.
  659. Dim lx As Long
  660. For lx = 0 To UBound(m_aDomHht)
  661. With m_aDomHht(lx)
  662. Dim oListTopics As IXMLDOMNodeList
  663. Set oListTopics = .oDomHht.selectNodes("/METADATA/TAXONOMY_ENTRIES/TAXONOMY_ENTRY[ not( @ENTRY ) ]")
  664. If (Not oListTopics Is Nothing) Then
  665. ' We go through this HHT ONLY if it has
  666. ' Taxonomy Entries for Topics
  667. Dim oTaxoNode As IXMLDOMNode, strUri As String
  668. Me.prgBar.Visible = True
  669. Me.prgBar.Max = oListTopics.length + 1
  670. Me.prgBar.Value = 0
  671. .oDomHht.setProperty "SelectionLanguage", "XPath"
  672. Dim intNewKeywords As Long, intOldKeywords As Long, _
  673. intTotalNewKeywords As Long, intTotalOldKeywords As Long
  674. For Each oTaxoNode In oListTopics
  675. strUri = LCase$(XMLGetAttribute(oTaxoNode, "URI"))
  676. If (m_dictUriList.Exists(strUri)) Then
  677. ' The URI exists so we need to set the keywords.
  678. Dim oUQ As UriQueries
  679. Set oUQ = m_dictUriList.Item(strUri)
  680. oUQ.SetTaxonomyEntryKeywords oTaxoNode
  681. intTotalNewKeywords = intTotalNewKeywords + intNewKeywords
  682. intTotalOldKeywords = intTotalOldKeywords + intOldKeywords
  683. End If
  684. Me.prgBar.Value = Me.prgBar.Value + 1
  685. WriteStatus "Fixing URIs in HHTs " & " [" & Me.prgBar.Value & "/" & Me.prgBar.Max & "]"
  686. Next
  687. .oDomHht.Save .strHhtFile
  688. End If
  689. End With
  690. Next
  691. If (Not p_MeetsAcceptanceTest) Then
  692. GoTo Common_Exit
  693. End If
  694. ' Now we save the resulting package_description.xml
  695. oDomPkg.Save strPkgFile
  696. ' Finally we log an entry that specifies the amount of Keywords that
  697. ' have priority attributes.
  698. FixPerSe = True
  699. Common_Exit:
  700. Exit Function
  701. End Function
  702. Private Sub p_OpenAllHhts( _
  703. ByVal strCabFolder As String, _
  704. ByRef oDomPkg As IXMLDOMNode _
  705. )
  706. Dim oMetaDataNode As IXMLDOMNode
  707. Set oMetaDataNode = oDomPkg.selectSingleNode("HELPCENTERPACKAGE/METADATA")
  708. Dim oDomHhtNode As IXMLDOMNode, oDomHht As IXMLDOMNode
  709. Dim strHhtFile As String
  710. Dim lx As Long
  711. For Each oDomHhtNode In oMetaDataNode.selectNodes("HHT")
  712. Set oDomHht = p_GetHht(oDomHhtNode, strCabFolder, strHhtFile)
  713. ReDim Preserve m_aDomHht(lx)
  714. With m_aDomHht(lx)
  715. Set .oDomHht = oDomHht
  716. .strHhtFile = strCabFolder + "\" + strHhtFile
  717. End With
  718. lx = lx + 1
  719. Next
  720. Common_Exit:
  721. End Sub
  722. Private Sub p_ZapAllPriorityEntries()
  723. Dim lx As Long
  724. For lx = 0 To UBound(m_aDomHht)
  725. ' Let's point to the right HHT
  726. Dim oDomHht As IXMLDOMNode
  727. Set oDomHht = m_aDomHht(lx).oDomHht
  728. Dim oDomNodeList As IXMLDOMNodeList
  729. Set oDomNodeList = oDomHht.selectNodes("//KEYWORD[ @PRIORITY ]")
  730. If (Not oDomNodeList Is Nothing) Then
  731. Dim oDomNode As IXMLDOMNode
  732. For Each oDomNode In oDomNodeList
  733. oDomNode.Attributes.removeNamedItem ("PRIORITY")
  734. Next
  735. End If
  736. Next lx
  737. End Sub
  738. Private Function p_MeetsAcceptanceTest() As Boolean
  739. p_MeetsAcceptanceTest = False
  740. Dim lngKwHht As Long, lngKwPriHht As Long, _
  741. lngTotalKwHht As Long, lngTotalKwPriHht As Long, _
  742. lngKwGt12k As Long, _
  743. lngKwEq10k As Long, _
  744. lngKwEq5k As Long, _
  745. lngKwEq3_3k As Long, _
  746. lngTotalKwGt12k As Long, _
  747. lngTotalKwEq10k As Long, _
  748. lngTotalKwEq5k As Long, _
  749. lngTotalKwEq3_3k As Long
  750. ' lngTotalTaxoEntries As Long, lngTaxoEntries As Long
  751. Dim lx As Long
  752. ' We assess that this set has less than 25% of the Keywords
  753. ' with the PRIORITY attribute set.
  754. ' lngTotalTaxoEntries = 0
  755. lngTotalKwHht = 0: lngTotalKwPriHht = 0:
  756. lngTotalKwGt12k = 0: lngTotalKwEq10k = 0: lngTotalKwEq5k = 0: lngTotalKwEq3_3k = 0
  757. For lx = 0 To UBound(m_aDomHht)
  758. With m_aDomHht(lx)
  759. ' Dim oList As IXMLDOMNodeList
  760. ' Set oList = .oDomHht.selectNodes("//TAXONOMY_ENTRY")
  761. ' lngTaxoEntries = IIf(oList Is Nothing, 0, oList.length)
  762. ' lngTotalTaxoEntries = lngTotalTaxoEntries + lngTaxoEntries
  763. p_GetPrioKw .oDomHht, lngKwHht, lngKwPriHht, _
  764. lngKwGt12k, _
  765. lngKwEq10k, _
  766. lngKwEq5k, _
  767. lngKwEq3_3k
  768. lngTotalKwHht = lngTotalKwHht + lngKwHht
  769. lngTotalKwPriHht = lngTotalKwPriHht + lngKwPriHht
  770. lngTotalKwGt12k = lngTotalKwGt12k + lngKwGt12k
  771. lngTotalKwEq10k = lngTotalKwEq10k + lngKwEq10k
  772. lngTotalKwEq5k = lngTotalKwEq5k + lngKwEq5k
  773. lngTotalKwEq3_3k = lngTotalKwEq3_3k + lngKwEq3_3k
  774. WriteLog m_fso.GetFileName(m_aDomHht(lx).strHhtFile) & _
  775. ": There are " & lngKwHht & " keywords and " & _
  776. lngKwPriHht & " of them are prioritized "
  777. If (lngKwGt12k > 0) Then
  778. WriteLog "No keywords are allowed with Priority greater than 12000"
  779. GoTo Common_Exit
  780. End If
  781. End With
  782. Next lx
  783. Dim lngPercentPri As Long:
  784. ' The following is just a hack to avoid division by 0
  785. ' it does not alter statistics.
  786. If (lngTotalKwHht = 0) Then lngTotalKwHht = 1
  787. lngPercentPri = lngTotalKwPriHht / lngTotalKwHht * 100
  788. WriteLog Me.txtCabFile & " has " & Format$(lngPercentPri, "#0.0##") & "% Keywords with Priority Attribute"
  789. WriteLog vbTab & Format$(lngKwEq10k / lngTotalKwHht * 100, "#0.0##") & "% Keywords for single word queries"
  790. WriteLog vbTab & Format$(lngKwEq5k / lngTotalKwHht * 100, "#0.0##") & "% Keywords for two word queries"
  791. If (lngKwEq3_3k > 0) Then
  792. WriteLog vbTab & Format$(lngKwEq3_3k / lngTotalKwHht * 100, "#0.0##") & "% Keywords for three word queries"
  793. End If
  794. ' now we do the acceptance test... we leave a small back-door for
  795. ' Fix HHTs which will have up to 5 topics ... really 25 keywords
  796. If (lngPercentPri > 25 And lngTotalKwHht > 25) Then
  797. WriteLog "a Maximum of 25% Keywords can be prioritized."
  798. GoTo Common_Exit
  799. End If
  800. p_MeetsAcceptanceTest = True
  801. Common_Exit:
  802. End Function
  803. Private Sub p_BuildUriList()
  804. Dim strUserQuery As String, strExpectedUri As String
  805. Dim rsQs As ADODB.Recordset
  806. Dim Folder As Scripting.Folder
  807. Dim File As Scripting.File
  808. Set rsQs = New ADODB.Recordset
  809. rsQs.Fields.Append "User Query", adVarWChar, 512
  810. rsQs.Fields.Append "Expected Uri", adVarWChar, 512
  811. rsQs.Open
  812. Set Folder = m_fso.GetFolder(Me.txtQueriesFolder)
  813. For Each File In Folder.Files
  814. If (LCase$(Right(File.Name, 3) = "xml")) Then
  815. If (LCase$(Left(File.Name, 7)) = "queries") Then
  816. p_XlXml2Recordset File.Path, rsQs
  817. Else
  818. WriteLog "Ignoring " & File.Path
  819. End If
  820. ElseIf (LCase$(Right(File.Name, 3) = "xls")) Then
  821. If (LCase$(Left(File.Name, 7)) = "queries") Then
  822. p_Xls2Recordset File.Path, rsQs
  823. Else
  824. WriteLog "Ignoring " & File.Path
  825. End If
  826. End If
  827. Next
  828. rsQs.Sort = "[Expected Uri],[User Query]"
  829. If (rsQs.RecordCount = 0) Then
  830. Exit Sub
  831. End If
  832. rsQs.MoveFirst
  833. m_dictUriList.RemoveAll
  834. Dim oUQ As UriQueries
  835. Do While (Not rsQs.EOF)
  836. strUserQuery = rsQs("User Query")
  837. strExpectedUri = rsQs("Expected Uri")
  838. If (Not m_dictUriList.Exists(strExpectedUri)) Then
  839. Set oUQ = New UriQueries
  840. oUQ.Uri = strExpectedUri
  841. m_dictUriList.Add strExpectedUri, oUQ
  842. Else
  843. Set oUQ = m_dictUriList.Item(strExpectedUri)
  844. End If
  845. oUQ.AddQuestion strUserQuery
  846. rsQs.MoveNext
  847. Loop
  848. End Sub
  849. Private Sub p_GetPrioKw( _
  850. ByRef oDomHht As IXMLDOMNode, _
  851. ByRef o_lngKwHht As Long, _
  852. ByRef o_lngKwPriHht As Long, _
  853. ByRef o_lngKwGt12k As Long, _
  854. ByRef o_lngKwEq10k As Long, _
  855. ByRef o_lngKwEq5k As Long, _
  856. ByRef o_lngKwEq3_3k As Long _
  857. )
  858. Dim oListKW As IXMLDOMNodeList
  859. Set oListKW = oDomHht.selectNodes("//KEYWORD")
  860. If (Not oListKW Is Nothing) Then
  861. o_lngKwHht = oListKW.length
  862. End If
  863. Set oListKW = oDomHht.selectNodes("//KEYWORD[ @PRIORITY ]")
  864. If (Not oListKW Is Nothing) Then
  865. o_lngKwPriHht = oListKW.length
  866. End If
  867. Set oListKW = oDomHht.selectNodes("//KEYWORD[ @PRIORITY > 12000 ]")
  868. If (Not oListKW Is Nothing) Then
  869. o_lngKwGt12k = oListKW.length
  870. End If
  871. Set oListKW = oDomHht.selectNodes("//KEYWORD[ @PRIORITY = 10000 ]")
  872. If (Not oListKW Is Nothing) Then
  873. o_lngKwEq10k = oListKW.length
  874. End If
  875. Set oListKW = oDomHht.selectNodes("//KEYWORD[ @PRIORITY = 5000 ]")
  876. If (Not oListKW Is Nothing) Then
  877. o_lngKwEq5k = oListKW.length
  878. End If
  879. Set oListKW = oDomHht.selectNodes("//KEYWORD[ @PRIORITY = 3333 ]")
  880. If (Not oListKW Is Nothing) Then
  881. o_lngKwEq3_3k = oListKW.length
  882. End If
  883. End Sub
  884. Public Function p_RemoveStopSigns( _
  885. ByVal i_strText As String _
  886. ) As String
  887. Dim intIndex As Long
  888. Dim intLength As Long
  889. Dim str As String
  890. Dim char As String
  891. str = i_strText
  892. intLength = Len(str)
  893. For intIndex = intLength To 1 Step -1
  894. char = Mid$(str, intIndex, 1)
  895. If (dictStopSigns.Exists(char)) Then
  896. If (dictStopSigns(char) = CONTEXT_ANYWHERE_E) Then
  897. ' Replace the character with a space
  898. str = Mid$(str, 1, intIndex - 1) & " " & Mid$(str, intIndex + 1)
  899. ElseIf (intIndex > 1) Then
  900. ' Context is CONTEXT_AT_END_OF_WORD_E, and this isn't the first char
  901. If (Mid$(str, intIndex - 1, 1) <> " ") Then
  902. ' Previous character is not a space
  903. If ((intIndex = intLength) Or (Mid$(str, intIndex + 1, 1) = " ")) Then
  904. ' This is the last character or the next character is a space
  905. ' Replace the character with a space
  906. str = Mid$(str, 1, intIndex - 1) & " " & Mid$(str, intIndex + 1)
  907. End If
  908. End If
  909. End If
  910. End If
  911. Next
  912. p_RemoveStopSigns = str
  913. End Function
  914. Sub p_LoadStopSigns(ByRef oDomtaxo As DOMDocument)
  915. On Error Resume Next
  916. Dim oDomNode As IXMLDOMNode, oNodeList As IXMLDOMNodeList
  917. Dim l As Long
  918. WriteStatus "Loading Stop Signs"
  919. If (dictStopSigns Is Nothing) Then
  920. Set dictStopSigns = New Scripting.Dictionary
  921. End If
  922. Set oNodeList = oDomtaxo.selectNodes("/METADATA/STOPSIGN_ENTRIES/*")
  923. For Each oDomNode In oNodeList
  924. If (oDomNode.Attributes.getNamedItem("CONTEXT").Text = "ENDOFWORD") Then
  925. l = CONTEXT_AT_END_OF_WORD_E
  926. Else
  927. l = CONTEXT_ANYWHERE_E
  928. End If
  929. dictStopSigns.Add oDomNode.Attributes.getNamedItem("STOPSIGN").Text, l
  930. Next
  931. End Sub
  932. Sub p_LoadStopWords(ByRef oDomtaxo As DOMDocument)
  933. On Error Resume Next
  934. Dim oDomNode As IXMLDOMNode, oNodeList As IXMLDOMNodeList
  935. WriteStatus "Loading Stop Words"
  936. If (g_dictStopWords Is Nothing) Then
  937. Set g_dictStopWords = New Scripting.Dictionary
  938. End If
  939. g_dictStopWords.CompareMode = BinaryCompare
  940. Set oNodeList = oDomtaxo.selectNodes("/METADATA/STOPWORD_ENTRIES/*")
  941. For Each oDomNode In oNodeList
  942. g_dictStopWords.Add LCase$(oDomNode.Attributes.getNamedItem("STOPWORD").Text), True
  943. Next
  944. End Sub
  945. Sub p_LoadVerbalOperators(ByRef oDomtaxo As DOMDocument)
  946. On Error Resume Next
  947. Dim oDomNode As IXMLDOMNode, oNodeList As IXMLDOMNodeList
  948. Dim strOperation As String
  949. Dim strOperator As String
  950. WriteStatus "Loading Verbal Operators"
  951. Set oNodeList = oDomtaxo.selectNodes("/METADATA/OPERATOR_ENTRIES/*")
  952. For Each oDomNode In oNodeList
  953. strOperation = UCase$(oDomNode.Attributes.getNamedItem("OPERATION").nodeValue)
  954. strOperator = oDomNode.Attributes.getNamedItem("OPERATOR").nodeValue
  955. Select Case strOperation
  956. Case "AND"
  957. If (strOperatorsAnd = "") Then
  958. strOperatorsAnd = strOperator
  959. Else
  960. strOperatorsAnd = strOperatorsAnd & ";" & strOperator
  961. End If
  962. Case "OR"
  963. If (strOperatorsOr = "") Then
  964. strOperatorsOr = strOperator
  965. Else
  966. strOperatorsOr = strOperatorsOr & ";" & strOperator
  967. End If
  968. Case "NOT"
  969. If (strOperatorsNot = "") Then
  970. strOperatorsNot = strOperator
  971. Else
  972. strOperatorsNot = strOperatorsNot & ";" & strOperator
  973. End If
  974. End Select
  975. Next
  976. End Sub
  977. Sub p_Xls2Recordset( _
  978. ByVal strXlsFile As String, _
  979. ByVal rs As ADODB.Recordset _
  980. )
  981. Dim cnn As ADODB.Connection
  982. Set cnn = New ADODB.Connection
  983. Dim strErrMsg As String: strErrMsg = ""
  984. If (Not m_fso.FileExists(strXlsFile)) Then
  985. MsgBox "Cannot find " & strXlsFile
  986. GoTo Common_Exit
  987. End If
  988. prgBar.Visible = True
  989. WriteLog "Parsing " & strXlsFile
  990. Dim rs1 As ADODB.Recordset: Set rs1 = New ADODB.Recordset
  991. cnn.Open "DRIVER=Microsoft Excel Driver (*.xls);ReadOnly=0;DBQ=" & _
  992. strXlsFile & ";HDR=0;"
  993. rs1.Open "SELECT * FROM `Sheet1$`", cnn, adOpenStatic, adLockReadOnly
  994. Do While Not rs1.EOF
  995. If (IsNull(rs1("User Query"))) Then
  996. GoTo LContinue
  997. End If
  998. rs.AddNew
  999. rs("User Query") = LCase$(Trim$(rs1("User Query"))) & ""
  1000. rs("Expected Uri") = LCase$(Trim$(rs1("Expected Uri"))) & ""
  1001. rs.Update
  1002. LContinue:
  1003. rs1.MoveNext
  1004. Loop
  1005. rs.Sort = "[User Query],[Expected Uri]"
  1006. Common_Exit:
  1007. End Sub
  1008. Sub p_XlXml2Recordset( _
  1009. ByVal strXlXmlFile As String, _
  1010. ByVal rs As ADODB.Recordset _
  1011. )
  1012. Dim strErrMsg As String: strErrMsg = ""
  1013. If (Not m_fso.FileExists(strXlXmlFile)) Then
  1014. MsgBox "Cannot find " & strXlXmlFile
  1015. GoTo Common_Exit
  1016. End If
  1017. prgBar.Visible = True
  1018. WriteLog "Parsing " & strXlXmlFile
  1019. Dim oDomXlXml As DOMDocument: Set oDomXlXml = GetXmlFile(strXlXmlFile)
  1020. ' first we Find the Names of the rows
  1021. Dim oDomNodeWorksheet As IXMLDOMNode
  1022. Dim oDomWksList As IXMLDOMNodeList
  1023. Set oDomWksList = oDomXlXml.selectNodes("/Workbook/Worksheet")
  1024. Set oDomNodeWorksheet = oDomWksList.Item(0)
  1025. ' Now we need to get to the first row to read the column names
  1026. ' and lock up the output HSCSearchTester Columns from there
  1027. Dim oDomRowList As IXMLDOMNodeList
  1028. Set oDomRowList = oDomNodeWorksheet.selectNodes("Table/Row")
  1029. Dim oDomCellDataList As IXMLDOMNodeList
  1030. Set oDomCellDataList = oDomRowList.Item(0).selectNodes("Cell/Data")
  1031. Const xlUserQuery As Integer = 2 ^ 0, _
  1032. xlExpectedUri As Integer = 2 ^ 1
  1033. Dim xlInputColumns As Integer: xlInputColumns = 0
  1034. Dim ixColUserQuery As Integer
  1035. Dim ixColExpectedUri As Integer
  1036. Dim lx As Long: lx = 0
  1037. Dim oDomCellData As IXMLDOMNode
  1038. For Each oDomCellData In oDomCellDataList
  1039. Select Case LCase$(oDomCellData.Text)
  1040. Case "user query"
  1041. xlInputColumns = (xlInputColumns Or xlUserQuery)
  1042. ixColUserQuery = lx
  1043. Case "uri", "expected uri", "desired uri"
  1044. xlInputColumns = (xlInputColumns Or xlExpectedUri)
  1045. ixColExpectedUri = lx
  1046. End Select
  1047. lx = lx + 1
  1048. Next
  1049. ' We do some validation so that they send us a specific Spreadsheet
  1050. ' format. Namely only column names validation
  1051. If ((xlInputColumns And (xlUserQuery Or xlExpectedUri)) <> _
  1052. (xlUserQuery Or xlExpectedUri)) Then
  1053. WriteLog "Invalid Input XL Spreadsheet.", False
  1054. WriteLog "", False
  1055. WriteLog vbTab + "You must include at least the following columns:", False
  1056. WriteLog vbTab + vbTab + "- User Query", False
  1057. WriteLog vbTab + vbTab + "- Expected URI", False
  1058. WriteLog "", False
  1059. GoTo Common_Exit
  1060. End If
  1061. ' now we dump all Excel Data into the Recordset
  1062. Dim oDomRow As IXMLDOMNode
  1063. lx = 0
  1064. For Each oDomRow In oDomRowList
  1065. If (lx <> 0) Then
  1066. rs.AddNew
  1067. Dim ixCol As Integer: ixCol = 0
  1068. For Each oDomCellData In oDomRow.selectNodes("Cell/Data")
  1069. Select Case ixCol
  1070. Case ixColUserQuery
  1071. rs("User Query") = LCase$(Trim$(oDomCellData.Text))
  1072. Case ixColExpectedUri
  1073. rs("Expected Uri") = LCase$(p_NormalizeUriNotation(Trim$(oDomCellData.Text)))
  1074. End Select
  1075. ixCol = ixCol + 1
  1076. Next
  1077. rs.Update
  1078. End If
  1079. lx = lx + 1
  1080. Next
  1081. ' Some recordset Validations:
  1082. '
  1083. ' We do them here, so when Excel via ADO is integrated we
  1084. ' validate in a single place
  1085. '
  1086. ' we discard:
  1087. ' - all repeats of User Query/URI Pairs and flag as warnings these
  1088. ' - all records that have either an Empty Expected URI or Empty User Query
  1089. ' rs.MoveFirst
  1090. ' Dim strPrevUserQuery As String, strPrevExpectedUri As String, _
  1091. ' strUserQuery As String, strExpectedUri As String
  1092. '
  1093. ' strPrevUserQuery = ""
  1094. ' strPrevExpectedUri = ""
  1095. ' Do While (Not rs.EOF)
  1096. ' strUserQuery = rs("User Query")
  1097. ' strExpectedUri = rs("Expected Uri")
  1098. ' If (Len(strUserQuery) = 0 Or Len(strExpectedUri) = 0) Then
  1099. ' WriteLog "Warning Row[" & rs("XlRow") & "] has empty data and will not be included in set", False
  1100. ' WriteLog vbTab + "User Query = '" + strUserQuery + "'", False
  1101. ' WriteLog vbTab + "Expected Uri = '" + strExpectedUri + "'", False
  1102. ' rs.Delete
  1103. ' rs.Update
  1104. ' ElseIf (strPrevUserQuery = strUserQuery) Then
  1105. ' If (strPrevExpectedUri = strExpectedUri) Then
  1106. ' WriteLog "Warning Row[" & rs("XlRow") & "] is a duplicate and will not be included in set", False
  1107. ' WriteLog vbTab + "User Query = '" + strUserQuery + "'", False
  1108. ' WriteLog vbTab + "Expected Uri = '" + strExpectedUri + "'", False
  1109. ' rs.Delete
  1110. ' rs.Update
  1111. ' Else
  1112. ' strPrevExpectedUri = strExpectedUri
  1113. ' End If
  1114. ' Else
  1115. ' ' strPrevUserQuery <> strUserQuery
  1116. ' strPrevUserQuery = strUserQuery
  1117. ' strPrevExpectedUri = strExpectedUri
  1118. ' End If
  1119. ' rs.MoveNext
  1120. ' Loop
  1121. '
  1122. ' ' BUGBUG: This step should be unneeded, but due to the fact that I already coded
  1123. ' ' the validation using the above sort, I simply re-sort. So
  1124. ' ' the validation above should be reauthored for this order.
  1125. ' ' Now we need Re-sort the Recordset based on URI and User Query.
  1126. ' rs.Sort = "[Expected Uri],[User Query]"
  1127. ' rs.MoveFirst
  1128. Common_Exit:
  1129. End Sub
  1130. Private Function GetXmlFile(ByVal strFile As String) As DOMDocument
  1131. Set GetXmlFile = Nothing
  1132. Dim oDomDoc As DOMDocument: Set oDomDoc = New DOMDocument
  1133. oDomDoc.async = False
  1134. oDomDoc.Load strFile
  1135. If (oDomDoc.parseError <> 0) Then
  1136. p_DisplayParseError oDomDoc.parseError
  1137. GoTo Common_Exit
  1138. End If
  1139. Set GetXmlFile = oDomDoc
  1140. Common_Exit:
  1141. End Function
  1142. '============= Utilities =============
  1143. Private Sub p_DisplayParseError( _
  1144. ByRef i_ParseError As IXMLDOMParseError _
  1145. )
  1146. Dim strError As String
  1147. strError = "Error: " & i_ParseError.reason & _
  1148. "Line: " & i_ParseError.Line & vbCrLf & _
  1149. "Linepos: " & i_ParseError.linepos & vbCrLf & _
  1150. "srcText: " & i_ParseError.srcText
  1151. MsgBox strError, vbOKOnly, "Error while parsing"
  1152. End Sub