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.

607 lines
16 KiB

  1. Attribute VB_Name = "Database"
  2. Option Explicit
  3. Private p_cnn As ADODB.Connection
  4. Private p_intSKU As Long
  5. Private p_intAuthoringGroup As Long
  6. Private p_strUserName As String
  7. Private p_dictStopSigns As Scripting.Dictionary
  8. Private p_dictStopWords As Scripting.Dictionary
  9. Private p_dictKeywords As Scripting.Dictionary
  10. Private p_dictSynonymSets As Scripting.Dictionary
  11. Private p_dictSynonyms As Scripting.Dictionary
  12. Private p_dictTaxonomyNodes As Scripting.Dictionary
  13. Private Const EID_KID_SEPARATOR_C As String = "/"
  14. Private Const KEY_PREFIX_C As String = "KEY"
  15. Private Const ROOT_KEY_C As String = "KEY1"
  16. Private Const SYNONYM_C As String = "SYNONYM"
  17. Private Const SUPER_KEYWORD_C As String = "SuperKeyword"
  18. Private Const SYNSET_ID_C As String = "ID"
  19. Private Const HHT_OPERATOR_C As String = "OPERATOR"
  20. Private Const HHT_OPERATION_C As String = "OPERATION"
  21. Private Const OPERATOR_SEPARATOR_C As String = ";"
  22. Public Sub OpenDatabaseAndSetSKU( _
  23. ByVal i_strDatabase As String, _
  24. ByVal i_intSKU As Long _
  25. )
  26. On Error GoTo LError
  27. p_AllocateDBGlobals
  28. p_cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  29. "Data Source=" & i_strDatabase & ";"
  30. p_intSKU = i_intSKU
  31. p_intAuthoringGroup = GetParameter(p_cnn, AUTHORING_GROUP_C)
  32. p_strUserName = GetUserName1
  33. p_ReadDatabase
  34. LEnd:
  35. Exit Sub
  36. LError:
  37. Err.Raise E_FAIL, , "Unable to open database " & i_strDatabase & ": " & Err.Description
  38. End Sub
  39. Public Sub ImportTaxonomyEntry( _
  40. ByVal i_DOMNode As MSXML2.IXMLDOMNode _
  41. )
  42. On Error GoTo LError
  43. Dim rs As ADODB.Recordset
  44. Dim strQuery As String
  45. Dim intParentTID As Long
  46. Dim intOrderUnderParent As Long
  47. Dim strCategory As String
  48. Dim strEntry As String
  49. Dim strNewCategory As String
  50. Dim strVisible As String
  51. Dim strSubSite As String
  52. Dim blnLeaf As Boolean
  53. Dim intTID As Long
  54. strCategory = XMLGetAttribute(i_DOMNode, HHT_CATEGORY_C)
  55. If (Not p_dictTaxonomyNodes.Exists(strCategory)) Then
  56. Err.Raise E_FAIL, , "Category " & strCategory & " doesn't exist"
  57. Exit Sub
  58. End If
  59. intParentTID = p_dictTaxonomyNodes(strCategory)(0)
  60. intOrderUnderParent = p_dictTaxonomyNodes(strCategory)(1)
  61. Set rs = New ADODB.Recordset
  62. strQuery = "" & _
  63. "SELECT * " & _
  64. "FROM Taxonomy"
  65. rs.Open strQuery, p_cnn, adOpenForwardOnly, adLockOptimistic
  66. strEntry = XMLGetAttribute(i_DOMNode, HHT_ENTRY_C)
  67. blnLeaf = IIf((strEntry = ""), True, False)
  68. strVisible = XMLGetAttribute(i_DOMNode, HHT_VISIBLE_C)
  69. strSubSite = XMLGetAttribute(i_DOMNode, HHT_SUBSITE_C)
  70. rs.AddNew
  71. rs("ModifiedTime") = Now
  72. rs("Comments") = ""
  73. rs("ENUTitle") = p_GetValue(i_DOMNode, HHT_TITLE_C)
  74. rs("ENUDescription") = p_GetValue(i_DOMNode, HHT_DESCRIPTION_C)
  75. rs("Type") = XMLGetAttribute(i_DOMNode, HHT_TYPE_C)
  76. rs("ContentURI") = XMLGetAttribute(i_DOMNode, HHT_URI_C)
  77. rs("SKUs") = p_intSKU
  78. rs("ParentTID") = intParentTID
  79. rs("Leaf") = blnLeaf
  80. rs("BaseFile") = ""
  81. rs("LocInclude") = LOC_INCLUDE_ALL_C
  82. rs("Visible") = IIf((strVisible = ""), True, strVisible)
  83. rs("Keywords") = GetKeywords(p_cnn, i_DOMNode, p_dictKeywords)
  84. rs("OrderUnderParent") = intOrderUnderParent
  85. rs("AuthoringGroup") = p_intAuthoringGroup
  86. rs("IconURI") = XMLGetAttribute(i_DOMNode, HHT_ICONURI_C)
  87. rs("SubSite") = IIf((strSubSite = ""), False, strSubSite)
  88. rs("Username") = p_strUserName
  89. rs("Entry") = strEntry
  90. rs("NavigationModel") = p_GetNavigationModel(i_DOMNode)
  91. rs.Update
  92. intTID = rs("TID")
  93. p_dictTaxonomyNodes(strCategory) = Array(intParentTID, intOrderUnderParent + 1)
  94. If (Not blnLeaf) Then
  95. strNewCategory = strCategory
  96. If (strNewCategory <> "") Then
  97. strNewCategory = strNewCategory & "/" & strEntry
  98. Else
  99. strNewCategory = strEntry
  100. End If
  101. p_dictTaxonomyNodes.Add strNewCategory, Array(intTID, MAX_ORDER_C)
  102. End If
  103. LEnd:
  104. Exit Sub
  105. LError:
  106. Err.Raise E_FAIL, , "While importing " & i_DOMNode.XML & ": " & Err.Description
  107. End Sub
  108. Public Sub ImportOperators( _
  109. ByVal i_DOMNodeList As MSXML2.IXMLDOMNodeList _
  110. )
  111. Dim strOperator As String
  112. Dim strOperation As String
  113. Dim strOperatorsAnd As String
  114. Dim strOperatorsOr As String
  115. Dim strOperatorsNot As String
  116. Dim DOMNode As MSXML2.IXMLDOMNode
  117. strOperatorsAnd = GetParameter(p_cnn, OPERATORS_AND_C) & ""
  118. strOperatorsOr = GetParameter(p_cnn, OPERATORS_OR_C) & ""
  119. strOperatorsNot = GetParameter(p_cnn, OPERATORS_NOT_C) & ""
  120. For Each DOMNode In i_DOMNodeList
  121. strOperator = XMLGetAttribute(DOMNode, HHT_OPERATOR_C)
  122. strOperation = UCase$(XMLGetAttribute(DOMNode, HHT_OPERATION_C))
  123. Select Case strOperation
  124. Case "AND"
  125. If (strOperatorsAnd = "") Then
  126. strOperatorsAnd = strOperator
  127. Else
  128. strOperatorsAnd = strOperatorsAnd & OPERATOR_SEPARATOR_C & strOperator
  129. End If
  130. Case "OR"
  131. If (strOperatorsOr = "") Then
  132. strOperatorsOr = strOperator
  133. Else
  134. strOperatorsOr = strOperatorsOr & OPERATOR_SEPARATOR_C & strOperator
  135. End If
  136. Case "NOT"
  137. If (strOperatorsNot = "") Then
  138. strOperatorsNot = strOperator
  139. Else
  140. strOperatorsNot = strOperatorsNot & OPERATOR_SEPARATOR_C & strOperator
  141. End If
  142. End Select
  143. Next
  144. SetParameter p_cnn, OPERATORS_AND_C, strOperatorsAnd
  145. SetParameter p_cnn, OPERATORS_OR_C, strOperatorsOr
  146. SetParameter p_cnn, OPERATORS_NOT_C, strOperatorsNot
  147. End Sub
  148. Public Sub ImportStopSign( _
  149. ByVal i_DOMNode As MSXML2.IXMLDOMNode _
  150. )
  151. Dim strStopSign As String
  152. Dim strContext As String
  153. Dim intContext As Long
  154. Dim rs As ADODB.Recordset
  155. Dim strQuery As String
  156. strStopSign = XMLGetAttribute(i_DOMNode, HHT_STOPSIGN_C)
  157. strContext = UCase$(XMLGetAttribute(i_DOMNode, HHT_CONTEXT_C))
  158. Select Case strContext
  159. Case HHTVAL_ANYWHERE_C
  160. intContext = CONTEXT_ANYWHERE_E
  161. Case Else
  162. intContext = CONTEXT_AT_END_OF_WORD_E
  163. End Select
  164. If (p_dictStopSigns.Exists(strStopSign)) Then
  165. If (p_dictStopSigns(strStopSign) <> intContext) Then
  166. frmMain.Output "Existing StopSign """ & strStopSign & """ has opposite context", LOGGING_TYPE_WARNING_E
  167. End If
  168. Exit Sub
  169. End If
  170. Set rs = New ADODB.Recordset
  171. strQuery = "" & _
  172. "SELECT * " & _
  173. "FROM StopSigns"
  174. rs.Open strQuery, p_cnn, adOpenForwardOnly, adLockOptimistic
  175. rs.AddNew
  176. rs("StopSign") = strStopSign
  177. rs("Context") = intContext
  178. rs.Update
  179. p_dictStopSigns.Add strStopSign, intContext
  180. End Sub
  181. Public Sub ImportStopWord( _
  182. ByVal i_DOMNode As MSXML2.IXMLDOMNode _
  183. )
  184. Dim strStopWord As String
  185. Dim rs As ADODB.Recordset
  186. Dim strQuery As String
  187. strStopWord = XMLGetAttribute(i_DOMNode, HHT_STOPWORD_C)
  188. If (p_dictStopWords.Exists(strStopWord)) Then
  189. Exit Sub
  190. End If
  191. Set rs = New ADODB.Recordset
  192. strQuery = "" & _
  193. "SELECT * " & _
  194. "FROM StopWords"
  195. rs.Open strQuery, p_cnn, adOpenForwardOnly, adLockOptimistic
  196. rs.AddNew
  197. rs("StopWord") = strStopWord
  198. rs.Update
  199. p_dictStopWords.Add strStopWord, True
  200. End Sub
  201. Public Sub ImportSynset( _
  202. ByVal i_DOMNode As MSXML2.IXMLDOMNode _
  203. )
  204. ' The error handling is a hack. It is required, because a synonym set may have
  205. ' 2 keywords: "800 X 600" and "800 x 600". However, they are the same keyword.
  206. ' So rs2.Update will fail. The solution is to remember that we have already
  207. ' created the synonym and not try to create it again.
  208. On Error Resume Next
  209. Dim rs1 As ADODB.Recordset
  210. Dim rs2 As ADODB.Recordset
  211. Dim strQuery As String
  212. Dim intEID As Long
  213. Dim intKID As Long
  214. Dim DOMNode As MSXML2.IXMLDOMNode
  215. Dim strKeyword As String
  216. ' Dim blnSynonymSetNamed As Boolean
  217. intEID = XMLGetAttribute(i_DOMNode, SYNSET_ID_C)
  218. Set rs1 = New ADODB.Recordset
  219. strQuery = "" & _
  220. "SELECT * " & _
  221. "FROM SynonymSets"
  222. rs1.Open strQuery, p_cnn, adOpenForwardOnly, adLockOptimistic
  223. rs1.AddNew
  224. rs1("Name") = "Not named yet"
  225. rs1("EID") = intEID
  226. rs1.Update
  227. Set rs2 = New ADODB.Recordset
  228. strQuery = "" & _
  229. "SELECT * " & _
  230. "FROM Synonyms"
  231. rs2.Open strQuery, p_cnn, adOpenForwardOnly, adLockOptimistic
  232. If (Not i_DOMNode.firstChild Is Nothing) Then
  233. For Each DOMNode In i_DOMNode.childNodes
  234. If (DOMNode.baseName = SYNONYM_C) Then
  235. strKeyword = DOMNode.Text
  236. If (strKeyword <> "") Then
  237. intKID = GetKID(p_cnn, strKeyword, p_dictKeywords)
  238. rs2.AddNew
  239. rs2("EID") = intEID
  240. rs2("KID") = intKID
  241. rs2.Update
  242. ' If (Not blnSynonymSetNamed) Then
  243. ' rs1("Name") = strKeyword
  244. ' rs1.Update
  245. ' blnSynonymSetNamed = True
  246. ' End If
  247. End If
  248. ElseIf (DOMNode.baseName = SUPER_KEYWORD_C) Then
  249. rs1("Name") = DOMNode.Text
  250. rs1.Update
  251. End If
  252. Next
  253. End If
  254. End Sub
  255. Public Sub SetDomFragment( _
  256. ByVal i_strXML As String _
  257. )
  258. Dim strName As String
  259. Dim strXML As String
  260. strName = DOM_FRAGMENT_HHT_C & p_intSKU
  261. strXML = GetParameter(p_cnn, strName) & vbCrLf & i_strXML
  262. SetParameter p_cnn, strName, strXML
  263. End Sub
  264. Public Sub FinalizeDatabase( _
  265. )
  266. FixOrderingNumbers p_cnn
  267. End Sub
  268. Private Function p_GetValue( _
  269. ByVal i_DOMNode As MSXML2.IXMLDOMNode, _
  270. ByVal i_strName As String _
  271. ) As String
  272. On Error Resume Next
  273. Dim str As String
  274. str = XMLGetAttribute(i_DOMNode, i_strName)
  275. If (str = "") Then
  276. str = i_DOMNode.selectSingleNode(i_strName).Text
  277. End If
  278. p_GetValue = str
  279. End Function
  280. Private Function p_GetNavigationModel( _
  281. ByVal i_DOMNode As MSXML2.IXMLDOMNode _
  282. ) As Long
  283. Dim str As String
  284. str = LCase$(XMLGetAttribute(i_DOMNode, HHT_NAVIGATIONMODEL_C))
  285. Select Case str
  286. Case NAVMODEL_SERVER_STR_C
  287. p_GetNavigationModel = NAVMODEL_SERVER_NUM_C
  288. Case NAVMODEL_DESKTOP_STR_C
  289. p_GetNavigationModel = NAVMODEL_DESKTOP_NUM_C
  290. Case Else
  291. p_GetNavigationModel = NAVMODEL_DEFAULT_NUM_C
  292. End Select
  293. End Function
  294. Private Sub p_AllocateDBGlobals()
  295. Set p_cnn = New ADODB.Connection
  296. Set p_dictStopSigns = New Scripting.Dictionary
  297. Set p_dictStopWords = New Scripting.Dictionary
  298. p_dictStopWords.CompareMode = TextCompare
  299. Set p_dictKeywords = New Scripting.Dictionary
  300. p_dictKeywords.CompareMode = TextCompare
  301. Set p_dictSynonymSets = New Scripting.Dictionary
  302. Set p_dictSynonyms = New Scripting.Dictionary
  303. Set p_dictTaxonomyNodes = New Scripting.Dictionary
  304. p_dictTaxonomyNodes.CompareMode = TextCompare
  305. End Sub
  306. Private Sub p_ReadDatabase()
  307. p_ReadStopSigns
  308. p_ReadStopWords
  309. p_ReadKeywords
  310. p_ReadSynonymSets
  311. p_ReadSynonyms
  312. p_ReadTaxonomyNodes
  313. End Sub
  314. Private Sub p_ReadStopSigns()
  315. Dim rs As ADODB.Recordset
  316. Dim strQuery As String
  317. frmMain.Output "Reading existing Stop Signs", LOGGING_TYPE_NORMAL_E
  318. Set rs = New ADODB.Recordset
  319. strQuery = "" & _
  320. "SELECT * " & _
  321. "FROM StopSigns"
  322. rs.Open strQuery, p_cnn, adOpenForwardOnly, adLockReadOnly
  323. Do While (Not rs.EOF)
  324. p_dictStopSigns.Add rs("StopSign").Value, rs("Context").Value
  325. DoEvents
  326. rs.MoveNext
  327. Loop
  328. End Sub
  329. Private Sub p_ReadStopWords()
  330. Dim rs As ADODB.Recordset
  331. Dim strQuery As String
  332. frmMain.Output "Reading existing Stop Words", LOGGING_TYPE_NORMAL_E
  333. Set rs = New ADODB.Recordset
  334. strQuery = "" & _
  335. "SELECT * " & _
  336. "FROM StopWords"
  337. rs.Open strQuery, p_cnn, adOpenForwardOnly, adLockReadOnly
  338. Do While (Not rs.EOF)
  339. p_dictStopWords.Add rs("StopWord").Value, True
  340. DoEvents
  341. rs.MoveNext
  342. Loop
  343. End Sub
  344. Private Sub p_ReadKeywords()
  345. Dim rs As ADODB.Recordset
  346. Dim strQuery As String
  347. frmMain.Output "Reading existing Keywords", LOGGING_TYPE_NORMAL_E
  348. Set rs = New ADODB.Recordset
  349. strQuery = "" & _
  350. "SELECT * " & _
  351. "FROM Keywords"
  352. rs.Open strQuery, p_cnn, adOpenForwardOnly, adLockReadOnly
  353. Do While (Not rs.EOF)
  354. p_dictKeywords.Add rs("Keyword").Value, rs("KID").Value
  355. DoEvents
  356. rs.MoveNext
  357. Loop
  358. End Sub
  359. Private Sub p_ReadSynonymSets()
  360. Dim rs As ADODB.Recordset
  361. Dim strQuery As String
  362. frmMain.Output "Reading existing Synonym Sets", LOGGING_TYPE_NORMAL_E
  363. Set rs = New ADODB.Recordset
  364. strQuery = "" & _
  365. "SELECT * " & _
  366. "FROM SynonymSets"
  367. rs.Open strQuery, p_cnn, adOpenForwardOnly, adLockReadOnly
  368. Do While (Not rs.EOF)
  369. p_dictSynonymSets.Add rs("Name").Value, rs("EID").Value
  370. DoEvents
  371. rs.MoveNext
  372. Loop
  373. End Sub
  374. Private Sub p_ReadSynonyms()
  375. Dim rs As ADODB.Recordset
  376. Dim strQuery As String
  377. frmMain.Output "Reading existing Synonyms", LOGGING_TYPE_NORMAL_E
  378. Set rs = New ADODB.Recordset
  379. strQuery = "" & _
  380. "SELECT * " & _
  381. "FROM Synonyms"
  382. rs.Open strQuery, p_cnn, adOpenForwardOnly, adLockReadOnly
  383. Do While (Not rs.EOF)
  384. p_dictSynonyms.Add rs("EID").Value & EID_KID_SEPARATOR_C & rs("KID").Value, True
  385. DoEvents
  386. rs.MoveNext
  387. Loop
  388. End Sub
  389. Private Sub p_ReadTaxonomyNodes()
  390. Dim rs As ADODB.Recordset
  391. Dim strQuery As String
  392. Dim dict As Scripting.Dictionary
  393. frmMain.Output "Reading existing Taxonomy Nodes", LOGGING_TYPE_NORMAL_E
  394. Set rs = New ADODB.Recordset
  395. Set dict = New Scripting.Dictionary
  396. strQuery = "" & _
  397. "SELECT * " & _
  398. "FROM Taxonomy"
  399. rs.Open strQuery, p_cnn, adOpenForwardOnly, adLockReadOnly
  400. Do While (Not rs.EOF)
  401. If (Not rs("Leaf").Value) Then
  402. dict.Add KEY_PREFIX_C & rs("TID").Value, _
  403. Array("", rs("Entry").Value, rs("ParentTID").Value)
  404. End If
  405. DoEvents
  406. rs.MoveNext
  407. Loop
  408. p_PopulateDictTaxonomyNodes dict
  409. End Sub
  410. Private Sub p_PopulateDictTaxonomyNodes( _
  411. ByVal i_dict As Scripting.Dictionary _
  412. )
  413. Dim vntKey As Variant
  414. Dim intKey As Long
  415. For Each vntKey In i_dict.Keys
  416. p_SetCategory i_dict, vntKey
  417. Next
  418. For Each vntKey In i_dict.Keys
  419. intKey = Mid$(vntKey, 4) ' Get rid of KEY_PREFIX_C
  420. p_dictTaxonomyNodes.Add i_dict(vntKey)(0), Array(intKey, MAX_ORDER_C)
  421. Next
  422. End Sub
  423. Private Sub p_SetCategory( _
  424. ByVal i_dict As Scripting.Dictionary, _
  425. ByVal i_strKey As String _
  426. )
  427. Dim strParentKey As String
  428. Dim strParentCategory As String ' The Category represented by the Node, not the Category of the Node.
  429. Dim strCategory As String
  430. Dim vnt As Variant
  431. If (i_strKey = ROOT_KEY_C) Then
  432. Exit Sub
  433. End If
  434. vnt = i_dict(i_strKey)
  435. strParentKey = KEY_PREFIX_C & vnt(2)
  436. If (i_dict(strParentKey)(0) = "") Then
  437. p_SetCategory i_dict, strParentKey
  438. End If
  439. strParentCategory = i_dict(strParentKey)(0)
  440. If (strParentKey = ROOT_KEY_C) Then
  441. strCategory = vnt(1)
  442. Else
  443. strCategory = strParentCategory & "/" & vnt(1)
  444. End If
  445. i_dict(i_strKey) = Array(strCategory, vnt(1), vnt(2))
  446. End Sub