| ofs | hex dump | ascii |
|---|
| 0000 | 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 80 00 00 00 80 08 06 00 00 00 c3 3e 61 | .PNG........IHDR..............>a |
| 0020 | cb 00 00 00 04 73 42 49 54 08 08 08 08 7c 08 64 88 00 00 00 09 70 48 59 73 00 00 03 76 00 00 03 | .....sBIT....|.d.....pHYs...v... |
| 0040 | 76 01 7d d5 82 cc 00 00 00 19 74 45 58 74 53 6f 66 74 77 61 72 65 00 77 77 77 2e 69 6e 6b 73 63 | v.}.......tEXtSoftware.www.inksc |
| 0060 | 61 70 65 2e 6f 72 67 9b ee 3c 1a 00 00 19 94 49 44 41 54 78 9c ed 9d 79 7c 1b d5 b5 c7 bf 33 23 | ape.org..<.....IDATx...y|.....3# |
| 0080 | d9 96 f7 3d 51 9c 45 4e 82 b3 93 cd 31 21 04 08 09 21 40 53 12 20 b4 2c 09 7d d0 f7 a0 1b 65 2b | ...=Q.EN....1!...!@S...,.}....e+ |
| 00a0 | 14 02 64 81 02 2d ed 2b f0 da 3e de eb a7 ef f5 43 03 84 96 f5 b1 07 08 29 21 85 b0 26 6d 81 90 | ..d..-.+..>.....C.......)!..&m.. |
| 00c0 | 80 41 89 93 c8 d9 e3 55 b2 a4 d1 bc 3f 66 64 39 f6 95 ad 65 24 8d 83 7f 9f 8f 3e 96 34 33 f7 5e | .A.....U....?fd9...e$.....>.43.^ |
| 00e0 | eb fc ee b9 e7 9e 7b ee b9 92 a6 69 1c 6f f0 28 ae 42 a0 06 18 63 bc 46 01 c5 40 21 50 d0 ed 2f | ......{....i.o.(.B...c.F..@!P../ |
| 0100 | 40 33 d0 d2 ed ef 51 a0 1e d8 6e bc 76 38 55 77 73 fa fe 8b f4 40 ea ef 04 f0 28 ae 3c 60 36 30 | @3....Q...n.v8Uws....@....(.<`60 |
| 0120 | 17 a8 43 17 b8 33 55 d5 a1 93 e1 3d e0 0d 60 93 53 75 b7 a5 a8 ae b4 a0 df 11 c0 a3 b8 b2 88 08 | ..C..3U....=..`.Su.............. |
| 0140 | fc 0c 60 06 60 cf 50 73 02 c0 fb e8 64 d8 80 4e 08 7f 86 da 92 10 fa 0d 01 3c 8a 6b 26 b0 0c b8 | ..`.`.Ps....d..N.........<.k&... |
| 0160 | 18 28 cd 70 73 a2 e1 30 f0 38 b0 c6 a9 ba 37 67 ba 31 b1 c0 d2 04 f0 28 ae 11 e8 42 5f 86 3e a6 | .(.ps..0.8....7g.1.....(...B_.>. |
| 0180 | f7 27 ec 00 d6 a0 93 61 67 a6 1b 13 0d 96 24 80 47 71 d5 02 cb 81 c5 80 94 e1 e6 24 0b 0d 78 16 | .'.....ag.....$.Gq.........$..x. |
| 01a0 | b8 c7 a9 ba 3f c8 74 63 ba c3 52 04 f0 28 ae 53 81 db 80 05 99 6e 4b 8a b0 0e b8 db a9 ba df ca | ....?.tc..R..(.S.....nK......... |
| 01c0 | 74 43 c2 b0 04 01 3c 8a 6b 1e b0 12 38 35 d3 6d 49 13 de 02 56 3b 55 f7 fa 4c 37 24 a3 04 f0 28 | tC....<.k...85.mI...V;U..L7$...( |
| 01e0 | ae a1 c0 fd c0 92 8c 35 22 b3 78 12 b8 de a9 ba 77 67 aa 01 19 21 80 47 71 d9 80 6b 81 55 40 7e | .......5".x.....wg...!.Gq..k.U@~ |
| 0200 | da 1b 60 2d b4 a2 ff 0e 0f 3a 55 77 30 dd 95 a7 9d 00 1e c5 35 1b 78 08 98 98 d6 8a ad 8f 8f 81 | ..`-.....:Uw0.......5.x......... |
| 0220 | ef 3b 55 f7 a6 74 56 9a 36 02 78 14 97 02 dc 05 dc 42 ff b7 ec 53 05 0d f8 39 70 87 53 75 ab e9 | .;U..tV.6.x......B...S...9p.Su.. |
| 0240 | a8 30 2d 04 30 c6 fa b5 e8 1e bc 01 f4 8d 4d c0 25 e9 b0 0d e4 54 57 e0 51 5c e7 02 5b 19 10 7e | .0-.0.........M.%....TW.Q\..[..~ |
| 0260 | 3c 98 0d 6c 35 7e bb 94 22 65 1a c0 a3 b8 24 e0 5e e0 66 06 54 7e a2 d0 80 fb 80 5b 9d aa 3b 25 | <..l5~.."e....$.^.f.T~.....[..;% |
| 0280 | 82 4a 09 01 8c 05 9b 87 d1 fd f6 03 48 1e 8f 03 df 49 c5 42 93 e9 04 f0 28 ae 7c e0 69 60 be a9 | .J..........H....I.B....(.|.i`.. |
| 02a0 | 05 0f e0 35 e0 02 a7 ea 6e 35 b3 50 53 09 e0 51 5c 15 c0 4b 40 ad 69 85 a6 12 8a a4 5b 41 81 cc | ...5....n5.PS..Q\..K@.i.....[A.. |
| 02c0 | 7b 43 63 c4 07 c0 b9 4e d5 7d c0 ac 02 4d 23 80 47 71 0d 47 67 a9 65 57 ed 82 43 73 90 2e 19 4e | {Cc....N.}...M#.Gq.Gg.eW..Cs...N |
| 02e0 | 6e 5d 05 d9 c3 f2 71 0c ce 43 de ff 12 9a 96 43 d0 67 c7 5b 2f d1 fc 60 13 ca df 3b 32 dd d4 de | n]....q..C.....C.g.[/..`...;2... |
| 0300 | b0 03 98 ef 54 dd bb cc 28 cc 14 02 18 3d 7f 13 16 15 7e 60 7c 01 f9 77 4c a2 78 d6 60 24 f9 58 | ....T...(....=....~`|..wL.x.`$.X |
| 0320 | 7b 54 da fb 42 b7 bb 25 02 ed 05 1c b9 c7 8b fa 9a a9 da d6 4c ec 00 66 9b a1 09 92 26 80 31 e6 | {T..B..%............L..f....&.1. |
| 0340 | 6f c0 a2 6a 3f 78 f9 70 9c 2b a6 a1 64 2b c2 eb 3d 09 10 be a0 70 78 43 1e 1d 3f 35 4d db 9a 8d | o..j?x.p.+..d+..=....pxC..?5M... |
| 0360 | 0f 80 33 92 b5 09 92 f2 03 18 d6 fe d3 58 54 f8 d2 2f 27 33 f4 ee 19 51 85 df 2b 34 95 d2 39 cd | ..3..........XT../'3...Q..+4..9. |
| 0380 | 14 3f 33 c8 fc 86 99 83 5a e0 69 43 06 09 23 61 02 18 f3 fc 87 b1 a8 b5 1f fc ee 08 06 5d 3c 3a | .?3.....Z.iC..#a.............]<: |
| 03a0 | e9 72 1c 43 8e 62 fb 75 b9 09 2d 4a 09 e6 03 0f 1b b2 48 08 c9 68 80 7b b1 e8 3c 3f 58 5b cc 90 | .r.C.b.u..-J......H..h.{..<?X[.. |
| 03c0 | db a6 99 56 5e c5 29 6d b4 5e 62 d9 45 cb 8b d1 65 91 10 12 b2 01 0c 17 e5 0b 58 d1 c3 97 25 53 | ...V^.)m.^b.E...e.........X...%S |
| 03e0 | b8 e1 4c 72 87 17 08 2f 7b 7d f0 69 bd c6 f6 af f4 d7 a6 cd 5b a9 1e 62 e3 a4 b1 7e 2e 38 e5 08 | ..Lr.../{}.i........[..b...~.8.. |
| 0400 | e5 85 62 5f 4b 08 07 ef 2e 3a 88 ab d1 96 ca d6 27 0a 0d 58 e8 54 dd 2f c5 fb 60 dc 04 30 16 76 | ..b_K....:......'..X.T./..`..0.v |
| 0420 | b6 02 65 f1 56 96 0e 84 ae 1d cd 90 9f 4c 16 5e 3b da 0c 0f ae 51 39 70 38 f2 dd 47 5b df ef 7c | ..e.V........L.^;....Q9p8..G[..| |
| 0440 | 9f eb c8 e2 bf af 3b c2 e8 21 5e e1 f3 fb fe 59 c4 17 37 ec 66 64 73 52 c3 6e aa 70 08 98 12 ef | ......;..!^....Y..7.fdsR.n.p.... |
| 0460 | 02 52 5c 43 80 b1 a4 bb 16 ab 0a 7f 50 36 95 3f 18 2f bc 26 12 7e 77 f5 d5 ee f5 73 f5 03 25 7c | .R\C........P6.?./.&.~w....s..%| |
| 0480 | b1 d7 21 2c 63 d0 89 6d 74 4c c8 e6 cb 28 5a 22 c3 28 03 d6 1a 32 8a 19 f1 da 00 77 61 e1 55 3d | ..!,c..mtL...(Z".(...2.....wa.U= |
| 04a0 | db ed e3 b1 e5 f6 dc 23 12 08 c2 6f 1e 89 08 bf 30 1f ae bc 40 e6 de 1b 15 9e 5c d5 ca 15 e7 da | .......#...o....0...@.....\..... |
| 04c0 | c8 ca d2 9f 6b f7 fa f9 de 03 25 b4 75 08 7e 47 2d 48 dd 1d 95 1c 70 a8 56 25 c1 6c 74 19 c5 8c | ....k.....%.u.~G-H....p.V%.lt... |
| 04e0 | 98 09 60 44 f2 dc 12 6f 8b d2 85 60 6d 31 95 8b 46 0a af ad 7f 47 63 df 21 fd 7d 41 1e 5c bb 4c | ..`D...o...`m1..F....Gc.!.}A.\.L |
| 0500 | 61 da 04 89 fc 5c a8 2a f3 71 d5 39 8d dc ff fd 16 ec 76 7d 7c 6f f3 fa b9 7b ad 78 77 59 7e d9 | a....\.*.q.9......v}|o...{.xwY~. |
| 0520 | 51 86 9f 5d 6a 65 12 dc 62 c8 2a 26 c4 44 00 23 86 ef 21 ac 68 f4 01 48 50 78 e7 14 61 eb 8e 36 | Q..]je..b.*&.D.#..!.h..HPx..a..6 |
| 0540 | c3 ab 7f 0b 75 7e be f0 2c 99 41 82 59 dd b4 d1 ad 5c 76 66 c4 1e da b8 d5 1f 75 28 38 f1 aa 5c | ....u~..,.A.Y....\vf......u(8..\ |
| 0560 | 90 b1 2a 09 24 e0 21 43 66 7d 22 56 0d 70 2d 16 8e e1 0b 5e 3c 8c c2 49 62 b3 e4 d9 f5 21 fc 01 | ..*.$.!Cf}"V.p-....^<..Ib....!.. |
| 0580 | fd fd a8 61 12 b5 13 a3 73 f8 ea 73 f7 51 5e 92 03 80 aa 86 58 fd 48 85 f0 3e 9b ad 95 29 d7 56 | ...a....s..s.Q^.....X.H..>...).V |
| 05a0 | 01 96 25 c1 44 74 99 f5 89 3e 09 60 58 fd ab 92 6c 50 ca 10 ca b7 51 71 f3 24 e1 b5 2f 1b 34 3e | ..%.Dt...>.`X...lP....Qq.$../.4> |
| 05c0 | f8 58 ef d5 92 04 4b 16 f4 ad c0 6e fa 56 0b 92 a4 df f7 45 43 3b af 7c 50 22 bc 6f c4 19 01 72 | .X....K....n.V.....EC;.|P".o...r |
| 05e0 | 4a 75 bb c1 a2 24 58 65 c8 ae 57 c4 a2 01 ee c7 c2 a1 db d2 8d 35 64 97 f7 54 d5 9a 06 4f ac 8b | Ju...$Xe..W..........5d..T...O.. |
| 0600 | a8 f4 59 53 25 86 39 fb 26 c0 69 13 9b 18 3f 32 a7 f3 f3 03 4f e7 a1 aa 3d 9f 93 f0 53 b7 6a 48 | ..YS%.9.&.i...?2....O...=...S.jH |
| 0620 | e7 67 0b 92 20 1f 5d 76 bd a2 57 02 18 3b 76 2c bb 69 43 1d 95 c7 a0 ef 8c 11 5e 7b 67 ab 46 83 | .g....]v..W..;v,.iC.......^{g.F. |
| 0640 | 47 27 80 23 1b be 79 46 ec 13 9e d5 cb f6 63 53 f4 59 40 53 8b 8f ff 78 4e 6c 10 96 ba 5a a8 98 | G'.#..yF......cS.Y@S...xNl...Z.. |
| 0660 | 16 71 38 59 90 04 4b 0c 19 46 45 5f bf ca 4a 13 1b 63 3a 72 56 4d 42 b6 f7 fc 17 bc 1d f0 fc 86 | .q8Y..K..FE_..J..c:rVMB......... |
| 0680 | 88 e1 77 ee e9 32 f9 b9 b1 97 5b 55 d6 c1 d9 33 23 d3 c0 67 de 0a 71 b0 49 94 82 20 c4 f4 9b 8e | ..w..2....[U...3#..g..q.I....... |
| 06a0 | dd a9 6e 41 12 f4 2a c3 a8 04 30 36 6a 5a 76 af 5e 70 5e 05 65 73 aa 84 d7 5e de 18 a2 c5 c8 db | ..nA..*...06jZv.^p^.es...^...... |
| 06c0 | 31 b8 1c 4e 9f 11 ff e4 e5 e6 25 1e f2 73 b3 01 08 04 82 ac 7e 74 b0 f0 be 9c bc 26 6a 2e ad 3c | 1..N......%..s......~t.....&j..< |
| 06e0 | e6 3b 8b 91 e0 54 43 96 42 f4 a6 01 6e 4b 41 63 4c 81 66 93 28 59 29 76 f7 ee 3b 08 6f be 17 19 | .;...TC.B...nKAcL.f.(Y)v..;.o... |
| 0700 | fb 2f 5c 20 23 27 b0 e4 65 b7 69 5c f5 cd 48 64 d0 87 9f f9 f8 e8 0b b1 29 34 f6 db 36 e4 ac 63 | ./\.#'..e.i\..Hd........)4..6..c |
| 0720 | 2b b1 18 09 a2 ca 52 f8 d3 18 fb f3 2d bb 45 3b f4 6f d5 e4 55 17 09 af 3d f5 6a 08 d5 d0 fe 93 | +.....R.....-.E;.o..U...=.j..... |
| 0740 | 6a 24 c6 8d 4c dc 75 71 d1 ec 83 0c 1b ac 1b 98 9a a6 71 f7 63 e2 19 81 2c b5 33 63 79 4f 83 fb | j$..L.uq..........q.c...,.3cyO.. |
| 0760 | 80 43 e5 ab c2 40 c2 f5 9b 88 05 86 4c 7b 20 5a df 58 9e c2 c6 24 05 b5 22 8b 41 3f 16 bb 24 3e | .C...@......L{.Z.X...$..".A?..$> |
| 0780 | <using FluentFTP;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Core.DB;
using Tango.Core.Helpers;
using Tango.Core.IO;
using Tango.Integration.Operation;
using Tango.PMR.Synchronization;
using Tango.PPC.Common.Application;
using Tango.PPC.Common.Connection;
using Tango.PPC.Common.OS;
using Tango.PPC.Common.RemoteAssistance;
using Tango.PPC.Common.UWF;
using Tango.Settings;
using Tango.SharedUI.Helpers;
using Tango.SQLExaminer;
using Tango.Transport.Web;
namespace Tango.PPC.Common.MachineSetup
{
/// <summary>
/// Represents the PPC machine setup manager.
/// </summary>
/// <seealso cref="Tango.Core.ExtendedObject" />
/// <seealso cref="Tango.PPC.Common.MachineSetup.IMachineSetupManager" />
public class MachineSetupManager : ExtendedObject, IMachineSetupManager
{
private IRemoteAssistanceProvider _remoteAssistance;
private IUnifiedWriteFilterManager _uwf;
private IWindowsActivationManager _windows_activation_manager;
#region Events
/// <summary>
/// Occurs when there is a text log message available.
/// </summary>
public event EventHandler<string> ProgressLog;
/// <summary>
/// Occurs when the <see cref="CurrentStep" /> has changed.
/// </summary>
public event EventHandler<MachineSetupProgress> Progress;
#endregion
#region Properties
private MachineSetupProgress _status;
public MachineSetupProgress Status
{
get { return _status; }
private set { _status = value; RaisePropertyChangedAuto(); }
}
#endregion
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="MachineSetupManager"/> class.
/// </summary>
/// <param name="remoteAssistance">The remote assistance.</param>
public MachineSetupManager(IRemoteAssistanceProvider remoteAssistance, IUnifiedWriteFilterManager unifiedWriterFilterManager, IWindowsActivationManager windowsActivationManager)
{
_remoteAssistance = remoteAssistance;
_uwf = unifiedWriterFilterManager;
_windows_activation_manager = windowsActivationManager;
}
#endregion
#region Public Methods
/// <summary>
/// Performs a machine setup using the specified serial number and machine service address.
/// </summary>
/// <param name="serialNumber">The serial number.</param>
/// <param name="machineServiceAddress">The machine service address.</param>
/// <returns></returns>
public async Task<MachineSetupResult> Setup(string serialNumber, string machineServiceAddress)
{
TaskCompletionSource<MachineSetupResult> result = new TaskCompletionSource<MachineSetupResult>();
try
{
LogManager.Log($"Starting machine setup for serial number {serialNumber}...");
IMachineOperator op = null;
var settings = SettingsManager.Default.GetOrCreate<PPCSettings>();
//Connect to machine service and get matching packages for this machine.
UpdateProgress("Validating serial number", "Connecting to machine service...");
LogManager.Log($"Connecting to machine service on {machineServiceAddress}...");
MachineSetupRequest request = new MachineSetupRequest();
request.SerialNumber = serialNumber;
MachineSetupResponse setup_response = null;
try
{
using (var http = new WebTransportClient())
{
setup_response = await http.PostJson<MachineSetupRequest, MachineSetupResponse>(machineServiceAddress + "/api/PPC/MachineSetup", request);
}
}
catch (Exception ex)
{
throw LogManager.Log(ex, $"An error occurred while trying to contact machine service: {ex.FlattenMessage()}");
}
LogManager.Log($"Machine setup response received: {Environment.NewLine}{setup_response.ToJsonString()}");
if (setup_response.SetupFirmware)
{
//Connecting to machine...
LogManager.Log("Initiating machine connection...");
UpdateProgress("Connecting to machine", "Connecting...");
op = await DefaultMachineProvider.CreateMinimalMachineOperator((msg) =>
{
UpdateProgress("Connecting to machine", msg);
});
}
if (setup_response.SetupActivation)
{
LogManager.Log("Activating windows license...");
UpdateProgress("Activating operation system license", "Activating...");
await _windows_activation_manager.Activate(setup_response.OSKey);
}
if (setup_response.SetupRemoteAssistance)
{
LogManager.Log("Installing remote assistance...");
UpdateProgress("Installing remote assistance", "Installing...");
await _remoteAssistance.InstallRemoteAssistance(serialNumber);
}
if (setup_response.SetupUWF)
{
LogManager.Log("Activating unified write filter...");
UpdateProgress("Activating disk protection", "Activating...");
await _uwf.Setup();
}
//Create temporary folders for packages.
var _newPackageTempFolder = TemporaryManager.CreateFolder();
_newPackageTempFolder.Persist = true;
LogManager.Log($"Temporary package folder created: {_newPackageTempFolder}.");
//Download software package.
var tempFile = TemporaryManager.CreateFile(".zip");
LogManager.Log($"Temporary package zip file created: {tempFile}.");
LogManager.Log("Downloading software package...");
long fileSize = 0;
UpdateProgress("Downloading software package", "Downloading...", false);
await Task.Factory.StartNew(() =>
{
using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) =>
{
UpdateProgress("Downloading software package", "Downloading...", false, current, fileSize);
}))
{
LogManager.Log($"Connecting to storage blob with address {setup_response.BlobAddress}");
CloudBlockBlob blob = new CloudBlockBlob(new Uri(setup_response.BlobAddress));
LogManager.Log("Fetching blob attributes...");
blob.FetchAttributes();
fileSize = blob.Properties.Length;
LogManager.Log("Download size: " + fileSize + " bytes.");
LogManager.Log("Starting blob download...");
blob.DownloadToStream(fs);
}
});
UpdateProgress("Downloading software package", "Extracting package...");
LogManager.Log("Extracting downloaded zip file...");
//Extract software package.
ZipFile.ExtractToDirectory(tempFile, _newPackageTempFolder);
LogManager.Log("Copying latest updater utility to application path...");
//Copy new updater utility to app path.
File.Copy(Path.Combine(_newPackageTempFolder, "Tango.PPC.Updater.exe"), Path.Combine(PathHelper.GetStartupPath(), "Tango.PPC.Updater.exe"), true);
//Synchronize database
UpdateProgress("Updating Database", "Initializing...");
var localDataSource = SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource;
LogManager.Log($"Synchronizing database '{setup_response.DataSource.ToString()}' => '{localDataSource.ToString()}'...");
UpdateProgress("Updating Database", "Connecting to local database...");
LogManager.Log($"Connecting to local database at {localDataSource}...");
DbManager db = DbManager.FromAddress(localDataSource.Address);
LogManager.Log($"Ensuring {localDataSource.Catalog} database exists on the local machine...");
if (!db.Exists(localDataSource.Catalog))
{
UpdateProgress("Updating Database", "Creating new database...");
LogManager.Log("Database does not exist. Creating new database...");
db.Create(localDataSource.Catalog);
}
else
{
LogManager.Log("Database exists.");
}
db.Dispose();
LogManager.Log("Initializing database manager...");
db = DbManager.FromDataSource(localDataSource);
UpdateProgress("Updating Database", "Clearing current database...");
LogManager.Log("Clearing database...");
db.ClearDb();
LogManager.Log("Disposing database manager.");
db.Dispose();
LogManager.Log($"Initializing {nameof(ExaminerSequenceConfigurationRunner)}...");
UpdateProgress("Updating Database", "Initializing provisioning sequence...");
ExaminerSequenceConfigurationRunner runner = new ExaminerSequenceConfigurationRunner(
Path.Combine(_newPackageTempFolder, "Provision Scripts", "config.xml"),
Path.Combine(_newPackageTempFolder, "Provision Scripts"),
setup_response.DataSource,
localDataSource,
serialNumber);
runner.Log += (x, msg) =>
{
LogManager.Log(msg);
ProgressLog?.Invoke(this, msg);
};
runner.ScriptExecuting += (x, item) =>
{
LogManager.Log($"Executing script {item.ToString()}...");
UpdateProgress("Updating Database", item.Name + "...");
};
LogManager.Log("Starting synchronization process...");
try
{
await runner.Run();
LogManager.Log("Synchronization completed successfully!");
UpdateProgress("Updating Database", "Database synchronization completed successfully.");
}
catch (Exception ex)
{
throw LogManager.Log(ex, "Setup manager error while trying to synchronize database.");
}
if (setup_response.SetupFirmware)
{
//Updating firmware
UpdateProgress("Updating Firmware", "Connecting to firmware device...");
LogManager.Log("");
LogManager.Log("-------------------------------------------------------------------------");
LogManager.Log("Updating Firmware...");
UpdateProgress("Updating Firmware", "Loading firmware package...");
var tfpPath = Path.Combine(_newPackageTempFolder, "firmware_package.tfp");
var stream = new FileStream(tfpPath, FileMode.Open);
var handler = await op.UpgradeFirmware(stream);
handler.Failed += (_, ex) =>
{
stream.Dispose();
result.SetException(ex);
};
handler.Completed += (_, __) =>
{
UpdateProgress("Updating Firmware", "Firmware update completed successfully.");
stream.Dispose();
result.SetResult(new MachineSetupResult()
{
UpdatePackagePath = _newPackageTempFolder,
});
};
handler.Canceled += (_, __) =>
{
stream.Dispose();
result.SetException(new Exception("The operation has been canceled."));
};
handler.Progress += (_, e) =>
{
UpdateProgress("Updating Firmware", e.Message, false, e.Current, e.Total);
};
}
else
{
result.SetResult(new MachineSetupResult()
{
UpdatePackagePath = _newPackageTempFolder,
});
}
}
catch (Exception ex)
{
LogManager.Log(ex, "An error occurred in machine setup.");
result.SetException(ex);
}
return await result.Task;
}
#endregion
#region Protected Methods
protected virtual void UpdateProgress(String name, String message = "", bool isIntermediate = true, double progress = 0, double total = 0)
{
InvokeUINow(() =>
{
Status = new MachineSetupProgress()
{
Name = name,
Message = message,
IsIntermediate = isIntermediate,
Progress = progress,
Total = total,
};
Progress?.Invoke(this, Status);
});
UIHelper.DoEvents();
}
#endregion
}
}