diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-11-26 10:45:22 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-11-26 10:45:22 +0200 |
| commit | 58f7128ac32d80cb6baf9bee7389eeef889067ae (patch) | |
| tree | 5e0f955c814f79800bd7115b677b5042f0a3ffa2 /Software/Visual_Studio/PPC | |
| parent | a70419a35bac0e053278002856499430edbbb598 (diff) | |
| download | Tango-58f7128ac32d80cb6baf9bee7389eeef889067ae.tar.gz Tango-58f7128ac32d80cb6baf9bee7389eeef889067ae.zip | |
Working on backup/restore...
Diffstat (limited to 'Software/Visual_Studio/PPC')
10 files changed, 51 insertions, 65 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/BackupViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/BackupViewVM.cs index 067e40d08..dd561c5be 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/BackupViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/BackupViewVM.cs @@ -15,11 +15,11 @@ namespace Tango.PPC.BackupRestore.ViewModels { public class BackupViewVM : PPCViewModel { + private String _backupFileName; + [TangoInject] public IBackupManager BackupManager { get; set; } - public BackupSettings BackupSettings { get; set; } - private BackupRestoreProgressEventArgs _currentBackupProgress; public BackupRestoreProgressEventArgs CurrentBackupProgress { @@ -27,7 +27,6 @@ namespace Tango.PPC.BackupRestore.ViewModels set { _currentBackupProgress = value; RaisePropertyChangedAuto(); } } - private bool _isBackupJobs; public bool IsBackupJobs { @@ -100,6 +99,10 @@ namespace Tango.PPC.BackupRestore.ViewModels if (IsFree) { IsFree = false; + await BackupManager.CreateBackup(_backupFileName, BackupName, new BackupSettings() + { + Mode = IsBackupFull ? BackupMode.Full : BackupMode.Jobs, + }); await Task.Delay(10000); IsFree = true; } @@ -107,7 +110,7 @@ namespace Tango.PPC.BackupRestore.ViewModels public override void OnApplicationStarted() { - + } public override void OnApplicationReady() @@ -137,6 +140,7 @@ namespace Tango.PPC.BackupRestore.ViewModels if (result != null) { + _backupFileName = result.Path + ExplorerFileDefinition.Backup.Extension; BackupLocation = System.IO.Path.GetFileNameWithoutExtension(result.Path) + ExplorerFileDefinition.Backup.Extension; } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupFile.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupFile.cs index 4425aad9e..ebb7b9fcd 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupFile.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupFile.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.PMR.Exports; using Tango.Web; namespace Tango.PPC.Common.BackupRestore @@ -45,7 +46,7 @@ namespace Tango.PPC.Common.BackupRestore /// <summary> /// Gets or sets the job files. /// </summary> - public List<String> JobFiles { get; set; } + public List<JobFile> JobFiles { get; set; } /// <summary> /// Gets or sets the backup settings. @@ -58,7 +59,7 @@ namespace Tango.PPC.Common.BackupRestore public BackupFile() { Settings = new BackupSettings(); - JobFiles = new List<string>(); + JobFiles = new List<JobFile>(); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupRestoreProgressEventArgs.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupRestoreProgressEventArgs.cs index 9508755cb..d12db7b56 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupRestoreProgressEventArgs.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupRestoreProgressEventArgs.cs @@ -32,10 +32,5 @@ namespace Tango.PPC.Common.BackupRestore /// Gets or sets the progress stage. /// </summary> public BackupRestoreStage Stage { get; set; } - - /// <summary> - /// Gets or sets the message. - /// </summary> - public String Message { get; set; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupRestoreStage.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupRestoreStage.cs index efef2d4d0..3d5de1122 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupRestoreStage.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupRestoreStage.cs @@ -16,18 +16,18 @@ namespace Tango.PPC.Common.BackupRestore Initializing, //Backup + [Description("Backing up jobs...")] + BackingupJobs, [Description("Backing up data...")] BackingupDatabase, [Description("Backing up application...")] BackingupApplication, - [Description("Backing up settings...")] + [Description("Backing up user settings...")] BackingupSettings, - [Description("Writing settings...")] - WritingSettings, + [Description("Writing configuration...")] + WritingConfiguration, [Description("Compressing files...")] CompressingFiles, - [Description("Finalizing backup...")] - FinalizingBackup, //Restore [Description("Validating backup...")] diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/DefaultBackupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/DefaultBackupManager.cs index 1724dfa73..31bdefd5d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/DefaultBackupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/DefaultBackupManager.cs @@ -15,8 +15,9 @@ using Tango.BL; using Tango.Settings; using Tango.Core.DB; using System.Data.SqlClient; +using Ionic.Zip; -namespace Tango.PPC.UI.BackupRestore +namespace Tango.PPC.Common.BackupRestore { public class DefaultBackupManager : ExtendedObject, IBackupManager { @@ -42,6 +43,7 @@ namespace Tango.PPC.UI.BackupRestore { try { + //Basic LogManager.Log($"Starting backup operation to file {filePath}."); LogManager.Log($"Backup settings:\n{settings.ToJsonString()}"); OnProgress(BackupRestoreStage.Initializing); @@ -56,6 +58,7 @@ namespace Tango.PPC.UI.BackupRestore backupFile.MachineSerialNumber = _machineProvider.Machine.SerialNumber; backupFile.ApplicationVersion = _applicationManager.Version.ToString(); + //Firmware try { LogManager.Log("Extracting firmware version from local tfp package..."); @@ -73,6 +76,7 @@ namespace Tango.PPC.UI.BackupRestore if (settings.Mode == BackupMode.Jobs) { + //Jobs LogManager.Log("Starting jobs backup..."); OnProgress(BackupRestoreStage.BackingupJobs); using (ObservablesContext db = ObservablesContext.CreateDefault()) @@ -99,10 +103,12 @@ namespace Tango.PPC.UI.BackupRestore } else { + //User Settings LogManager.Log("Backing up application settings..."); OnProgress(BackupRestoreStage.BackingupSettings); backupFile.SettingsFile = File.ReadAllText(SettingsManager.Default.FilePath); + //Application Version LogManager.Log("Backing up application files..."); OnProgress(BackupRestoreStage.BackingupApplication); var files = Directory.GetFiles(AssemblyHelper.GetCurrentAssemblyFolder()).Where(x => Path.GetFileName(x) != BACKUP_FILE_NAME).ToList(); @@ -120,6 +126,7 @@ namespace Tango.PPC.UI.BackupRestore } } + //Database LogManager.Log("Backing up database..."); OnProgress(BackupRestoreStage.BackingupDatabase); try @@ -138,9 +145,10 @@ namespace Tango.PPC.UI.BackupRestore LogManager.Log("Database backup completed."); } + //Compression try { - OnProgress(BackupRestoreStage.WritingSettings); + OnProgress(BackupRestoreStage.WritingConfiguration); var backupFilePath = Path.Combine(tempFolder, BACKUP_FILE_NAME); LogManager.Log($"Writing backup configuration file '{backupFilePath}'..."); File.WriteAllText(backupFilePath, backupFile.ToJsonString()); @@ -150,12 +158,31 @@ namespace Tango.PPC.UI.BackupRestore throw new IOException("Error writing backup configuration file.", ex); } - //using (ZipFile zip = new ZipFile()) - //{ - //} + LogManager.Log($"Generating {filePath}..."); + using (ZipFile zip = new ZipFile()) + { + zip.AddDirectory(tempFolder); + + zip.SaveProgress += (x, e) => + { + if (e.EventType == ZipProgressEventType.Saving_BeforeWriteEntry) + { + LogManager.Log($"Compressing '{e.CurrentEntry.FileName}'..."); + OnProgress(BackupRestoreStage.CompressingFiles, e.EntriesSaved + 1, e.EntriesTotal, false); + } + }; + + zip.ParallelDeflateThreshold = -1; + zip.Save(filePath); + } + + //Done + LogManager.Log("Backup operation completed!!!"); + OnProgress(BackupRestoreStage.Done); } catch (Exception ex) { + OnProgress(BackupRestoreStage.Error); LogManager.Log(ex, "Could not complete the backup operation."); throw ex; } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/IBackupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/IBackupManager.cs index a50f0ab60..8ff8a434c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/IBackupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/IBackupManager.cs @@ -20,9 +20,10 @@ namespace Tango.PPC.Common.BackupRestore /// Creates a backup file containing database, application and firmware versions. /// </summary> /// <param name="filePath">The file path.</param> + /// <param name="name">The backup name.</param> /// <param name="settings">Backup configuration.</param> /// <returns></returns> - Task CreateBackup(String filePath, BackupSettings settings); + Task CreateBackup(String filePath, String name, BackupSettings settings); /// <summary> /// Restores a backup located in the specified file path. diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 83d5f7b98..cff1e5a71 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -125,6 +125,7 @@ <Compile Include="BackupRestore\BackupFile.cs" /> <Compile Include="BackupRestore\BackupSettings.cs" /> <Compile Include="BackupRestore\BackupRestoreStage.cs" /> + <Compile Include="BackupRestore\DefaultBackupManager.cs" /> <Compile Include="BackupRestore\IBackupManager.cs" /> <Compile Include="Connection\DefaultMachineProvider.cs" /> <Compile Include="Connection\IMachineProvider.cs" /> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/BackupRestore/DefaultBackupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/BackupRestore/DefaultBackupManager.cs deleted file mode 100644 index e73dde3ce..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/BackupRestore/DefaultBackupManager.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.PPC.Common.Application; -using Tango.PPC.Common.BackupRestore; - -namespace Tango.PPC.UI.BackupRestore -{ - public class DefaultBackupManager : IBackupManager - { - public event EventHandler<BackupRestoreProgressEventArgs> Progress; - - public DefaultBackupManager(IPPCApplicationManager applicationManager) - { - - } - - public Task CreateBackup(string filePath, BackupSettings settings) - { - throw new NotImplementedException(); - } - - public Task Restore(string filePath) - { - throw new NotImplementedException(); - } - - protected virtual void OnProgress(BackupRestoreStage stage, double progress = 0, double maxProgress = 100, bool isIntermediate = true) - { - Progress?.Invoke(this, new BackupRestoreProgressEventArgs() - { - Stage = stage, - Progress = progress, - MaxProgress = maxProgress, - IsIntermediate = isIntermediate, - }); - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index ca7bad41e..c28a49584 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -115,7 +115,6 @@ <Link>GlobalVersionInfo.cs</Link> </Compile> <Compile Include="Authentication\DefaultAuthenticationProvider.cs" /> - <Compile Include="BackupRestore\DefaultBackupManager.cs" /> <Compile Include="Connectivity\DefaultConnectivityProvider.cs" /> <Compile Include="Connectivity\WiFiAuthenticationView.xaml.cs"> <DependentUpon>WiFiAuthenticationView.xaml</DependentUpon> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 688a9b376..cb448bb0e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -25,7 +25,6 @@ using Tango.PPC.Common.Threading; using Tango.PPC.Common.UWF; using Tango.PPC.Common.Web; using Tango.PPC.UI.Authentication; -using Tango.PPC.UI.BackupRestore; using Tango.PPC.UI.Connectivity; using Tango.PPC.UI.Modules; using Tango.PPC.UI.Navigation; |
