blob: 743561e8b9707473cd15b72fbbb2f4b4a42a4646 (
plain)
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
|
using Microsoft.Azure.Management.AppService.Fluent;
using Microsoft.Azure.Management.Fluent;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Tango.AzureUtils.Environment;
using Tango.AzureUtils.Firmware;
using Tango.BL.Enumerations;
using Tango.Core.Commands;
namespace Tango.AzureUtils.UI.ViewModels
{
public class EnvironmentFirmwareUpgradeViewVM : AzureDashboardViewModel
{
private FirmwareManager _firmwareManager;
private List<IWebAppBase> _deploymentSlots;
public List<IWebAppBase> DeploymentSlots
{
get { return _deploymentSlots; }
set { _deploymentSlots = value; RaisePropertyChangedAuto(); }
}
private IWebAppBase _selectedDeploymentSlot;
public IWebAppBase SelectedDeploymentSlot
{
get { return _selectedDeploymentSlot; }
set { _selectedDeploymentSlot = value; RaisePropertyChangedAuto(); }
}
private List<MachineTypes> _machineTypes;
public List<MachineTypes> MachineTypes
{
get { return _machineTypes; }
set { _machineTypes = value; RaisePropertyChangedAuto(); }
}
private MachineTypes _selectedMachineType;
public MachineTypes SelectedMachineType
{
get { return _selectedMachineType; }
set { _selectedMachineType = value; RaisePropertyChangedAuto(); }
}
private String _filePath;
public String FilePath
{
get { return _filePath; }
set { _filePath = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
}
private String _firmwareVersion;
public String FirmwareVersion
{
get { return _firmwareVersion; }
set { _firmwareVersion = value; RaisePropertyChangedAuto(); }
}
public RelayCommand UpgradeFirmwareCommand { get; set; }
public RelayCommand BrowseFileCommand { get; set; }
public EnvironmentFirmwareUpgradeViewVM()
{
UpgradeFirmwareCommand = new RelayCommand(UpgradeFirmware, () => FilePath != null);
BrowseFileCommand = new RelayCommand(BrowseFile);
MachineTypes = Enum.GetValues(typeof(MachineTypes)).Cast<MachineTypes>().ToList();
}
public override void OnAuthenticated(IAzure azure, List<IWebAppBase> apps)
{
DeploymentSlots = apps.Where(x => x.Name.Contains("MachineService")).ToList();
SelectedDeploymentSlot = DeploymentSlots.FirstOrDefault(x => x.Name.EndsWith("DEV"));
_firmwareManager = new FirmwareManager(azure);
_firmwareManager.ConfirmationRequired += ConfirmationHandler;
_firmwareManager.Progress += ProgressHandler;
}
private async void BrowseFile()
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Select Firmware Package";
dlg.Filter = "Tango Firmware Package Files|*.tfp";
if (dlg.ShowDialog().Value)
{
FilePath = dlg.FileName;
try
{
FirmwareVersion = await _firmwareManager.GetFirmwareVersion(FilePath);
}
catch (Exception ex)
{
FilePath = null;
StatusManager.UpdateStatus(ex);
}
}
}
private async void UpgradeFirmware()
{
try
{
if (!Validate()) return;
IsFree = false;
await _firmwareManager.InjectFirmwarePackage(SelectedDeploymentSlot, SelectedMachineType, FilePath, null);
}
catch (Exception ex)
{
StatusManager.UpdateStatus(ex);
}
finally
{
RequireRefresh();
IsFree = true;
}
}
protected override void OnRefreshRequired()
{
base.OnRefreshRequired();
var old = SelectedDeploymentSlot;
SelectedDeploymentSlot = null;
SelectedDeploymentSlot = old;
}
}
}
|