1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.Core.Commands;
using Tango.FSE.BL;
using Tango.FSE.Common;
using Tango.FSE.Common.RemoteUpgrade;
namespace Tango.FSE.Upgrade.ViewModels
{
public class FirmwareUpgradeViewVM : RemoteUpgradeViewModel
{
private List<TangoVersion> _tangoVersions;
public List<TangoVersion> TangoVersions
{
get { return _tangoVersions; }
set { _tangoVersions = value; RaisePropertyChangedAuto(); }
}
private TangoVersion _selectedVersion;
public TangoVersion SelectedVersion
{
get { return _selectedVersion; }
set { _selectedVersion = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
private bool _useExistingTfpFile;
public bool UseExistingTfpFile
{
get { return _useExistingTfpFile; }
set { _useExistingTfpFile = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
private String _existingTfpFileLocation;
public String ExistingTfpFileLocation
{
get { return _existingTfpFileLocation; }
set { _existingTfpFileLocation = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
private String _existingTfpFileVersion;
public String ExistingTfpFileVersion
{
get { return _existingTfpFileVersion; }
set { _existingTfpFileVersion = value; RaisePropertyChangedAuto(); }
}
private RemoteUpgradeHandler _handler;
public RemoteUpgradeHandler Handler
{
get { return _handler; }
set { _handler = value; RaisePropertyChangedAuto(); }
}
public RelayCommand SelectExistingTfpFileLocationCommand { get; set; }
public RelayCommand GeneratePackageCommand { get; set; }
public RelayCommand ContinueCommand { get; set; }
public FirmwareUpgradeViewVM()
{
SelectExistingTfpFileLocationCommand = new RelayCommand(SelectExistingTfpFileLocation);
GeneratePackageCommand = new RelayCommand(GeneratePackage, () => SelectedVersion != null);
ContinueCommand = new RelayCommand(ContinueWithExistingTfpFile, () => ExistingTfpFileLocation != null);
}
public override void OnBeforeNavigatedTo()
{
base.OnBeforeNavigatedTo();
if (UseExistingTfpFile && !MachineProvider.IsConnected)
{
UseExistingTfpFile = false;
}
Handler = new RemoteUpgradeHandler("Ready");
}
private async void SelectExistingTfpFileLocation()
{
var result = await StorageProvider.OpenFile("Select existing firmware package file", "Tango Firmware Package|*.tfp");
if (result)
{
try
{
LogManager.Log("Validating firmware package file...");
using (FileStream s = File.OpenRead(result.SelectedItem))
{
var package = MachineProvider.MachineOperator.GetFirmwarePackageInfo(s).Result;
package.Validate();
ExistingTfpFileVersion = package.GetMcuVersion().ToString();
}
}
catch (Exception ex)
{
await NotificationProvider.ShowError($"Error loading the selected tfp file.\n{ex.FlattenMessage()}");
return;
}
ExistingTfpFileLocation = result.SelectedItem;
}
}
public async override void OnNavigatedTo()
{
base.OnNavigatedTo();
if (TangoVersions == null)
{
try
{
TangoVersions = (await Services.TangoVersionsService.GetAllTangoVersions()).DistinctBy(x => x.FirmwareVersion).Take(10).ToList();
SelectedVersion = TangoVersions.FirstOrDefault();
}
catch (Exception ex)
{
LogManager.Log(ex, "Error retrieving tango versions.");
await NotificationProvider.ShowError($"Error retrieving Tango versions.\n{ex.FlattenMessage()}");
}
}
}
private async void GeneratePackage()
{
try
{
IsFree = false;
var tempTfpFile = TemporaryManager.CreateImaginaryFile(".tfp");
Handler = await RemoteUpgradeManager.CreateTfpFile(SelectedVersion, tempTfpFile);
await Handler.WaitForCompletion();
await ModularNavigationManager.NavigateTo<FirmwareUpgradeGeneratedViewVM.NavigationObject>(Navigation.RemoteUpgradeView.FirmwareUpgradeGeneratedView, new FirmwareUpgradeGeneratedViewVM.NavigationObject()
{
IsExistingTfpFile = false,
TfpFileLocation = tempTfpFile,
SelectedVersion = SelectedVersion,
}, false);
}
catch (OperationCanceledException)
{
//Aborted...
}
catch (AuthorizationException ex)
{
await NotificationProvider.ShowError(ex.Message);
}
catch (Exception ex)
{
LogManager.Log(ex, "Error generating remote firmware upgrade package.");
}
finally
{
IsFree = true;
}
}
private async void ContinueWithExistingTfpFile()
{
await ModularNavigationManager.NavigateTo<FirmwareUpgradeGeneratedViewVM.NavigationObject>(Navigation.RemoteUpgradeView.FirmwareUpgradeGeneratedView, new FirmwareUpgradeGeneratedViewVM.NavigationObject()
{
IsExistingTfpFile = true,
TfpFileLocation = ExistingTfpFileLocation,
}, false);
}
}
}
|