Changes for issue #109

This commit is contained in:
MikeMaximus
2017-11-20 10:54:06 -06:00
parent bd2b828bd3
commit 644d073af0
4 changed files with 100 additions and 12 deletions
@@ -0,0 +1,32 @@
Public Class ExportData
Dim oExportInformation As ExportInformation
Dim oConfigs As List(Of Game)
Property Information As ExportInformation
Set(value As ExportInformation)
oExportInformation = value
End Set
Get
Return oExportInformation
End Get
End Property
Property Configurations As List(Of Game)
Set(value As List(Of Game))
oConfigs = value
End Set
Get
Return oConfigs
End Get
End Property
Public Sub New()
oExportInformation = New ExportInformation()
oConfigs = New List(Of Game)
End Sub
Public Sub New(ByVal oInitExportInformation As ExportInformation, ByVal oInitConfigs As List(Of Game))
oExportInformation = oInitExportInformation
oConfigs = oInitConfigs
End Sub
End Class
@@ -0,0 +1,32 @@
Public Class ExportInformation
Private dExported As Int64
Private iAppVer As Integer
Property Exported As Int64
Set(value As Int64)
dExported = value
End Set
Get
Return dExported
End Get
End Property
Property AppVer As Integer
Set(value As Integer)
iAppVer = value
End Set
Get
Return iAppVer
End Get
End Property
Public Sub New()
dExported = 0
iAppVer = 0
End Sub
Public Sub New(ByVal dInitExported As Int64, ByVal iInitAppVer As Integer)
dExported = dInitExported
iAppVer = iInitAppVer
End Sub
End Class
+2
View File
@@ -126,6 +126,8 @@
<Compile Include="Classes\clsGameFilterField.vb" />
<Compile Include="Classes\clsSavedPath.vb" />
<Compile Include="Classes\clsSession.vb" />
<Compile Include="Classes\XML Serialize Classes\ExportData.vb" />
<Compile Include="Classes\XML Serialize Classes\ExportInformation.vb" />
<Compile Include="Classes\XML Serialize Classes\Tag.vb" />
<Compile Include="Classes\XML Serialize Classes\Game.vb" />
<Compile Include="Classes\clsGameTag.vb" />
+34 -12
View File
@@ -46,38 +46,60 @@ Public Class mgrXML
Return hshList
End Function
Public Shared Function ImportandDeserialize(ByVal sLocation As String, Optional ByVal bWebRead As Boolean = False) As List(Of Game)
Private Shared Function ReadImportData(ByVal sLocation As String, ByVal bWebRead As Boolean)
Dim oReader As StreamReader
Dim oWebClient As WebClient
If bWebRead Then
oWebClient = New WebClient
oReader = New StreamReader(oWebClient.OpenRead(sLocation))
Else
oReader = New StreamReader(sLocation)
End If
Return oReader
End Function
Public Shared Function ImportandDeserialize(ByVal sLocation As String, Optional ByVal bWebRead As Boolean = False) As List(Of Game)
Dim oReader As StreamReader
Dim oSerializer As XmlSerializer
Dim oList As New List(Of Game)
Dim oExportData As New ExportData
Dim oConfigurations As New List(Of Game)
Try
If bWebRead Then
oWebClient = New WebClient
oReader = New StreamReader(oWebClient.OpenRead(sLocation))
oReader = ReadImportData(sLocation, bWebRead)
oSerializer = New XmlSerializer(oExportData.GetType(), New XmlRootAttribute("gbm"))
oExportData = oSerializer.Deserialize(oReader)
oReader.Close()
'Compatability Mode
If oExportData.Information.AppVer = 0 Then
oReader = ReadImportData(sLocation, bWebRead)
oSerializer = New XmlSerializer(oConfigurations.GetType(), New XmlRootAttribute("gbm"))
oConfigurations = oSerializer.Deserialize(oReader)
oReader.Close()
Else
oReader = New StreamReader(sLocation)
oConfigurations = oExportData.Configurations
End If
oSerializer = New XmlSerializer(oList.GetType(), New XmlRootAttribute("gbm"))
oList = oSerializer.Deserialize(oReader)
oReader.Close()
Catch ex As Exception
mgrCommon.ShowMessage(mgrXML_ErrorImportFailure, ex.Message, MsgBoxStyle.Exclamation)
End Try
Return oList
Return oConfigurations
End Function
Public Shared Function SerializeAndExport(ByVal oList As List(Of Game), ByVal sLocation As String) As Boolean
Dim oSerializer As XmlSerializer
Dim oWriter As StreamWriter
Dim oExportInformation = New ExportInformation(mgrCommon.DateToUnix(Now), mgrCommon.AppVersion)
Dim oExportData As ExportData
Try
oSerializer = New XmlSerializer(oList.GetType(), New XmlRootAttribute("gbm"))
oExportData = New ExportData(oExportInformation, oList)
oSerializer = New XmlSerializer(oExportData.GetType(), New XmlRootAttribute("gbm"))
oWriter = New StreamWriter(sLocation)
oSerializer.Serialize(oWriter.BaseStream, oList)
oSerializer.Serialize(oWriter.BaseStream, oExportData)
oWriter.Flush()
oWriter.Close()
Return True