aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-02-24 19:04:47 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-02-24 19:04:47 +0200
commit40746c60fed9e70f3cb7f6f12f55595a77a1adfa (patch)
tree815a77a25888aceed48d15a9ce2f977e0d9ee845 /Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
parent64b768178dc9e64293a52c1b6d2631709af9502a (diff)
downloadTango-40746c60fed9e70f3cb7f6f12f55595a77a1adfa.tar.gz
Tango-40746c60fed9e70f3cb7f6f12f55595a77a1adfa.zip
Fixed PPC and Machine Studio issues before next release.
Started working on Advanced Installer libraries.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs167
1 files changed, 96 insertions, 71 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
index 6fd53bce2..2a53d765e 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
@@ -203,7 +203,7 @@ namespace Tango.PPC.Common.MachineUpdate
LogManager.Log($"Initializing {nameof(ExaminerSequenceConfigurationRunner)}...");
- UpdateProgress("Updating Database", "Initializing provisioning sequence...");
+ UpdateProgress("Updating Database", "Initializing update sequence...");
ExaminerSequenceConfigurationRunner runner = new ExaminerSequenceConfigurationRunner(
Path.Combine(_newPackageTempFolder, "Update Scripts", "config.xml"),
@@ -318,62 +318,70 @@ namespace Tango.PPC.Common.MachineUpdate
/// <param name="serialNumber">The serial number.</param>
/// <param name="machineServiceAddress">The machine service address.</param>
/// <returns></returns>
- public Task UpdateDB(DbCompareResult dbCompareResult)
+ public Task UpdateDB(DbCompareResult dbCompareResult, String serialNumber)
{
return Task.Factory.StartNew(() =>
{
LogManager.Log("Starting database update...");
- LogManager.Log("Looking for OverrideData script on application path...");
+ LogManager.Log("Looking for update scripts configuration on application path...");
- String config_file = Path.Combine(PathHelper.GetStartupPath(), "Update Scripts", "OverrideData.xml");
+ String config_file = Path.Combine(PathHelper.GetStartupPath(), "Update Scripts", "config.xml");
if (!File.Exists(config_file))
{
- config_file = Path.Combine(PathHelper.GetStartupPath(), "Provision Scripts", "OverrideData.xml");
- }
-
- if (!File.Exists(config_file))
- {
- throw LogManager.Log(new FileNotFoundException("Could not locate OverrideData.xml file on application folder."));
+ throw LogManager.Log(new FileNotFoundException($"Could not locate '{config_file}' file on application folder."));
}
UpdateDBResponse update_response = dbCompareResult.UpdateDBResponse;
var localDataSource = SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource;
- LogManager.Log($"Overriding database static tables '{update_response.DataSource.ToString()}' => '{localDataSource.ToString()}'...");
+ LogManager.Log($"Updating database '{update_response.DataSource.ToString()}' => '{localDataSource.ToString()}'...");
- ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(config_file);
- builder.SetSource(update_response.DataSource);
- builder.SetTarget(localDataSource);
- builder.Synchronize();
+ ExaminerSequenceConfiguration config_sequence = ExaminerSequenceConfiguration.FromFile(config_file);
- var config = builder.Build();
-
- ExaminerProcess process = new ExaminerProcess(config, ExaminerProcessType.Data);
- process.Progress += (x, msg) =>
+ foreach (var item in config_sequence.Items.Where(x => x.Type == ExaminerSequenceItemType.Data).OrderBy(x => x.Index))
{
- LogManager.Log(msg);
- };
+ LogManager.Log($"Executing update script '{item.FileName}...'");
- LogManager.Log("Starting synchronization process...");
-
- try
- {
- var result = process.Execute().Result;
+ ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(Path.Combine(Path.GetDirectoryName(config_file), item.FileName));
+ builder.SetSource(update_response.DataSource);
+ builder.SetTarget(localDataSource);
- if (result.ExitCode != ExaminerProcessExitCode.Success)
+ if (item.RequiresSerialNumber)
{
- throw LogManager.Log(new InvalidDataException(String.Format("OverrideData script has terminated with exit code '{0}'.", result.ExitCode)));
+ builder.SetMachineSerialNumber(serialNumber);
}
- LogManager.Log("Synchronization completed successfully!");
- }
- catch (Exception ex)
- {
- throw LogManager.Log(ex, "Setup manager error while trying to update the database.");
+ builder.Synchronize();
+
+ var config = builder.Build();
+
+ ExaminerProcess process = new ExaminerProcess(config, ExaminerProcessType.Data);
+ process.Progress += (x, msg) =>
+ {
+ LogManager.Log(msg);
+ };
+
+ try
+ {
+ var result = process.Execute().Result;
+
+ if (result.ExitCode != ExaminerProcessExitCode.Success)
+ {
+ throw LogManager.Log(new InvalidDataException(String.Format("OverrideData script has terminated with exit code '{0}'.", result.ExitCode)));
+ }
+
+ LogManager.Log("Script executed successfully.");
+ }
+ catch (Exception ex)
+ {
+ throw LogManager.Log(ex, "Setup manager error while trying to update the database.");
+ }
}
+
+ LogManager.Log("Update completed successfully.");
});
}
@@ -391,18 +399,13 @@ namespace Tango.PPC.Common.MachineUpdate
LogManager.Log($"Checking if database update is required for serial number {serialNumber}...");
- LogManager.Log("Looking for OverrideData script on application path...");
+ LogManager.Log("Looking for update scripts configuration on application path...");
- String config_file = Path.Combine(PathHelper.GetStartupPath(), "Update Scripts", "OverrideData.xml");
+ String config_file = Path.Combine(PathHelper.GetStartupPath(), "Update Scripts", "config.xml");
if (!File.Exists(config_file))
{
- config_file = Path.Combine(PathHelper.GetStartupPath(), "Provision Scripts", "OverrideData.xml");
- }
-
- if (!File.Exists(config_file))
- {
- throw LogManager.Log(new FileNotFoundException("Could not locate OverrideData.xml file on application folder."));
+ throw LogManager.Log(new FileNotFoundException($"Could not locate '{config_file}' file on application folder."));
}
LogManager.Log($"Connecting to machine service on {machineServiceAddress}...");
@@ -420,53 +423,75 @@ namespace Tango.PPC.Common.MachineUpdate
var localDataSource = SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource;
- LogManager.Log($"Comparing database static tables '{update_response.DataSource.ToString()}' => '{localDataSource.ToString()}'...");
+ LogManager.Log($"Comparing database '{update_response.DataSource.ToString()}' => '{localDataSource.ToString()}'...");
var report_file = TemporaryManager.CreateFile(".xml");
- ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(config_file);
- builder.SetSource(update_response.DataSource);
- builder.SetTarget(localDataSource);
- builder.SetReportFile(report_file);
+ ExaminerSequenceConfiguration config_sequence = ExaminerSequenceConfiguration.FromFile(config_file);
- var config = builder.Build();
+ bool has_differences = false;
- ExaminerProcess process = new ExaminerProcess(config, ExaminerProcessType.Data);
- process.Progress += (x, msg) =>
+ foreach (var item in config_sequence.Items.Where(x => x.Type == ExaminerSequenceItemType.Data).OrderBy(x => x.Index))
{
- LogManager.Log(msg);
- };
+ LogManager.Log($"Executing update script '{item.FileName}...'");
- LogManager.Log("Starting comparison process...");
- LogManager.Log("Generating report on " + report_file);
+ ExaminerConfigurationBuilder builder = new ExaminerConfigurationBuilder(Path.Combine(Path.GetDirectoryName(config_file), item.FileName));
+ builder.SetSource(update_response.DataSource);
+ builder.SetTarget(localDataSource);
+ builder.SetReportFile(report_file);
- try
- {
- var result = process.Execute().Result;
-
- if (result.ExitCode != ExaminerProcessExitCode.Success)
+ if (item.RequiresSerialNumber)
{
- throw LogManager.Log(new InvalidDataException(String.Format("OverrideData script has terminated with exit code '{0}'.", result.ExitCode)));
+ builder.SetMachineSerialNumber(serialNumber);
}
- LogManager.Log("Comparison completed successfully!");
- LogManager.Log("Loading report file...");
+ var config = builder.Build();
- ExaminerDataReport report = ExaminerDataReport.FromFile(report_file);
- report_file.Delete();
+ ExaminerProcess process = new ExaminerProcess(config, ExaminerProcessType.Data);
+ process.Progress += (x, msg) =>
+ {
+ LogManager.Log(msg);
+ };
- LogManager.Log("Comparison summary: \n" + report.Totals.ToJsonString());
+ LogManager.Log("Starting comparison process...");
+ LogManager.Log("Generating report on " + report_file);
- return new DbCompareResult()
+ try
{
- RequiresUpdate = report.HasDifferences,
- UpdateDBResponse = update_response,
- };
+ var result = process.Execute().Result;
+
+ if (result.ExitCode != ExaminerProcessExitCode.Success)
+ {
+ throw LogManager.Log(new InvalidDataException(String.Format("Update script has terminated with exit code '{0}'.", result.ExitCode)));
+ }
+
+ LogManager.Log("Comparison completed successfully!");
+ LogManager.Log("Loading report file...");
+
+ ExaminerDataReport report = ExaminerDataReport.FromFile(report_file);
+ report_file.Delete();
+
+ LogManager.Log("Comparison summary: \n" + report.Totals.ToJsonString());
+
+ if (report.HasDifferences)
+ {
+ has_differences = true;
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ throw LogManager.Log(ex, "Update manager error while trying to compare the database.");
+ }
}
- catch (Exception ex)
+
+ LogManager.Log("Comparison completed successfully.");
+
+ return new DbCompareResult()
{
- throw LogManager.Log(ex, "Update manager error while trying to compare the database.");
- }
+ RequiresUpdate = has_differences,
+ UpdateDBResponse = update_response,
+ };
});
}