- gestione backup e ripristino

- aggiornamento pacchetto ionic.zip con dotnetzip
This commit is contained in:
Emmanuele Sassi
2023-07-31 09:59:05 +02:00
parent bf1dd1d526
commit 638461a4e3
10 changed files with 350 additions and 69 deletions
+3 -1
View File
@@ -162,6 +162,8 @@ Public Module ConstIni
Public Const K_DEFAULTQUANTITY As String = "DefaultQuantity"
Public Const S_BACKUPANDRESTORE As String = "Backup&Restore"
Public Const K_FILEPATH As String = "FilePath"
Public Const K_EXTERNALBACKUPACTIVE As String = "ExternalBackupActive"
Public Const K_EXTERNALFILEPATH As String = "ExternalFilePath"
Public Const K_REMINDERFREQUENCY As String = "ReminderFrequency"
End Module
@@ -16,6 +16,8 @@ Public Module LoadingWndHelper
CHANGEPARAM = 10
CREATINGPDF = 11
CHANGEMATERIAL = 12
BACKUP = 13
RESTORE = 14
End Enum
Dim m_MainWindow As Windows.Window
@@ -149,6 +149,9 @@
<Reference Include="Csv, Version=1.0.31.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Csv.1.0.31\lib\net40\Csv.dll</HintPath>
</Reference>
<Reference Include="DotNetZip, Version=1.16.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll</HintPath>
</Reference>
<Reference Include="EgtUILib, Version=2.4.3.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\ExtLibs\EgtUILib.dll</HintPath>
@@ -177,9 +180,6 @@
<HintPath>..\ExtLibs\Interop.FXServer.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
<HintPath>..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="ISOCNC.Remoting">
<HintPath>..\ExtLibs\ISOCNC.Remoting.dll</HintPath>
</Reference>
+1 -1
View File
@@ -6,7 +6,7 @@
</configSections>
<entityFramework>
<!--<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.EntityFramework" />-->
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.21.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
</provider>
+1 -1
View File
@@ -2,10 +2,10 @@
<packages>
<package id="BouncyCastle" version="1.8.5" targetFramework="net472" />
<package id="Csv" version="1.0.31" targetFramework="net472" />
<package id="DotNetZip" version="1.16.0" targetFramework="net472" />
<package id="EntityFramework" version="6.4.4" targetFramework="net452" />
<package id="FluentFTP" version="19.2.2" targetFramework="net472" />
<package id="Google.Protobuf" version="3.21.9" targetFramework="net472" />
<package id="Ionic.Zip" version="1.9.1.8" targetFramework="net472" />
<package id="K4os.Compression.LZ4" version="1.3.5" targetFramework="net472" />
<package id="K4os.Compression.LZ4.Streams" version="1.3.5" targetFramework="net472" />
<package id="K4os.Hash.xxHash" version="1.0.8" targetFramework="net472" />
+9 -1
View File
@@ -6,7 +6,7 @@
</configSections>
<entityFramework>
<!--<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.EntityFramework" />-->
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.21.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
</provider>
@@ -41,6 +41,14 @@
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.data>
@@ -77,22 +77,48 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="File path:"/>
<Grid Margin="0,2,0,5">
<Grid Grid.Row="0"
Margin="0,2,0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<CheckBox x:Name="ExternalBackup_CheckBox"
IsChecked="{Binding bExternalBackupActive}"
VerticalAlignment="Center"/>
<TextBlock Grid.Column="1"
Text="External file path:"
VerticalAlignment="Center"/>
</Grid>
<Grid Grid.Row="1"
Margin="0,2,0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Text="{Binding BackupFilePath}"
<TextBox Text="{Binding ExternalBackupFolderPath}"
IsEnabled="{Binding IsChecked, ElementName=ExternalBackup_CheckBox}"
Margin="0,0,2.5,0"/>
<Button Grid.Column="1"
Content="..."
Width="18"
Command="{Binding ChooseBackupFilePath_Command}"
Command="{Binding ChooseExternalBackupFolderPath_Command}"
IsEnabled="{Binding IsChecked, ElementName=ExternalBackup_CheckBox}"
Margin="2.5,0,0,0"/>
</Grid>
<StackPanel Grid.Row="1"
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Reminder Frequency"/>
<ComboBox Grid.Column="1"
ItemsSource="{Binding ReminderList}"
SelectedItem="{Binding SelReminder}"/>
</Grid>
<StackPanel Grid.Row="3"
Orientation="Horizontal">
<Button Content="Backup"
Command="{Binding Backup_Command}"
@@ -5,6 +5,10 @@ Imports EgtWPFLib5
Imports EgtBEAMWALL.Core
Imports MS.Internal
Imports Org.BouncyCastle.X509
Imports Ionic.Zip
Imports Org.BouncyCastle.Bcpg
Imports Microsoft.VisualBasic.ApplicationServices
Imports Renci.SshNet.Security
Public Class ConfigurationPageVM
Inherits VMBase
@@ -160,20 +164,49 @@ Public Class ConfigurationPageVM
End Set
End Property
Private m_BackupFilePath As String
Public Property BackupFilePath As String
Private m_bExternalBackupActive As Boolean
Public Property bExternalBackupActive As Boolean
Get
Return m_BackupFilePath
Return m_bExternalBackupActive
End Get
Set(value As Boolean)
m_bExternalBackupActive = value
WriteMainPrivateProfileString(S_BACKUPANDRESTORE, K_EXTERNALBACKUPACTIVE, If(m_bExternalBackupActive, 1, 0))
End Set
End Property
Private m_ExternalBackupFolderPath As String
Public Property ExternalBackupFolderPath As String
Get
Return m_ExternalBackupFolderPath
End Get
Set(value As String)
m_BackupFilePath = value
WriteMainPrivateProfileString(S_BACKUPANDRESTORE, K_FILEPATH, m_BackupFilePath)
m_ExternalBackupFolderPath = value
WriteMainPrivateProfileString(S_BACKUPANDRESTORE, K_EXTERNALFILEPATH, m_ExternalBackupFolderPath)
End Set
End Property
Private m_ReminderList As New List(Of IdNameStruct)({New IdNameStruct(0, "Never"), New IdNameStruct(1, "1 day"), New IdNameStruct(2, "2 days"), New IdNameStruct(7, "1 week"), New IdNameStruct(14, "2 weeks"), New IdNameStruct(30, "1 month")})
Public ReadOnly Property ReminderList As List(Of IdNameStruct)
Get
Return m_ReminderList
End Get
End Property
Private m_SelReminder As IdNameStruct
Public Property SelReminder As IdNameStruct
Get
Return m_SelReminder
End Get
Set(value As IdNameStruct)
m_SelReminder = value
WriteMainPrivateProfileString(S_BACKUPANDRESTORE, K_REMINDERFREQUENCY, m_SelReminder.Id)
End Set
End Property
' Definizione comandi
Private m_cmdSave As ICommand
Private m_cmdChooseBackupFilePath As ICommand
Private m_cmdChooseExternalBackupFolderPath As ICommand
Private m_cmdBackup As ICommand
Private m_cmdRestore As ICommand
@@ -363,8 +396,13 @@ Public Class ConfigurationPageVM
m_QBTLParamVMList_View = CollectionViewSource.GetDefaultView(m_QBTLParamVMList)
m_QBTLParamVMList_View.GroupDescriptions.Add(New PropertyGroupDescription(NameOf(QBTLParamVM.GroupType)))
m_QBTLParamVMList_View.GroupDescriptions.Add(New PropertyGroupDescription(NameOf(QBTLParamVM.ghDesc)))
' leggo path per backup
GetMainPrivateProfileString(S_BACKUPANDRESTORE, K_FILEPATH, "", m_BackupFilePath)
' leggo dati per backup
GetMainPrivateProfileString(S_BACKUPANDRESTORE, K_EXTERNALFILEPATH, "", m_ExternalBackupFolderPath)
Dim nDefaultReminderFrequency As Integer = GetMainPrivateProfileInt(S_BACKUPANDRESTORE, K_REMINDERFREQUENCY, 1)
SelReminder = m_ReminderList.FirstOrDefault(Function(x) x.Id = nDefaultReminderFrequency)
Dim nExternalBackupActive As Integer = GetMainPrivateProfileInt(S_BACKUPANDRESTORE, K_EXTERNALBACKUPACTIVE, 0)
m_bExternalBackupActive = nExternalBackupActive > 0
NotifyPropertyChanged(NameOf(bExternalBackupActive))
End Sub
#End Region ' Constructor
@@ -394,36 +432,41 @@ Public Class ConfigurationPageVM
#End Region ' SaveCommand
#Region "ChooseBackupFilePath"
#Region "ChooseExternalBackupFolderPath"
''' <summary>
''' Returns a command that do Save.
''' </summary>
Public ReadOnly Property ChooseBackupFilePath_Command As ICommand
Public ReadOnly Property ChooseExternalBackupFolderPath_Command As ICommand
Get
If m_cmdChooseBackupFilePath Is Nothing Then
m_cmdChooseBackupFilePath = New Command(AddressOf ChooseBackupFilePath)
If m_cmdChooseExternalBackupFolderPath Is Nothing Then
m_cmdChooseExternalBackupFolderPath = New Command(AddressOf ChooseExternalBackupFolderPath)
End If
Return m_cmdChooseBackupFilePath
Return m_cmdChooseExternalBackupFolderPath
End Get
End Property
''' <summary>
''' Execute the Save. This method is invoked by the SaveCommand.
''' </summary>
Public Sub ChooseBackupFilePath()
Dim FileDialog As New Microsoft.Win32.SaveFileDialog() With {.FileName = m_BackupFilePath,
Public Sub ChooseExternalBackupFolderPath()
'Dim FileDialog As New System.Windows.Forms.FolderBrowserDialog With {.SelectedPath = m_ExternalBackupFolderPath,
' .Description = "Backup & Restore File Path"}
Dim FileDialog As New Microsoft.Win32.SaveFileDialog() With {.InitialDirectory = m_ExternalBackupFolderPath,
.CheckFileExists = False,
.CheckPathExists = False,
.DefaultExt = ".folder",
.OverwritePrompt = False,
.FileName = "Select this ",
.Title = "Backup & Restore File Path"}
If FileDialog.ShowDialog() Then
m_BackupFilePath = FileDialog.FileName
NotifyPropertyChanged(NameOf(BackupFilePath))
m_ExternalBackupFolderPath = Path.GetDirectoryName(FileDialog.FileName)
WriteMainPrivateProfileString(S_BACKUPANDRESTORE, K_EXTERNALFILEPATH, m_ExternalBackupFolderPath)
NotifyPropertyChanged(NameOf(ExternalBackupFolderPath))
End If
End Sub
#End Region ' ChooseBackupFilePath
#End Region ' ChooseExternalBackupFolderPath
#Region "Backup"
@@ -433,7 +476,7 @@ Public Class ConfigurationPageVM
Public ReadOnly Property Backup_Command As ICommand
Get
If m_cmdBackup Is Nothing Then
m_cmdBackup = New Command(AddressOf Backup)
m_cmdBackup = New Command(AddressOf BackupCmd)
End If
Return m_cmdBackup
End Get
@@ -442,27 +485,123 @@ Public Class ConfigurationPageVM
''' <summary>
''' Execute the Save. This method is invoked by the SaveCommand.
''' </summary>
Public Sub Backup()
If Not String.IsNullOrWhiteSpace(m_BackupFilePath) AndAlso Directory.Exists(Path.GetDirectoryName(m_BackupFilePath)) Then
If File.Exists(m_BackupFilePath) Then
If MessageBox.Show("Are you sure you want to overwrite the file?", "Info", MessageBoxButton.OKCancel, MessageBoxImage.Warning) = MessageBoxResult.OK Then
' rinomino ed elimino file gia' esistente
Try
File.Move(m_BackupFilePath, m_BackupFilePath & ".old")
File.Delete(m_BackupFilePath)
Catch ex As Exception
MessageBox.Show("Backup failed! Impossible to move or delete previous file!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
End Try
' backup del corrente
Try
Public Sub BackupCmd()
Backup(True)
End Sub
Catch ex As Exception
MessageBox.Show("Backup failed! Impossible to create the backup package!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
End Try
Else Return
Public Sub Backup(bLoadingWindow As Boolean)
' verifico se esiste cartella backup, altrimenti la creo
Dim sBackupFolder As String = Map.refMainWindowVM.MainWindowM.sDataDir & "\Backup"
If Directory.Exists(sBackupFolder) Then
' verifico se devo cancellare backup vecchi
Dim nBackupCount As Integer = 0
Dim YearDirList() As String = Directory.GetDirectories(sBackupFolder)
For YearIndex = YearDirList.Length - 1 To 0 Step -1
Dim nYear As Integer = 0
Integer.TryParse(Path.GetFileName(YearDirList(YearIndex)), nYear)
Dim sYearDir As String = sBackupFolder & "\" & nYear
Dim MonthDirList() As String = Directory.GetDirectories(sYearDir)
For MonthIndex = MonthDirList.Length - 1 To 0 Step -1
Dim nMonth As Integer = 0
Integer.TryParse(Path.GetFileName(MonthDirList(MonthIndex)), nMonth)
Dim sMonthDir As String = sYearDir & "\" & nMonth
Dim DayDirList() As String = Directory.GetDirectories(sMonthDir)
For DayIndex = DayDirList.Length - 1 To 0 Step -1
Dim nDay As Integer = 0
Integer.TryParse(Path.GetFileName(DayDirList(DayIndex)), nDay)
If nBackupCount > 3 Then
Directory.Delete(sBackupFolder & "\" & nYear & "\" & nMonth & "\" & nDay, True)
End If
Next
DayDirList = Directory.GetDirectories(sMonthDir)
If IsNothing(DayDirList) OrElse DayDirList.Length = 0 Then
Directory.Delete(sMonthDir)
End If
Next
MonthDirList = Directory.GetDirectories(sYearDir)
If IsNothing(MonthDirList) OrElse MonthDirList.Length = 0 Then
Directory.Delete(sYearDir)
End If
Next
Else
Directory.CreateDirectory(sBackupFolder)
End If
sBackupFolder &= "\" & DateTime.Now().Year
If Not Directory.Exists(sBackupFolder) Then
Directory.CreateDirectory(sBackupFolder)
End If
sBackupFolder &= "\" & DateTime.Now().Month
If Not Directory.Exists(sBackupFolder) Then
Directory.CreateDirectory(sBackupFolder)
End If
sBackupFolder &= "\" & DateTime.Now().Day
If Not Directory.Exists(sBackupFolder) Then
Directory.CreateDirectory(sBackupFolder)
End If
sBackupFolder &= "\" & DateTime.Now().ToString("yyyyMMddHHmmss") & ".bwbck"
Dim sBackupZipPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\DbBackup.zip"
' apro finestra di caricamento
If bLoadingWindow Then LoadingWndHelper.OpenLoadingWnd(ActiveIds.BACKUP, 2, "Backup", "Database backup", 15) ' Backup ' Database backup
Dim bOk As Boolean = True
' backup del Db corrente
Try
DataLayer.DbConfig.DataBaseDumpToFile(sBackupZipPath)
Catch ex As Exception
MessageBox.Show("Backup failed! Impossible to create the backup package!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
bOk = False
End Try
If bOk AndAlso File.Exists(sBackupZipPath) Then
If bLoadingWindow Then LoadingWndHelper.UpdateLoadingWnd(ActiveIds.BACKUP, 2, "Projects backup", 15, 100) ' Projects backup
' backup dei progetti correnti
Try
Using zip As New Ionic.Zip.ZipFile(sBackupFolder, Console.Out)
zip.AlternateEncodingUsage = ZipOption.Always
zip.AlternateEncoding = Text.Encoding.UTF8
zip.CompressionMethod = CompressionMethod.None
' aggiungo Db
zip.AddItem(sBackupZipPath, "")
' aggiungo cartella progetti
Dim sProjectFolder As String = Map.refMainWindowVM.MainWindowM.sDataDir & "\"
Dim sKey As String = ""
EgtGetKeyInfo(sKey)
sKey = sKey.Replace(" ", "")
Dim sUserFolder As String = ""
If Not IsNothing(sKey) AndAlso sKey.Length > 11 Then
sUserFolder = sKey.Substring(3, 6)
sProjectFolder &= sUserFolder
End If
zip.AddItem(sProjectFolder, sUserFolder)
' salvo lo zip
zip.Save()
End Using
Catch ex As Exception
MessageBox.Show("Backup failed! Impossible to create the backup package!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
bOk = False
End Try
End If
' se esiste zip del Db, lo elimino
If File.Exists(sBackupZipPath) Then
File.Delete(sBackupZipPath)
End If
' se richiesto faccio copia su external source
If m_bExternalBackupActive Then
If Directory.Exists(m_ExternalBackupFolderPath) Then
CopyForExternalBackup(sBackupFolder, m_ExternalBackupFolderPath)
Else
MessageBox.Show("External folder does not exist or is not reachable! Copy to external folder impossible!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
End If
End If
'chiudo finestra di caricamento
If bLoadingWindow Then LoadingWndHelper.CloseLoadingWnd(ActiveIds.BACKUP)
End Sub
Private Async Sub CopyForExternalBackup(sBackupFile As String, sExternalBackupFolder As String)
Using SourceStream As FileStream = File.Open(sBackupFile, FileMode.Open)
Dim sExternalBackupFile As String = sExternalBackupFolder & "\" & Path.GetFileName(sBackupFile)
Using DestinationStream As FileStream = File.Create(sExternalBackupFile)
Await SourceStream.CopyToAsync(DestinationStream)
End Using
End Using
End Sub
#End Region ' Backup
@@ -485,26 +624,130 @@ Public Class ConfigurationPageVM
''' Execute the Save. This method is invoked by the SaveCommand.
''' </summary>
Public Sub Restore()
If Not String.IsNullOrWhiteSpace(m_BackupFilePath) AndAlso Directory.Exists(Path.GetDirectoryName(m_BackupFilePath)) Then
If File.Exists(m_BackupFilePath) Then
If MessageBox.Show("Are you sure you want to restore this file?", "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning) = MessageBoxResult.OK Then
' backup del corrente
Try
File.Move(m_BackupFilePath, m_BackupFilePath & ".old")
File.Delete(m_BackupFilePath)
Catch ex As Exception
MessageBox.Show("Backup failed! Impossible to move or delete previous file!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
End Try
' restore di quello indicato
Try
Catch ex As Exception
MessageBox.Show("Backup failed! Impossible to create the backup package!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
End Try
Else Return
' recupero processo del supervisore
Dim sSupervisorName As String = "EgtBEAMWALL.SupervisorR32"
Dim localProc As Process() = Process.GetProcessesByName(sSupervisorName)
' verifico che sia chiuso
If localProc.Length > 0 Then
MessageBox.Show("Please verify the machine is stoped and close the supervisor before proceding with the restore operation!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
Return
End If
' verifico se esiste backup
Dim sBackupFolder As String = Map.refMainWindowVM.MainWindowM.sDataDir & "\Backup"
Dim nYear As Integer = 0
Dim nMonth As Integer = 0
Dim nDay As Integer = 0
Dim sRestorePath As String = ""
If Directory.Exists(sBackupFolder) Then
Dim YearDirList() As String = Directory.GetDirectories(sBackupFolder)
For YearIndex = YearDirList.Length - 1 To 0 Step -1
nYear = 0
Integer.TryParse(Path.GetFileName(YearDirList(YearIndex)), nYear)
Dim sYearDir As String = sBackupFolder & "\" & nYear
Dim MonthDirList() As String = Directory.GetDirectories(sYearDir)
For MonthIndex = MonthDirList.Length - 1 To 0 Step -1
nMonth = 0
Integer.TryParse(Path.GetFileName(MonthDirList(MonthIndex)), nMonth)
Dim sMonthDir As String = sYearDir & "\" & nMonth
Dim DayDirList() As String = Directory.GetDirectories(sMonthDir)
For DayIndex = DayDirList.Length - 1 To 0 Step -1
nDay = 0
Integer.TryParse(Path.GetFileName(DayDirList(DayIndex)), nDay)
Dim sDayDir As String = sMonthDir & "\" & nDay
Dim VersionList() As String = Directory.GetFiles(sDayDir)
If VersionList.Length > 0 Then
Dim nMaxVersion As Int64 = VersionList.Max(Function(x) Int64.Parse(Path.GetFileNameWithoutExtension(x)))
sRestorePath = sDayDir & "\" & nMaxVersion & ".bwbck"
Exit For
End If
Next
If Not String.IsNullOrEmpty(sRestorePath) Then Exit For
Next
If Not String.IsNullOrEmpty(sRestorePath) Then Exit For
Next
End If
If String.IsNullOrEmpty(sRestorePath) Then
MessageBox.Show("Restore impossible! Last backup not found!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
End If
If MessageBox.Show("Are you sure you want to restore the last backup from " & nYear & "\" & nMonth & "\" & nDay & "? If you proceed you will lose actual data!", "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning) <> MessageBoxResult.OK Then Return
Dim bDoBackup = False
Select Case MessageBox.Show("Do you want to do a backup of the current project before proceding with the restore?", "Information", MessageBoxButton.YesNoCancel, MessageBoxImage.Information)
Case MessageBoxResult.Yes
bDoBackup = True
Case MessageBoxResult.No
bDoBackup = False
Case MessageBoxResult.Cancel
MessageBox.Show("Restore operation aborted!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
Return
End Select
' apro finestra di caricamento
LoadingWndHelper.OpenLoadingWnd(ActiveIds.RESTORE, 3, "Restore", "Backup current", If(bDoBackup, 40, 10)) ' Restore ' Database Restore
If bDoBackup Then
Backup(False)
End If
' recupero cartella corrente dei progetti
Dim sProjectFolder As String = Map.refMainWindowVM.MainWindowM.sDataDir
Dim sKey As String = ""
EgtGetKeyInfo(sKey)
sKey = sKey.Replace(" ", "")
Dim sUserFolder As String = ""
If Not IsNothing(sKey) AndAlso sKey.Length > 11 Then
sUserFolder = sKey.Substring(3, 6)
End If
If Directory.Exists(sProjectFolder & "\" & sUserFolder) Then
' se faccio backup elimino cartella dei progetti
If bDoBackup Then
Directory.Delete(sProjectFolder & "\" & sUserFolder, True)
Else
' altrimenti la rinomino old
If Directory.Exists(sProjectFolder & "\" & sUserFolder & ".old") Then
Directory.Delete(sProjectFolder & "\" & sUserFolder & ".old", True)
End If
Directory.Move(sProjectFolder & "\" & sUserFolder, sProjectFolder & "\" & sUserFolder & ".old")
End If
End If
LoadingWndHelper.UpdateLoadingWnd(ActiveIds.RESTORE, 2, "Restore data extraction", If(bDoBackup, 40, 10), 80) ' Restore data extraction
' estraggo lo zip nella cartella Temp
Dim sRestoreDir As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\Restore"
If Directory.Exists(sRestoreDir) Then
Directory.Delete(sRestoreDir, True)
End If
Directory.CreateDirectory(sRestoreDir)
Dim bOk As Boolean = True
' apro file zip
Try
Using zip As New Ionic.Zip.ZipFile(sRestorePath, Console.Out)
' estraggo file da zip
zip.ExtractAll(sRestoreDir)
End Using
Catch ex1 As Exception
EgtOutLog("Error! Impossible importing Recovery file " & sRestorePath & "!")
EgtOutLog("Exception in zip: " & ex1.ToString())
MessageBox.Show("Impossible importing Recovery file!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
bOk = False
End Try
Dim sBackupTempPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\DbRestore"
LoadingWndHelper.UpdateLoadingWnd(ActiveIds.RESTORE, 3, "Database restore", 80, 100) ' Database restore
If bOk Then
' restore del Db
Try
DataLayer.DbConfig.DataBaseRestoreFromFile(sRestoreDir & "\DbBackup.zip", "", sBackupTempPath)
Catch ex As Exception
MessageBox.Show("Restore failed! Impossible to restore the backup Database!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
bOk = False
End Try
End If
If File.Exists(sRestoreDir & "\DbBackup.zip") Then
File.Delete(sRestoreDir & "\DbBackup.zip")
End If
If bOk Then
' sposto il backup al posto giusto
Directory.Move(sRestoreDir & "\" & sUserFolder, sProjectFolder & "\" & sUserFolder)
End If
If Directory.Exists(sRestoreDir) Then
Directory.Delete(sRestoreDir)
End If
LoadingWndHelper.CloseLoadingWnd(ActiveIds.RESTORE)
End Sub
#End Region ' Restore
@@ -141,6 +141,9 @@
<Reference Include="BouncyCastle.Crypto, Version=1.9.0.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
<HintPath>..\packages\Portable.BouncyCastle.1.9.0\lib\net40\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="DotNetZip, Version=1.16.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll</HintPath>
</Reference>
<Reference Include="EgtUILib, Version=2.4.3.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\ExtLibs\EgtUILib.dll</HintPath>
@@ -158,9 +161,6 @@
<Reference Include="Google.Protobuf, Version=3.21.9.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL">
<HintPath>..\packages\Google.Protobuf.3.21.9\lib\net45\Google.Protobuf.dll</HintPath>
</Reference>
<Reference Include="Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
<HintPath>..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="K4os.Compression.LZ4, Version=1.3.5.0, Culture=neutral, PublicKeyToken=2186fa9121ef231d, processorArchitecture=MSIL">
<HintPath>..\packages\K4os.Compression.LZ4.1.3.5\lib\net462\K4os.Compression.LZ4.dll</HintPath>
</Reference>
+1 -1
View File
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle" version="1.8.5" targetFramework="net472" />
<package id="DotNetZip" version="1.16.0" targetFramework="net472" />
<package id="EntityFramework" version="6.4.4" targetFramework="net452" />
<package id="Google.Protobuf" version="3.21.9" targetFramework="net472" />
<package id="Ionic.Zip" version="1.9.1.8" targetFramework="net472" />
<package id="K4os.Compression.LZ4" version="1.3.5" targetFramework="net472" />
<package id="K4os.Compression.LZ4.Streams" version="1.3.5" targetFramework="net472" />
<package id="K4os.Hash.xxHash" version="1.0.8" targetFramework="net472" />