aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-11-26 10:45:22 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-11-26 10:45:22 +0200
commit58f7128ac32d80cb6baf9bee7389eeef889067ae (patch)
tree5e0f955c814f79800bd7115b677b5042f0a3ffa2 /Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore
parenta70419a35bac0e053278002856499430edbbb598 (diff)
downloadTango-58f7128ac32d80cb6baf9bee7389eeef889067ae.tar.gz
Tango-58f7128ac32d80cb6baf9bee7389eeef889067ae.zip
Working on backup/restore...
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupFile.cs5
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupRestoreProgressEventArgs.cs5
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/BackupRestoreStage.cs10
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/DefaultBackupManager.cs37
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/BackupRestore/IBackupManager.cs3
5 files changed, 42 insertions, 18 deletions
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.