aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-11-28 16:53:09 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-11-28 16:53:09 +0200
commite6e91a5c5435e524876d44d91b92c90f990a60c7 (patch)
treeec95738b8d9b349c94255ffdb1748e893b9a6cec /Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs
parent242cb9fd566647406792d63547b61ec1d6a5f3bc (diff)
downloadTango-e6e91a5c5435e524876d44d91b92c90f990a60c7.tar.gz
Tango-e6e91a5c5435e524876d44d91b92c90f990a60c7.zip
Implemented setup and update notifications from PPC to service.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs66
1 files changed, 55 insertions, 11 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs
index 29c5bc6a2..537e652e6 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs
@@ -99,6 +99,51 @@ namespace Tango.PPC.Common.MachineSetup
});
}
+ private async void OnFailed(Exception ex, TaskCompletionSource<MachineSetupResult> completionSource, MachineSetupResponse response)
+ {
+ LogManager.Log(ex, "An error occurred in machine setup.");
+
+ completionSource.SetException(ex);
+
+ if (response != null)
+ {
+ try
+ {
+ var result = await _client.NotifyUpdateCompleted(new MachineUpdateCompletedRequest()
+ {
+ Token = response.NotifyCompletedToken,
+ Status = BL.Enumerations.TangoUpdateStatuses.SetupFailed,
+ FailedReason = ex.FlattenMessage(),
+ });
+ }
+ catch (Exception xx)
+ {
+ LogManager.Log(xx, "Error notifying setup completed.");
+ }
+ }
+ }
+
+ private async void OnCompleted(MachineSetupResult result, TaskCompletionSource<MachineSetupResult> completionSource, MachineSetupResponse response)
+ {
+ completionSource.SetResult(result);
+
+ if (response != null)
+ {
+ try
+ {
+ var r = await _client.NotifyUpdateCompleted(new MachineUpdateCompletedRequest()
+ {
+ Token = response.NotifyCompletedToken,
+ Status = BL.Enumerations.TangoUpdateStatuses.SetupCompleted,
+ });
+ }
+ catch (Exception xx)
+ {
+ LogManager.Log(xx, "Error notifying setup completed.");
+ }
+ }
+ }
+
#endregion
#region Public Methods
@@ -113,6 +158,8 @@ namespace Tango.PPC.Common.MachineSetup
{
TaskCompletionSource<MachineSetupResult> result = new TaskCompletionSource<MachineSetupResult>();
+ MachineSetupResponse setup_response = null;
+
try
{
LogManager.Log($"Starting machine setup for serial number {serialNumber}...");
@@ -135,8 +182,6 @@ namespace Tango.PPC.Common.MachineSetup
request.DeviceID = await _windows_manager.GetDeviceId();
request.DeviceName = await _windows_manager.GetDeviceName();
- MachineSetupResponse setup_response = null;
-
try
{
LogManager.Log($"Sending setup request...\n{request.ToJsonString()}");
@@ -180,7 +225,7 @@ namespace Tango.PPC.Common.MachineSetup
{
LogManager.Log("Installing remote assistance...");
UpdateProgress("Installing remote assistance", "Installing...");
- await _remoteAssistance.InstallRemoteAssistance(serialNumber,settings.DeploymentSlot.ToString());
+ await _remoteAssistance.InstallRemoteAssistance(serialNumber, settings.DeploymentSlot.ToString());
}
if (setup_response.SetupUWF)
@@ -324,21 +369,21 @@ namespace Tango.PPC.Common.MachineSetup
handler.Failed += (_, ex) =>
{
stream.Dispose();
- result.SetException(ex);
+ OnFailed(ex, result, setup_response);
};
handler.Completed += (_, __) =>
{
UpdateProgress("Updating Firmware", "Firmware update completed successfully.");
stream.Dispose();
- result.SetResult(new MachineSetupResult()
+ OnCompleted(new MachineSetupResult()
{
UpdatePackagePath = _newPackageTempFolder,
- });
+ }, result, setup_response);
};
handler.Canceled += (_, __) =>
{
stream.Dispose();
- result.SetException(new Exception("The operation has been canceled."));
+ OnFailed(new Exception("The operation has been canceled."), result, setup_response);
};
handler.Progress += (_, e) =>
{
@@ -347,16 +392,15 @@ namespace Tango.PPC.Common.MachineSetup
}
else
{
- result.SetResult(new MachineSetupResult()
+ OnCompleted(new MachineSetupResult()
{
UpdatePackagePath = _newPackageTempFolder,
- });
+ }, result, setup_response);
}
}
catch (Exception ex)
{
- LogManager.Log(ex, "An error occurred in machine setup.");
- result.SetException(ex);
+ OnFailed(ex, result, setup_response);
}
return await result.Task;