From a8cda1d5f87fe0795ce8abf011ed866014718e96 Mon Sep 17 00:00:00 2001 From: "Michael J. Seiferling" Date: Mon, 16 Nov 2015 11:16:35 -0600 Subject: [PATCH] Changed some sync logic --- GBM/Classes/clsGame.vb | 12 +++++++ GBM/Classes/clsTag.vb | 12 +++++++ GBM/Managers/mgrGameTags.vb | 54 +++++++++++++++---------------- GBM/Managers/mgrMonitorList.vb | 58 ++++++++++++++++++---------------- GBM/Managers/mgrTags.vb | 54 +++++++++++++++---------------- 5 files changed, 108 insertions(+), 82 deletions(-) diff --git a/GBM/Classes/clsGame.vb b/GBM/Classes/clsGame.vb index 5355877..4f61a34 100644 --- a/GBM/Classes/clsGame.vb +++ b/GBM/Classes/clsGame.vb @@ -278,6 +278,18 @@ End If End Function + Public Function MinimalEquals(obj As Object) As Boolean + Dim oGame As clsGame = TryCast(obj, clsGame) + If oGame Is Nothing Then + Return False + Else + If ID <> oGame.ID Then + Return False + End If + Return True + End If + End Function + Public Function ShallowCopy() As clsGame Return DirectCast(Me.MemberwiseClone(), clsGame) End Function diff --git a/GBM/Classes/clsTag.vb b/GBM/Classes/clsTag.vb index e4cc1f5..e8b95e4 100644 --- a/GBM/Classes/clsTag.vb +++ b/GBM/Classes/clsTag.vb @@ -35,4 +35,16 @@ End If End Function + Public Function MinimalEquals(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 + Return True + End If + End Function + End Class diff --git a/GBM/Managers/mgrGameTags.vb b/GBM/Managers/mgrGameTags.vb index 79812a0..edd9946 100644 --- a/GBM/Managers/mgrGameTags.vb +++ b/GBM/Managers/mgrGameTags.vb @@ -223,33 +223,6 @@ 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) @@ -277,6 +250,33 @@ DoGameTagAddSync(hshSyncItems, mgrSQLite.Database.Local) End If + '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 + Return hshDeleteItems.Count + hshSyncItems.Count End Function diff --git a/GBM/Managers/mgrMonitorList.vb b/GBM/Managers/mgrMonitorList.vb index e890a8c..034c481 100644 --- a/GBM/Managers/mgrMonitorList.vb +++ b/GBM/Managers/mgrMonitorList.vb @@ -95,11 +95,14 @@ Public Class mgrMonitorList Dim hshParams As Hashtable Dim oParamList As New List(Of Hashtable) - sSQL = "DELETE FROM monitorlist " + sSQL = "DELETE FROM gametags " + sSQL &= "WHERE MonitorID = @MonitorID;" + sSQL &= "DELETE FROM monitorlist " sSQL &= "WHERE Name = @Name AND Process= @Process;" For Each oGame As clsGame In hshGames.Values hshParams = New Hashtable + hshParams.Add("MonitorID", oGame.ID) hshParams.Add("Name", oGame.Name) hshParams.Add("Process", oGame.TrueProcess) oParamList.Add(hshParams) @@ -125,33 +128,6 @@ Public Class mgrMonitorList RaiseEvent UpdateLog("A sync from the master game list has been triggered.", False, ToolTipIcon.Info, True) End If - 'Delete Sync - If bToRemote Then - hshCompareFrom = ReadList(eListTypes.FullList, mgrSQLite.Database.Local) - hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Remote) - Else - hshCompareFrom = ReadList(eListTypes.FullList, mgrSQLite.Database.Remote) - hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Local) - End If - - hshDeleteItems = hshCompareTo.Clone - - For Each oToItem In hshCompareTo.Values - If hshCompareFrom.Contains(oToItem.ProcessName) Then - oFromItem = DirectCast(hshCompareFrom(oToItem.ProcessName), clsGame) - If oToItem.CoreEquals(oFromItem) Then - hshDeleteItems.Remove(oToItem.ProcessName) - End If - End If - Next - - If bToRemote Then - DoListDeleteSync(hshDeleteItems, mgrSQLite.Database.Remote) - Else - DoListDeleteSync(hshDeleteItems, mgrSQLite.Database.Local) - End If - - 'Add / Update Sync If bToRemote Then hshCompareFrom = ReadList(eListTypes.FullList, mgrSQLite.Database.Local) @@ -183,6 +159,32 @@ Public Class mgrMonitorList iChanges = mgrTags.SyncTags(bToRemote) iChanges += mgrGameTags.SyncGameTags(bToRemote) + 'Delete Sync + If bToRemote Then + hshCompareFrom = ReadList(eListTypes.FullList, mgrSQLite.Database.Local) + hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Remote) + Else + hshCompareFrom = ReadList(eListTypes.FullList, mgrSQLite.Database.Remote) + hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Local) + End If + + hshDeleteItems = hshCompareTo.Clone + + For Each oToItem In hshCompareTo.Values + If hshCompareFrom.Contains(oToItem.ProcessName) Then + oFromItem = DirectCast(hshCompareFrom(oToItem.ProcessName), clsGame) + If oToItem.MinimalEquals(oFromItem) Then + hshDeleteItems.Remove(oToItem.ProcessName) + End If + End If + Next + + If bToRemote Then + DoListDeleteSync(hshDeleteItems, mgrSQLite.Database.Remote) + Else + DoListDeleteSync(hshDeleteItems, mgrSQLite.Database.Local) + End If + RaiseEvent UpdateLog(hshDeleteItems.Count + hshSyncItems.Count + iChanges & " change(s) synced.", False, ToolTipIcon.Info, True) Cursor.Current = Cursors.Default Application.DoEvents() diff --git a/GBM/Managers/mgrTags.vb b/GBM/Managers/mgrTags.vb index 8b938e1..fbb3e8e 100644 --- a/GBM/Managers/mgrTags.vb +++ b/GBM/Managers/mgrTags.vb @@ -203,33 +203,7 @@ 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 + Dim oToItem As clsTag 'Add / Update Sync If bToRemote Then @@ -257,6 +231,32 @@ DoTagAddUpdateSync(hshSyncItems, mgrSQLite.Database.Local) End If + '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.MinimalEquals(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 + Return hshDeleteItems.Count + hshSyncItems.Count End Function