From b3d005773db01537b831ae523224aaf124202fb7 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 27 Apr 2021 09:32:40 +0300 Subject: Attempt to fix auto update check. Fixed emulator ink consumption calc. --- .../MachineUpdate/MachineUpdateManager.cs | 72 +++++++++++++--------- 1 file changed, 43 insertions(+), 29 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs') 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 6ef2f946b..642707e87 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -914,6 +914,7 @@ namespace Tango.PPC.Common.MachineUpdate } catch (Exception ex) { + _isUpdating = false; OnFailed(ex, result, update_response, performDatabaseRollback, dbBackupFile, backupsFolder, null, localDataSource, _newPackageTempFolder); } @@ -929,48 +930,56 @@ namespace Tango.PPC.Common.MachineUpdate { return Task.Factory.StartNew(() => { - _isUpdating = true; + try + { + _isUpdating = true; - var machineServiceAddress = _settings.GetMachineServiceAddress(); + var machineServiceAddress = _settings.GetMachineServiceAddress(); - LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); + LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - String machineGuid = _machineProvider.Machine.Guid; + String machineGuid = _machineProvider.Machine.Guid; - Login(machineGuid).GetAwaiter().GetResult(); + Login(machineGuid).GetAwaiter().GetResult(); - LogManager.Log($"Checking if updates available..."); + LogManager.Log($"Checking if updates available..."); - CheckForUpdateRequest request = new CheckForUpdateRequest(); - request.Version = _app_manager.Version.ToString(); - request.FirmwareVersion = _app_manager.FirmwareVersion?.ToString(); + CheckForUpdateRequest request = new CheckForUpdateRequest(); + request.Version = _app_manager.Version.ToString(); + request.FirmwareVersion = _app_manager.FirmwareVersion?.ToString(); - try - { - request.MachineLastUpdated = _machineProvider.Machine.LastUpdated; + try + { + request.MachineLastUpdated = _machineProvider.Machine.LastUpdated; - using (ObservablesContext db = ObservablesContext.CreateDefault()) + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + request.Rmls = db.Rmls.ToList().Select(x => new UpdatedEntity(x)).ToList(); + request.HardwareVersions = db.HardwareVersions.ToList().Select(x => new UpdatedEntity(x)).ToList(); + request.Catalogs = db.ColorCatalogs.ToList().Select(x => new UpdatedEntity(x)).ToList(); + request.UsedRmlsGuids = db.Jobs.Select(x => x.RmlGuid).Distinct().ToList(); + } + } + catch (Exception ex) { - request.Rmls = db.Rmls.ToList().Select(x => new UpdatedEntity(x)).ToList(); - request.HardwareVersions = db.HardwareVersions.ToList().Select(x => new UpdatedEntity(x)).ToList(); - request.Catalogs = db.ColorCatalogs.ToList().Select(x => new UpdatedEntity(x)).ToList(); - request.UsedRmlsGuids = db.Jobs.Select(x => x.RmlGuid).Distinct().ToList(); + LogManager.Log(ex, "An error occurred while trying to fill the existing database entities before checking for updates."); } - } - catch (Exception ex) - { - LogManager.Log(ex, "An error occurred while trying to fill the existing database entities before checking for updates."); - } - CheckForUpdateResponse update_response = null; + CheckForUpdateResponse update_response = null; - update_response = _client.CheckForUpdates(request).Result; + update_response = _client.CheckForUpdates(request).Result; - LogManager.Log($"Check for update response received: {Environment.NewLine}{update_response.ToJsonString()}"); + LogManager.Log($"Check for update response received: {Environment.NewLine}{update_response.ToJsonString()}"); - _isUpdating = false; + _isUpdating = false; - return update_response; + return update_response; + } + catch (Exception ex) + { + _isUpdating = false; + throw ex; + } }); } @@ -986,7 +995,6 @@ namespace Tango.PPC.Common.MachineUpdate return Task.Factory.StartNew(() => { - _isUpdating = true; UpdateDBResponse update_response = null; var localDataSource = SettingsManager.Default.GetOrCreate().DataSource; bool performDatabaseRollback = false; @@ -994,6 +1002,8 @@ namespace Tango.PPC.Common.MachineUpdate try { + _isUpdating = true; + LogManager.Log("Starting database update..."); if (_machineProvider.MachineOperator.IsPrinting) @@ -1098,6 +1108,7 @@ namespace Tango.PPC.Common.MachineUpdate } catch (Exception ex) { + _isUpdating = false; OnFailed(ex, update_response, performDatabaseRollback, dbBackupFile, localDataSource); throw ex; } @@ -1495,6 +1506,7 @@ namespace Tango.PPC.Common.MachineUpdate } catch (Exception ex) { + _isUpdating = false; OnFailed(ex, result, null, performDatabaseRollback, dbBackupFile, backupsFolder, tempDbName, localDataSource, _newPackageTempFolder, publishInfo); } @@ -1579,6 +1591,8 @@ namespace Tango.PPC.Common.MachineUpdate } catch (Exception ex) { + _isUpdating = false; + try { if (stream != null) @@ -1728,7 +1742,7 @@ namespace Tango.PPC.Common.MachineUpdate } catch (Exception ex) { - Debug.WriteLine(ex); + LogManager.Log(ex, "Error occurred while checking for software update."); } _checkForUpdateTimer.Start(); -- cgit v1.3.1