Changed some sync logic

This commit is contained in:
Michael J. Seiferling
2015-11-16 11:16:35 -06:00
parent 049878202a
commit a8cda1d5f8
5 changed files with 108 additions and 82 deletions
+12
View File
@@ -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
+12
View File
@@ -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
+27 -27
View File
@@ -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
+30 -28
View File
@@ -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()
+26 -26
View File
@@ -205,32 +205,6 @@
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)
@@ -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