Sub ABMaterialDocument(sPath As String,pc As String) As ResumableSub
'open the database to work with
Dim helpdb As SQL
helpdb.InitializeSQLite(File.dirapp,"abmaterialhelp.db",True)
'classes
DBUtils.InitializeNewTable("Classes","id","id")
DBUtils.AddFieldOfText("ClassName",True,True)
DBUtils.addfieldoftext("OnPrevious",True,False)
DBUtils.addfieldoftext("OnCurrent",True,False)
DBUtils.addfieldoftext("PVersion",True,False)
DBUtils.addfieldoftext("CVersion",True,False)
DBUtils.AddFieldOfText("Author",True,False)
DBUtils.AddFieldOfText("Comment",True,False)
DBUtils.AddFieldOfText("IsNewClass",True,False)
DBUtils.AddFieldOfText("IsTheme",True,False)
DBUtils.AddFieldOfText("Owner",True,False)
DBUtils.AddFieldOfText("IsLibrary",True,False)
DBUtils.CreateTableFromDefinition(helpdb)
'properties
DBUtils.InitializeNewTable("Properties","id","id")
DBUtils.AddFieldOfText("PropertyKey",True,True)
DBUtils.AddFieldOfText("ClassName",True,False)
DBUtils.AddFieldOfText("PropertyName",True,False)
DBUtils.AddFieldOfText("ReturnType",True,False)
DBUtils.AddFieldOfText("Comment",True,False)
DBUtils.addfieldoftext("OnPrevious",True,False)
DBUtils.addfieldoftext("OnCurrent",True,False)
DBUtils.addfieldoftext("PVersion",True,False)
DBUtils.addfieldoftext("CVersion",True,False)
DBUtils.AddFieldOfText("IsNewClass",True,False)
DBUtils.AddFieldOfText("IsTheme",True,False)
DBUtils.AddFieldOfText("IsLibrary",True,False)
DBUtils.CreateTableFromDefinition(helpdb)
'fields
DBUtils.InitializeNewTable("Fields","id","id")
DBUtils.AddFieldOfText("FieldKey",True,True)
DBUtils.AddFieldOfText("ClassName",True,False)
DBUtils.AddFieldOfText("FieldName",True,False)
DBUtils.AddFieldOfText("ReturnType",True,False)
DBUtils.AddFieldOfText("Comment",True,False)
DBUtils.addfieldoftext("OnPrevious",True,False)
DBUtils.addfieldoftext("OnCurrent",True,False)
DBUtils.addfieldoftext("PVersion",True,False)
DBUtils.addfieldoftext("CVersion",True,False)
DBUtils.addfieldoftext("OnProperties",True,False)
DBUtils.AddFieldOfText("IsNewClass",True,False)
DBUtils.AddFieldOfText("IsTheme",True,False)
DBUtils.AddFieldOfText("IsLibrary",True,False)
DBUtils.CreateTableFromDefinition(helpdb)
'methods
DBUtils.InitializeNewTable("Methods","id","id")
DBUtils.AddFieldOfText("MethodKey",True,True)
DBUtils.AddFieldOfText("ClassName",True,False)
DBUtils.AddFieldOfText("MethodName",True,False)
DBUtils.AddFieldOfText("ReturnType",True,False)
DBUtils.AddFieldOfText("Comment",True,False)
DBUtils.addfieldoftext("OnPrevious",True,False)
DBUtils.addfieldoftext("OnCurrent",True,False)
DBUtils.addfieldoftext("PVersion",True,False)
DBUtils.addfieldoftext("CVersion",True,False)
DBUtils.addfieldoftext("PParameters",True,False)
DBUtils.addfieldoftext("CParameters",True,False)
DBUtils.addfieldoftext("ParametersMatch",True,False)
DBUtils.AddFieldOfText("IsNewClass",True,False)
DBUtils.AddFieldOfText("IsTheme",True,False)
DBUtils.AddFieldOfText("IsLibrary",True,False)
DBUtils.CreateTableFromDefinition(helpdb)
'events
'fields
DBUtils.InitializeNewTable("Events","id","id")
DBUtils.AddFieldOfText("EventKey",True,True)
DBUtils.AddFieldOfText("ClassName",True,False)
DBUtils.AddFieldOfText("EventName",True,False)
DBUtils.AddFieldOfText("Comment",True,False)
DBUtils.addfieldoftext("OnPrevious",True,False)
DBUtils.addfieldoftext("OnCurrent",True,False)
DBUtils.addfieldoftext("PVersion",True,False)
DBUtils.addfieldoftext("CVersion",True,False)
DBUtils.addfieldoftext("PParameters",True,False)
DBUtils.addfieldoftext("CParameters",True,False)
DBUtils.addfieldoftext("ParametersMatch",True,False)
DBUtils.AddFieldOfText("IsNewClass",True,False)
DBUtils.AddFieldOfText("IsTheme",True,False)
DBUtils.AddFieldOfText("IsLibrary",True,False)
DBUtils.CreateTableFromDefinition(helpdb)
'clear the tables if we on previous version
If pc = "p" Then
'clear the tables
DBUtils.TableClear(helpdb,"Classes")
DBUtils.TableClear(helpdb,"Fields")
DBUtils.TableClear(helpdb,"Methods")
DBUtils.TableClear(helpdb,"Properties")
DBUtils.TableClear(helpdb,"Events")
End If
Dim classList1 As List
classList1.initialize
Dim classList2 As List
classList2.initialize
Dim propList1 As List
propList1.initialize
Dim propList2 As List
propList2.initialize
Dim fldList1 As List
fldList1.initialize
Dim fldList2 As List
fldList2.initialize
Dim mthList1 As List
mthList1.initialize
Dim mthList2 As List
mthList2.initialize
Dim eventList1 As List
eventList1.initialize
Dim eventList2 As List
eventList2.initialize
'start processing
Dim xm As Xml2Map
xm.Initialize
Dim ParsedData As Map = xm.Parse(File.ReadString("", sPath))
'get all the class names
Dim root As Map = ParsedData.Get("root")
Dim class As List = root.Get("class")
Dim version As String = root.Get("version")
Dim author As String = root.Get("author")
For Each colclass As Map In class
'get the name of the clas
Dim classname As String = colclass.Get("name")
Dim comment As String = colclass.Getdefault("comment","")
Dim owner As String = colclass.Getdefault("owner","")
'the short name might be blan
classname = jMash.MvLast(".",classname)
'add class to databse
Dim newclass As Map
newclass.initialize
newclass.put("ClassName",classname)
newclass.put("Author",author)
newclass.put("owner",owner)
If comment.length > 0 Then newclass.put("Comment",comment)
If pc = "p" Then
newclass.Put("OnPrevious","Y")
newclass.put("OnCurrent","N")
newclass.put("PVersion",version)
newclass.put("CVersion","")
classList1.add(newclass)
else if pc = "c" Then
newclass.put("OnCurrent","Y")
newclass.put("CVersion",version)
classList2.add(newclass)
End If
'get all the properties for the class
Dim property As List = jMash.GetElements(colclass,"property")
For Each colproperty As Map In property
Dim propname As String = colproperty.Getdefault("name","")
Dim returntype As String = colproperty.Getdefault("returntype","")
If returntype.length > 0 Then returntype = jMash.MvLast(".",returntype)
Dim comment As String = colproperty.Getdefault("comment","")
'Log(shortname & "." & propname & "-" & returntype)
Dim newprop As Map
newprop.initialize
newprop.put("PropertyKey",$"${classname}.${propname}"$)
newprop.put("ClassName",classname)
newprop.put("PropertyName",propname)
newprop.put("ReturnType",returntype)
If comment.length > 0 Then newprop.put("Comment",comment)
If pc = "p" Then
newprop.put("OnPrevious","Y")
newprop.put("PVersion",version)
newprop.put("OnCurrent","N")
newprop.put("CVersion","")
propList1.add(newprop)
Else If pc = "c" Then
newprop.put("OnCurrent","Y")
newprop.put("CVersion",version)
propList2.add(newprop)
End If
Next
'Log("*****fields*****")
'get all the fields for the class
Dim field As List = jMash.GetElements(colclass,"field")
For Each colfield As Map In field
Dim fldname As String = colfield.Getdefault("name","")
Dim returntype As String = colfield.Getdefault("returntype","")
If returntype.length > 0 Then returntype = jMash.MvLast(".",returntype)
Dim comment As String = colfield.Getdefault("comment","")
'Log(shortname & "." & fldname & "-" & returntype)
Dim newfld As Map
newfld.initialize
newfld.put("FieldKey",$"${classname}.${fldname}"$)
newfld.put("ClassName",classname)
newfld.put("FieldName",fldname)
newfld.put("ReturnType",returntype)
newfld.put("OnProperties","N")
If comment.length > 0 Then newfld.put("Comment",comment)
If pc = "p" Then
newfld.put("OnPrevious","Y")
newfld.put("PVersion",version)
newfld.put("OnCurrent","N")
newfld.put("CVersion","")
fldList1.add(newfld)
Else If pc = "c" Then
newfld.put("OnCurrent","Y")
newfld.put("CVersion",version)
fldList2.add(newfld)
End If
Next
'get all methods
Dim method As List = jMash.GetElements(colclass,"method")
For Each colmethod As Map In method
Dim methodname As String = colmethod.Getdefault("name","")
Dim returntype As String = colmethod.Getdefault("returntype","")
If returntype.length > 0 Then returntype = jMash.MvLast(".",returntype)
Dim comment As String = colmethod.Getdefault("comment","")
'Log(shortname & "." & name & "-" & returntype)
'get the parameters
Dim parameter As List = jMash.GetElements(colmethod,"parameter")
Dim parDefStr As String
Dim parDef As List
parDef.Initialize
For Each colparameter As Map In parameter
Dim parname As String = colparameter.Getdefault("name","")
Dim partype As String = colparameter.Getdefault("type","")
If partype.length > 0 Then partype = jMash.MvLast(".",partype)
If parname.length > 0 And partype.length > 0 Then
Dim sLine As String = $"${parname} As ${partype}"$
parDef.Add(sLine)
End If
'Log(shortname & "." & name & "." & parname)
Next
parDefStr = jMash.Join(",",parDef)
Dim mtdmap As Map
mtdmap.initialize
mtdmap.put("MethodKey",$"${classname}.${methodname}"$)
mtdmap.put("ClassName",classname)
mtdmap.put("MethodName",methodname)
mtdmap.put("ReturnType",returntype)
If comment.length > 0 Then mtdmap.put("Comment",comment)
If pc = "p" Then
mtdmap.put("OnPrevious","Y")
mtdmap.put("PVersion",version)
mtdmap.put("OnCurrent","N")
mtdmap.put("CVersion","")
mtdmap.put("PParameters", parDefStr)
mtdmap.put("CParameters", "")
mtdmap.put("ParametersMatch","Y")
mthList1.add(mtdmap)
Else If pc = "c" Then
mtdmap.put("OnCurrent","Y")
mtdmap.put("CVersion",version)
mtdmap.put("CParameters", parDefStr)
mthList2.add(mtdmap)
End If
Next
'get all events
'Log("*****events*****")
Dim event As List = jMash.GetElements(colclass,"event")
For Each colevent As String In event
'find the first open bracket
Dim openb As Int = jMash.instr(colevent,"(")
Dim eventName As String = jMash.Left(colevent,openb)
Dim paramdef As String = jMash.Mid(colevent,openb+2)
paramdef = jMash.RemDelim(paramdef,")")
'Log(shortname & "." & colevent)
Dim eventmap As Map
eventmap.initialize
eventmap.put("EventKey",$"${classname}.${eventName}"$)
eventmap.put("ClassName",classname)
eventmap.put("EventName",eventName)
eventmap.put("Comment","")
If pc = "p" Then
eventmap.put("OnPrevious","Y")
eventmap.put("PVersion",version)
eventmap.put("OnCurrent","N")
eventmap.put("CVersion","")
eventmap.put("PParameters",paramdef)
eventmap.Put("CParameters","")
eventmap.put("ParametersMatch","Y")
eventList1.add(eventmap)
Else If pc = "c" Then
eventmap.put("OnCurrent","Y")
eventmap.put("CVersion",version)
eventmap.put("CParameters", paramdef)
eventList2.add(eventmap)
End If
Next
Next
'add all the classes
If pc = "p" Then
DBUtils.InsertMaps(helpdb,"Classes",classList1)
DBUtils.InsertMaps(helpdb,"Properties",propList1)
DBUtils.InsertMaps(helpdb,"Fields",fldList1)
DBUtils.InsertMaps(helpdb,"Methods",mthList1)
DBUtils.InsertMaps(helpdb,"Events",eventList1)
else if pc = "c" Then
DBUtils.InsertMaps(helpdb,"Classes",classList2)
DBUtils.InsertMaps(helpdb,"Properties",propList2)
DBUtils.InsertMaps(helpdb,"Fields",fldList2)
DBUtils.InsertMaps(helpdb,"Methods",mthList2)
DBUtils.InsertMaps(helpdb,"Events",eventList2)
helpdb.BeginTransaction
For Each classMap As Map In classList2
Dim classname As String = classMap.get("ClassName")
DBUtils.UpdateRecord4(helpdb,"Classes",CreateMap("OnCurrent":"Y","CVersion":version),CreateMap("ClassName":classname))
Next
For Each propMap As Map In propList2
Dim PropertyKey As String = propMap.get("PropertyKey")
DBUtils.UpdateRecord4(helpdb,"Properties",CreateMap("OnCurrent":"Y","CVersion":version),CreateMap("PropertyKey":PropertyKey))
Next
For Each fldMap As Map In fldList2
Dim FieldKey As String = fldMap.get("FieldKey")
DBUtils.UpdateRecord4(helpdb,"Fields",CreateMap("OnCurrent":"Y","CVersion":version),CreateMap("FieldKey":FieldKey))
Next
For Each methodMap As Map In mthList2
Dim MethodKey As String = methodMap.get("MethodKey")
Dim CParameters As String = methodMap.get("CParameters")
DBUtils.UpdateRecord4(helpdb,"Methods",CreateMap("OnCurrent":"Y","CVersion":version,"CParameters":CParameters),CreateMap("MethodKey":MethodKey))
Next
For Each eventmap As Map In eventList2
Dim EventKey As String = eventmap.get("EventKey")
Dim CParameters As String = eventmap.get("CParameters")
DBUtils.UpdateRecord4(helpdb,"Events",CreateMap("OnCurrent":"Y","CVersion":version,"CParameters":CParameters),CreateMap("EventKey":EventKey))
Next
helpdb.TransactionSuccessful
'DBUtils.ExecuteBatch(helpdb)
End If
'delete fields with 'Type' and 'EventHandler'
DBUtils.DeleteRecordWhere(helpdb,"Fields",CreateMap("FieldName":"Type"))
DBUtils.DeleteRecordWhere(helpdb,"Fields",CreateMap("FieldName":"EventHandler"))
'set the defaults
helpdb.BeginTransaction
DBUtils.SetDefault1(helpdb,"Classes",CreateMap("OnPrevious":"'N'","OnCurrent":"'N'","IsTheme":"'N'","IsNewClass":"'N'","IsLibrary":"'N'"))
DBUtils.SetDefault1(helpdb,"Properties",CreateMap("OnPrevious":"'N'","OnCurrent":"'N'","IsTheme":"'N'","IsNewClass":"'N'","IsLibrary":"'N'"))
DBUtils.SetDefault1(helpdb,"Fields",CreateMap("OnPrevious":"'N'","OnCurrent":"'N'","IsTheme":"'N'","IsNewClass":"'N'","IsLibrary":"'N'"))
DBUtils.SetDefault1(helpdb,"Methods",CreateMap("OnPrevious":"'N'","OnCurrent":"'N'","IsTheme":"'N'","IsNewClass":"'N'", _
"PParameters":"''","CParameters":"''","ParametersMatch":"'N'","IsLibrary":"'N'"))
DBUtils.SetDefault1(helpdb,"Events",CreateMap("OnPrevious":"'N'","OnCurrent":"'N'","IsTheme":"'N'","IsNewClass":"'N'", _
"PParameters":"''","CParameters":"''","ParametersMatch":"'N'", "IsLibrary":"'N'"))
helpdb.TransactionSuccessful
'get the names of the new classes, we will update each field if the class is new
'we do this to know which classes where updated
Dim newClasses As List
newClasses = DBUtils.SQLSelectRecordWhereMaps(helpdb,"select classname from Classes",CreateMap("OnCurrent =":"Y","OnPrevious =":"N"))
newClasses = jMash.ListOfMapsExtractKey(newClasses,"classname")
'check if stuff on fields is on properties
helpdb.BeginTransaction
For Each strClass As String In newClasses
DBUtils.UpdateRecord4(helpdb,"Classes",CreateMap("IsNewClass":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Properties",CreateMap("IsNewClass":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Fields",CreateMap("IsNewClass":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Methods",CreateMap("IsNewClass":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Events",CreateMap("IsNewClass":"Y"),CreateMap("ClassName":strClass))
Next
helpdb.TransactionSuccessful
'DBUtils.ExecuteBatch(helpdb)
'update theme related content
Dim newClasses As List
newClasses = DBUtils.SQLSelectRecordWhereMaps(helpdb,"select classname from Classes",CreateMap("ClassName Like":"Theme%"))
newClasses = jMash.ListOfMapsExtractKey(newClasses,"classname")
'check if stuff on fields is on properties
helpdb.BeginTransaction
For Each strClass As String In newClasses
DBUtils.UpdateRecord4(helpdb,"Classes",CreateMap("IsTheme":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Properties",CreateMap("IsTheme":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Fields",CreateMap("IsTheme":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Methods",CreateMap("IsTheme":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Events",CreateMap("IsTheme":"Y"),CreateMap("ClassName":strClass))
Next
helpdb.TransactionSuccessful
'DBUtils.ExecuteBatch(helpdb)
'update theme related content
Dim newClasses As List
newClasses = DBUtils.SQLSelectRecordWhereMaps(helpdb,"select classname from Classes",CreateMap("ClassName Like":"%Theme"))
newClasses = jMash.ListOfMapsExtractKey(newClasses,"classname")
'check if stuff on fields is on properties
helpdb.BeginTransaction
For Each strClass As String In newClasses
DBUtils.UpdateRecord4(helpdb,"Classes",CreateMap("IsTheme":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Properties",CreateMap("IsTheme":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Fields",CreateMap("IsTheme":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Methods",CreateMap("IsTheme":"Y"),CreateMap("ClassName":strClass))
DBUtils.UpdateRecord4(helpdb,"Events",CreateMap("IsTheme":"Y"),CreateMap("ClassName":strClass))
Next
'DBUtils.ExecuteBatch(helpdb)
'update matching parameters for methods that match
'DBUtils.UpdateRecord4(helpdb,"Methods",CreateMap("ParametersMatch":"Y"),CreateMap("OnPrevious":"Y","OnCurrent":"Y","lower([PParameters])":"lower([CParameters])"))
'DBUtils.ExecuteBatch(helpdb)
'mark abmaterial as Library
DBUtils.UpdateRecord4(helpdb,"Classes",CreateMap("IsLibrary":"Y"),CreateMap("ClassName":"ABMaterial"))
DBUtils.UpdateRecord4(helpdb,"Properties",CreateMap("IsLibrary":"Y"),CreateMap("ClassName":"ABMaterial"))
DBUtils.UpdateRecord4(helpdb,"Fields",CreateMap("IsLibrary":"Y"),CreateMap("ClassName":"ABMaterial"))
DBUtils.UpdateRecord4(helpdb,"Methods",CreateMap("IsLibrary":"Y"),CreateMap("ClassName":"ABMaterial"))
DBUtils.UpdateRecord4(helpdb,"Events",CreateMap("IsLibrary":"Y"),CreateMap("ClassName":"ABMaterial"))
helpdb.TransactionSuccessful
'update methods
Dim methods As List = DBUtils.SQLSelectRecordWhereMaps(helpdb,"Methods",CreateMap("OnPrevious=":"Y","OnCurrent=":"Y"))
helpdb.BeginTransaction
For Each methodm As Map In methods
Dim MethodKey As String = methodm.get("methodkey")
Dim PParameters As String = methodm.getdefault("pparameters","")
Dim CParameters As String = methodm.GetDefault("cparameters","")
If PParameters.EqualsIgnoreCase(CParameters) Then
DBUtils.UpdateRecord4(helpdb,"Methods",CreateMap("ParametersMatch":"Y"),CreateMap("MethodKey":MethodKey))
End If
Next
helpdb.TransactionSuccessful
'update events
Dim events As List = DBUtils.SQLSelectRecordWhereMaps(helpdb,"Events",CreateMap("OnPrevious=":"Y","OnCurrent=":"Y"))
helpdb.BeginTransaction
For Each eventm As Map In events
Dim EventKey As String = eventm.get("eventkey")
Dim PParameters As String = eventm.getdefault("pparameters","")
Dim CParameters As String = eventm.GetDefault("cparameters","")
If PParameters.EqualsIgnoreCase(CParameters) Then
DBUtils.UpdateRecord4(helpdb,"Events",CreateMap("ParametersMatch":"Y"),CreateMap("EventKey":EventKey))
End If
Next
helpdb.TransactionSuccessful
'DBUtils.ExecuteBatch(helpdb)
'helpdb.Close
Return True
'Dim jg As JSONGenerator
'jg.Initialize(ParsedData)
'Dim sout As String = jg.ToPrettyString(4)
'File.WriteString(File.dirapp,"xml.json",sout)
'Return sout
End Sub