Sync Overhaul (Tag Support and Efficiency)

This commit is contained in:
Michael J. Seiferling
2015-11-14 14:09:29 -06:00
parent ebf5fb5f4d
commit 7c1698388a
5 changed files with 411 additions and 142 deletions
+15
View File
@@ -20,4 +20,19 @@
End Set End Set
End Property End Property
Public Function CoreEquals(obj As Object) As Boolean
Dim oGameTag As clsGameTag = TryCast(obj, clsGameTag)
If oGameTag Is Nothing Then
Return False
Else
If TagID <> oGameTag.TagID Then
Return False
End If
If MonitorID <> oGameTag.MonitorID Then
Return False
End If
Return True
End If
End Function
End Class End Class
+15
View File
@@ -20,4 +20,19 @@
End Set End Set
End Property End Property
Public Function CoreEquals(obj As Object) As Boolean
Dim oTag As clsTag = TryCast(obj, clsTag)
If oTag Is Nothing Then
Return False
Else
If ID <> oTag.ID Then
Return False
End If
If Name <> oTag.Name Then
Return False
End If
Return True
End If
End Function
End Class End Class
+129 -3
View File
@@ -1,7 +1,7 @@
Public Class mgrGameTags Public Class mgrGameTags
Public Shared Sub DoGameTagAdd(ByVal oGameTag As clsGameTag) Public Shared Sub DoGameTagAdd(ByVal oGameTag As clsGameTag, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String Dim sSQL As String
Dim hshParams As New Hashtable Dim hshParams As New Hashtable
@@ -17,7 +17,7 @@
Dim hshParams As Hashtable Dim hshParams As Hashtable
Dim oParamList As New List(Of Hashtable) Dim oParamList As New List(Of Hashtable)
sSQL = "INSERT INTO gametags VALUES (@TagID, @MonitorID)" sSQL = "INSERT INTO gametags VALUES (@TagID, @MonitorID);"
For Each oGameTag As clsGameTag In oGameTags For Each oGameTag As clsGameTag In oGameTags
hshParams = New Hashtable hshParams = New Hashtable
@@ -155,4 +155,130 @@
Return hshList Return hshList
End Function End Function
Public Shared Function ReadGameTags(Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As Hashtable
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim oData As DataSet
Dim sSQL As String
Dim sCompoundKey As String
Dim hshList As New Hashtable
Dim oGameTag As clsGameTag
sSQL = "SELECT * from gametags"
oData = oDatabase.ReadParamData(sSQL, New Hashtable)
For Each dr As DataRow In oData.Tables(0).Rows
oGameTag = New clsGameTag
oGameTag.TagID = CStr(dr(0))
oGameTag.MonitorID = CStr(dr(1))
sCompoundKey = oGameTag.TagID & ":" & oGameTag.MonitorID
hshList.Add(sCompoundKey, oGameTag)
Next
Return hshList
End Function
Public Shared Sub DoGameTagAddSync(ByVal hshTags As Hashtable, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As Hashtable
Dim oParamList As New List(Of Hashtable)
sSQL = "INSERT INTO gametags VALUES (@TagID, @MonitorID);"
For Each oGameTag As clsGameTag In hshTags.Values
hshParams = New Hashtable
hshParams.Add("TagID", oGameTag.TagID)
hshParams.Add("MonitorID", oGameTag.MonitorID)
oParamList.Add(hshParams)
Next
oDatabase.RunMassParamQuery(sSQL, oParamList)
End Sub
Public Shared Sub DoGameTagDeleteSync(ByVal hshTags As Hashtable, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As Hashtable
Dim oParamList As New List(Of Hashtable)
sSQL = "DELETE FROM gametags "
sSQL &= "WHERE TagID = @TagID AND MonitorID = @MonitorID;"
For Each oGameTag As clsGameTag In hshTags.Values
hshParams = New Hashtable
hshParams.Add("TagID", oGameTag.TagID)
hshParams.Add("MonitorID", oGameTag.MonitorID)
oParamList.Add(hshParams)
Next
oDatabase.RunMassParamQuery(sSQL, oParamList)
End Sub
Public Shared Function SyncGameTags(Optional ByVal bToRemote As Boolean = True) As Integer
Dim hshCompareFrom As Hashtable
Dim hshCompareTo As Hashtable
Dim hshSyncItems As Hashtable
Dim hshDeleteItems As Hashtable
Dim oFromItem As clsGameTag
Dim oToItem As clsGameTag
Dim sCompoundKey As String
'Delete Sync
If bToRemote Then
hshCompareFrom = ReadGameTags(mgrSQLite.Database.Local)
hshCompareTo = ReadGameTags(mgrSQLite.Database.Remote)
Else
hshCompareFrom = ReadGameTags(mgrSQLite.Database.Remote)
hshCompareTo = ReadGameTags(mgrSQLite.Database.Local)
End If
hshDeleteItems = hshCompareTo.Clone
For Each oToItem In hshCompareTo.Values
sCompoundKey = oToItem.TagID & ":" & oToItem.MonitorID
If hshCompareFrom.Contains(sCompoundKey) Then
oFromItem = DirectCast(hshCompareFrom(sCompoundKey), clsGameTag)
If oToItem.CoreEquals(oFromItem) Then
hshDeleteItems.Remove(sCompoundKey)
End If
End If
Next
If bToRemote Then
DoGameTagDeleteSync(hshDeleteItems, mgrSQLite.Database.Remote)
Else
DoGameTagDeleteSync(hshDeleteItems, mgrSQLite.Database.Local)
End If
'Add / Update Sync
If bToRemote Then
hshCompareFrom = ReadGameTags(mgrSQLite.Database.Local)
hshCompareTo = ReadGameTags(mgrSQLite.Database.Remote)
Else
hshCompareFrom = ReadGameTags(mgrSQLite.Database.Remote)
hshCompareTo = ReadGameTags(mgrSQLite.Database.Local)
End If
hshSyncItems = hshCompareFrom.Clone
For Each oFromItem In hshCompareFrom.Values
sCompoundKey = oFromItem.TagID & ":" & oFromItem.MonitorID
If hshCompareTo.Contains(sCompoundKey) Then
oToItem = DirectCast(hshCompareTo(sCompoundKey), clsGameTag)
If oFromItem.CoreEquals(oToItem) Then
hshSyncItems.Remove(sCompoundKey)
End If
End If
Next
If bToRemote Then
DoGameTagAddSync(hshSyncItems, mgrSQLite.Database.Remote)
Else
DoGameTagAddSync(hshSyncItems, mgrSQLite.Database.Local)
End If
Return hshDeleteItems.Count + hshSyncItems.Count
End Function
End Class End Class
+114 -129
View File
@@ -39,70 +39,6 @@ Public Class mgrMonitorList
End If End If
End Sub End Sub
Private Shared Sub ImportMonitorList(ByVal sLocation As String, Optional ByVal bWebRead As Boolean = False)
Dim hshCompareFrom As Hashtable
Dim hshCompareTo As Hashtable
Dim hshSyncItems As Hashtable
Dim oFromItem As clsGame
Dim oToItem As clsGame
Dim oTag As clsTag
Dim oGameTag As clsGameTag
Dim iItems As Integer = 0
Cursor.Current = Cursors.WaitCursor
'Add / Update Sync
hshCompareFrom = mgrXML.ReadMonitorList(sLocation, bWebRead)
hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Local)
hshSyncItems = hshCompareFrom.Clone
For Each oFromItem In hshCompareFrom.Values
If hshCompareTo.Contains(oFromItem.ProcessName) Then
oToItem = DirectCast(hshCompareTo(oFromItem.ProcessName), clsGame)
If oFromItem.CoreEquals(oToItem) Then
hshSyncItems.Remove(oFromItem.ProcessName)
End If
End If
Next
Cursor.Current = Cursors.Default
If hshSyncItems.Count > 0 Then
Dim frm As New frmAdvancedImport
frm.ImportData = hshSyncItems
If frm.ShowDialog() = DialogResult.OK Then
Cursor.Current = Cursors.WaitCursor
For Each oGame As clsGame In frm.ImportData.Values
If Not DoDuplicateListCheck(oGame.Name, oGame.TrueProcess) Then
DoListAdd(oGame, mgrSQLite.Database.Local)
'Handle Tag Import (TODO: This could use some optimization, way too many DB hits.)
For Each t As Tag In oGame.ImportTags
If mgrTags.DoCheckDuplicate(t.Name) Then
oTag = mgrTags.DoTagGetbyName(t.Name)
Else
oTag = New clsTag
oTag.Name = t.Name
mgrTags.DoTagAdd(oTag)
End If
oGameTag = New clsGameTag
oGameTag.MonitorID = oGame.ID
oGameTag.TagID = oTag.ID
mgrGameTags.DoGameTagAdd(oGameTag)
Next
iItems += 1
End If
Next
Cursor.Current = Cursors.Default
MsgBox("Import Complete. " & iItems & " entries have been imported.", MsgBoxStyle.Information, "Game Backup Monitor")
End If
Else
MsgBox("This list does not contain any new games to import.", MsgBoxStyle.Information, "Game Backup Monitor")
End If
Application.DoEvents()
End Sub
Public Shared Sub ExportMonitorList(ByVal sLocation As String) Public Shared Sub ExportMonitorList(ByVal sLocation As String)
'Dim hshList As Hashtable = ReadList(eListTypes.FullList, mgrSQLite.Database.Local) 'Dim hshList As Hashtable = ReadList(eListTypes.FullList, mgrSQLite.Database.Local)
'Dim bSuccess As Boolean 'Dim bSuccess As Boolean
@@ -117,6 +53,61 @@ Public Class mgrMonitorList
End If End If
End Sub End Sub
Public Shared Sub DoListAddUpdateSync(ByVal hshGames As Hashtable, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As Hashtable
Dim oParamList As New List(Of Hashtable)
sSQL = "INSERT OR REPLACE INTO monitorlist (MonitorID, Name, Process, Path, AbsolutePath, FolderSave, FileType, TimeStamp, ExcludeList, Hours, Enabled, MonitorOnly) "
sSQL &= "VALUES (COALESCE((SELECT MonitorID FROM monitorlist WHERE Name = @Name AND Process = @Process), @ID), @Name, @Process, @Path, @AbsolutePath, @FolderSave, @FileType, "
sSQL &= "@TimeStamp, @ExcludeList, @Hours, @Enabled, @MonitorOnly);"
For Each oGame As clsGame In hshGames.Values
hshParams = New Hashtable
'Parameters
hshParams.Add("ID", oGame.ID)
hshParams.Add("Name", oGame.Name)
hshParams.Add("Process", oGame.TrueProcess)
hshParams.Add("Path", oGame.TruePath)
hshParams.Add("AbsolutePath", oGame.AbsolutePath)
hshParams.Add("FolderSave", oGame.FolderSave)
hshParams.Add("FileType", oGame.FileType)
hshParams.Add("TimeStamp", oGame.AppendTimeStamp)
hshParams.Add("ExcludeList", oGame.ExcludeList)
hshParams.Add("Hours", oGame.Hours)
'Required Defaults
hshParams.Add("Enabled", True)
hshParams.Add("MonitorOnly", False)
oParamList.Add(hshParams)
Next
oDatabase.RunMassParamQuery(sSQL, oParamList)
End Sub
Public Shared Sub DoListDeleteSync(ByVal hshGames As Hashtable, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As Hashtable
Dim oParamList As New List(Of Hashtable)
sSQL = "DELETE FROM monitorlist "
sSQL &= "WHERE Name = @Name AND Process= @Process;"
For Each oGame As clsGame In hshGames.Values
hshParams = New Hashtable
hshParams.Add("Name", oGame.Name)
hshParams.Add("Process", oGame.TrueProcess)
oParamList.Add(hshParams)
Next
oDatabase.RunMassParamQuery(sSQL, oParamList)
End Sub
Public Shared Sub SyncMonitorLists(Optional ByVal bToRemote As Boolean = True) Public Shared Sub SyncMonitorLists(Optional ByVal bToRemote As Boolean = True)
Dim hshCompareFrom As Hashtable Dim hshCompareFrom As Hashtable
Dim hshCompareTo As Hashtable Dim hshCompareTo As Hashtable
@@ -124,6 +115,7 @@ Public Class mgrMonitorList
Dim hshDeleteItems As Hashtable Dim hshDeleteItems As Hashtable
Dim oFromItem As clsGame Dim oFromItem As clsGame
Dim oToItem As clsGame Dim oToItem As clsGame
Dim iChanges As Integer
Cursor.Current = Cursors.WaitCursor Cursor.Current = Cursors.WaitCursor
@@ -153,13 +145,12 @@ Public Class mgrMonitorList
End If End If
Next Next
For Each oGame As clsGame In hshDeleteItems.Values If bToRemote Then
If bToRemote Then DoListDeleteSync(hshDeleteItems, mgrSQLite.Database.Remote)
DoListDeleteSync(oGame, mgrSQLite.Database.Remote) Else
Else DoListDeleteSync(hshDeleteItems, mgrSQLite.Database.Local)
DoListDeleteSync(oGame, mgrSQLite.Database.Local) End If
End If
Next
'Add / Update Sync 'Add / Update Sync
If bToRemote Then If bToRemote Then
@@ -181,30 +172,64 @@ Public Class mgrMonitorList
End If End If
Next Next
For Each oGame As clsGame In hshSyncItems.Values If bToRemote Then
'Clear Extra Data DoListAddUpdateSync(hshSyncItems, mgrSQLite.Database.Remote)
oGame.Version = String.Empty
oGame.Company = String.Empty Else
oGame.ProcessPath = String.Empty DoListAddUpdateSync(hshSyncItems, mgrSQLite.Database.Local)
oGame.Icon = String.Empty End If
If bToRemote Then 'Sync Tags
If DoDuplicateListCheck(oGame.Name, oGame.TrueProcess, mgrSQLite.Database.Remote) Then iChanges = mgrTags.SyncTags(bToRemote)
DoListUpdateSync(oGame, mgrSQLite.Database.Remote) iChanges += mgrGameTags.SyncGameTags(bToRemote)
Else
DoListAdd(oGame, mgrSQLite.Database.Remote) RaiseEvent UpdateLog(hshDeleteItems.Count + hshSyncItems.Count + iChanges & " change(s) synced.", False, ToolTipIcon.Info, True)
End If Cursor.Current = Cursors.Default
Else Application.DoEvents()
If DoDuplicateListCheck(oGame.Name, oGame.TrueProcess, mgrSQLite.Database.Local) Then End Sub
DoListUpdateSync(oGame, mgrSQLite.Database.Local)
Else Private Shared Sub ImportMonitorList(ByVal sLocation As String, Optional ByVal bWebRead As Boolean = False)
DoListAdd(oGame, mgrSQLite.Database.Local) Dim hshCompareFrom As Hashtable
Dim hshCompareTo As Hashtable
Dim hshSyncItems As Hashtable
Dim oFromItem As clsGame
Dim oToItem As clsGame
Cursor.Current = Cursors.WaitCursor
'Add / Update Sync
hshCompareFrom = mgrXML.ReadMonitorList(sLocation, bWebRead)
hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Local)
hshSyncItems = hshCompareFrom.Clone
For Each oFromItem In hshCompareFrom.Values
If hshCompareTo.Contains(oFromItem.ProcessName) Then
oToItem = DirectCast(hshCompareTo(oFromItem.ProcessName), clsGame)
If oFromItem.CoreEquals(oToItem) Then
hshSyncItems.Remove(oFromItem.ProcessName)
End If End If
End If End If
Next Next
RaiseEvent UpdateLog(hshDeleteItems.Count + hshSyncItems.Count & " change(s) synced.", False, ToolTipIcon.Info, True)
Cursor.Current = Cursors.Default Cursor.Current = Cursors.Default
If hshSyncItems.Count > 0 Then
Dim frm As New frmAdvancedImport
frm.ImportData = hshSyncItems
If frm.ShowDialog() = DialogResult.OK Then
Cursor.Current = Cursors.WaitCursor
DoListAddUpdateSync(frm.ImportData)
mgrTags.DoTagAddImport(frm.ImportData)
Cursor.Current = Cursors.Default
MsgBox("Import Complete.", MsgBoxStyle.Information, "Game Backup Monitor")
End If
Else
MsgBox("This list does not contain any new games to import.", MsgBoxStyle.Information, "Game Backup Monitor")
End If
Application.DoEvents() Application.DoEvents()
End Sub End Sub
@@ -407,46 +432,6 @@ Public Class mgrMonitorList
End Sub End Sub
Public Shared Sub DoListUpdateSync(ByVal oGame As clsGame, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "UPDATE monitorlist SET Name=@Name, Process=@Process, Path=@Path, AbsolutePath=@AbsolutePath, FolderSave=@FolderSave, "
sSQL &= "FileType=@FileType, TimeStamp=@TimeStamp, ExcludeList=@ExcludeList, Hours=@Hours "
sSQL &= "WHERE Name=@QueryName AND Process=@QueryProcess"
'Parameters
hshParams.Add("Name", oGame.Name)
hshParams.Add("Process", oGame.TrueProcess)
hshParams.Add("Path", oGame.TruePath)
hshParams.Add("AbsolutePath", oGame.AbsolutePath)
hshParams.Add("FolderSave", oGame.FolderSave)
hshParams.Add("FileType", oGame.FileType)
hshParams.Add("TimeStamp", oGame.AppendTimeStamp)
hshParams.Add("ExcludeList", oGame.ExcludeList)
hshParams.Add("Hours", oGame.Hours)
hshParams.Add("QueryName", oGame.Name)
hshParams.Add("QueryProcess", oGame.TrueProcess)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoListDeleteSync(ByVal oGame As clsGame, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "DELETE FROM monitorlist "
sSQL &= "WHERE Name = @Name AND Process= @Process"
hshParams.Add("Name", oGame.Name)
hshParams.Add("Process", oGame.TrueProcess)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoListDelete(ByVal sMonitorID As String, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) Public Shared Sub DoListDelete(ByVal sMonitorID As String, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB) Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String Dim sSQL As String
+138 -10
View File
@@ -1,7 +1,7 @@
Public Class mgrTags Public Class mgrTags
Public Shared Sub DoTagAdd(ByVal oTag As clsTag) Public Shared Sub DoTagAdd(ByVal oTag As clsTag, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String Dim sSQL As String
Dim hshParams As New Hashtable Dim hshParams As New Hashtable
@@ -11,8 +11,8 @@
oDatabase.RunParamQuery(sSQL, hshParams) oDatabase.RunParamQuery(sSQL, hshParams)
End Sub End Sub
Public Shared Sub DoTagUpdate(ByVal oTag As clsTag) Public Shared Sub DoTagUpdate(ByVal oTag As clsTag, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String Dim sSQL As String
Dim hshParams As New Hashtable Dim hshParams As New Hashtable
@@ -59,7 +59,7 @@
For Each dr As DataRow In oData.Tables(0).Rows For Each dr As DataRow In oData.Tables(0).Rows
oTag = New clsTag oTag = New clsTag
oTag.ID = CStr(dr(0)) oTag.ID = CStr(dr(0))
oTag.Name = CStr(dr(1)) oTag.Name = CStr(dr(1))
Next Next
Return oTag Return oTag
@@ -88,8 +88,8 @@
Return oTag Return oTag
End Function End Function
Public Shared Function DoCheckDuplicate(ByVal sTagName As String, Optional ByVal sExcludeID As String = "") As Boolean Public Shared Function DoCheckDuplicate(ByVal sTagName As String, Optional ByVal sExcludeID As String = "", Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As Boolean
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String Dim sSQL As String
Dim oData As DataSet Dim oData As DataSet
Dim hshParams As New Hashtable Dim hshParams As New Hashtable
@@ -113,8 +113,8 @@
End If End If
End Function End Function
Public Shared Function ReadTags() As Hashtable Public Shared Function ReadTags(Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As Hashtable
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local) Dim oDatabase As New mgrSQLite(iSelectDB)
Dim oData As DataSet Dim oData As DataSet
Dim sSQL As String Dim sSQL As String
Dim hshList As New Hashtable Dim hshList As New Hashtable
@@ -126,11 +126,139 @@
For Each dr As DataRow In oData.Tables(0).Rows For Each dr As DataRow In oData.Tables(0).Rows
oTag = New clsTag oTag = New clsTag
oTag.ID = CStr(dr(0)) oTag.ID = CStr(dr(0))
oTag.Name = CStr(dr(1)) oTag.Name = CStr(dr(1))
hshList.Add(oTag.Name, oTag) hshList.Add(oTag.Name, oTag)
Next Next
Return hshList Return hshList
End Function End Function
Public Shared Sub DoTagAddImport(ByVal hshTags As Hashtable, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim sMonitorID As String
Dim oTag As clsTag
Dim hshParams As Hashtable
Dim oParamList As New List(Of Hashtable)
sSQL = "INSERT OR REPLACE INTO tags VALUES (COALESCE((SELECT TagID FROM tags WHERE Name = @Name), @ID), @Name); INSERT INTO gametags VALUES ((SELECT TagID from tags WHERE Name=@Name), @MonitorID);"
For Each oGame As clsGame In hshTags.Values
sMonitorID = oGame.ID
For Each t As Tag In oGame.ImportTags
hshParams = New Hashtable
oTag = New clsTag
oTag.Name = t.Name
hshParams.Add("ID", oTag.ID)
hshParams.Add("Name", oTag.Name)
hshParams.Add("MonitorID", sMonitorID)
oParamList.Add(hshParams)
Next
Next
oDatabase.RunMassParamQuery(sSQL, oParamList)
End Sub
Public Shared Sub DoTagAddUpdateSync(ByVal hshTags As Hashtable, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As Hashtable
Dim oParamList As New List(Of Hashtable)
sSQL = "INSERT OR REPLACE INTO tags VALUES (COALESCE((SELECT TagID FROM tags WHERE Name = @Name), @ID), @Name);"
For Each oTag As clsTag In hshTags.Values
hshParams = New Hashtable
hshParams.Add("ID", oTag.ID)
hshParams.Add("Name", oTag.Name)
oParamList.Add(hshParams)
Next
oDatabase.RunMassParamQuery(sSQL, oParamList)
End Sub
Private Shared Sub DoTagDeleteSync(ByVal hshTags As Hashtable, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As Hashtable
Dim oParamList As New List(Of Hashtable)
sSQL = "DELETE FROM gametags "
sSQL &= "WHERE TagID = @ID;"
sSQL = "DELETE FROM tags "
sSQL &= "WHERE TagID = @ID;"
For Each oTag As clsTag In hshTags.Values
hshParams = New Hashtable
hshParams.Add("ID", oTag.ID)
oParamList.Add(hshParams)
Next
oDatabase.RunMassParamQuery(sSQL, oParamList)
End Sub
Public Shared Function SyncTags(Optional ByVal bToRemote As Boolean = True) As Integer
Dim hshCompareFrom As Hashtable
Dim hshCompareTo As Hashtable
Dim hshSyncItems As Hashtable
Dim hshDeleteItems As Hashtable
Dim oFromItem As clsTag
Dim oToItem As clsTag
'Delete Sync
If bToRemote Then
hshCompareFrom = ReadTags(mgrSQLite.Database.Local)
hshCompareTo = ReadTags(mgrSQLite.Database.Remote)
Else
hshCompareFrom = ReadTags(mgrSQLite.Database.Remote)
hshCompareTo = ReadTags(mgrSQLite.Database.Local)
End If
hshDeleteItems = hshCompareTo.Clone
For Each oToItem In hshCompareTo.Values
If hshCompareFrom.Contains(oToItem.Name) Then
oFromItem = DirectCast(hshCompareFrom(oToItem.Name), clsTag)
If oToItem.CoreEquals(oFromItem) Then
hshDeleteItems.Remove(oToItem.Name)
End If
End If
Next
If bToRemote Then
DoTagDeleteSync(hshDeleteItems, mgrSQLite.Database.Remote)
Else
DoTagDeleteSync(hshDeleteItems, mgrSQLite.Database.Local)
End If
'Add / Update Sync
If bToRemote Then
hshCompareFrom = ReadTags(mgrSQLite.Database.Local)
hshCompareTo = ReadTags(mgrSQLite.Database.Remote)
Else
hshCompareFrom = ReadTags(mgrSQLite.Database.Remote)
hshCompareTo = ReadTags(mgrSQLite.Database.Local)
End If
hshSyncItems = hshCompareFrom.Clone
For Each oFromItem In hshCompareFrom.Values
If hshCompareTo.Contains(oFromItem.Name) Then
oToItem = DirectCast(hshCompareTo(oFromItem.Name), clsTag)
If oFromItem.CoreEquals(oToItem) Then
hshSyncItems.Remove(oFromItem.Name)
End If
End If
Next
If bToRemote Then
DoTagAddUpdateSync(hshSyncItems, mgrSQLite.Database.Remote)
Else
DoTagAddUpdateSync(hshSyncItems, mgrSQLite.Database.Local)
End If
Return hshDeleteItems.Count + hshSyncItems.Count
End Function
End Class End Class