blob: 40982a4caaa651eeb25851f0aee3ca4f7a94cad9 (
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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Tango.BL.Entities;
using Tango.Core.Commands;
using Tango.FSE.Common;
using Tango.FSE.PPCConsole.Dialogs;
using Tango.PPC.Shared.Updates;
using static Tango.SharedUI.Controls.NavigationControl;
namespace Tango.FSE.PPCConsole.ViewModels
{
/// <summary>
/// Represents the remote system software/firmware updates view model.
/// </summary>
/// <seealso cref="Tango.FSE.Common.FSEViewModel" />
/// <seealso cref="Tango.SharedUI.Controls.NavigationControl.INavigationViewModel" />
public class UpdatesViewVM : FSEViewModel, INavigationViewModel
{
private bool _loaded;
private ICollectionView _updatesView;
private ICollectionView _packagesView;
#region Properties
private List<TangoUpdate> _updates;
/// <summary>
/// Gets or sets the list of history software updates.
/// </summary>
public List<TangoUpdate> Updates
{
get { return _updates; }
set { _updates = value; RaisePropertyChangedAuto(); }
}
private List<PackageInstallation> _packages;
/// <summary>
/// Gets or sets the history of installed packages.
/// </summary>
public List<PackageInstallation> Packages
{
get { return _packages; }
set { _packages = value; RaisePropertyChangedAuto(); }
}
private String _filter;
/// <summary>
/// Gets or sets the search filter.
/// </summary>
public String Filter
{
get { return _filter; }
set { _filter = value; RaisePropertyChangedAuto(); OnFilterChanged(); }
}
#endregion
#region Commands
/// <summary>
/// Reloads the updates from the remote machine.
/// </summary>
public RelayCommand RefreshCommand { get; set; }
/// <summary>
/// Invokes a detailed dialog of the selected update.
/// </summary>
public RelayCommand<TangoUpdate> OpenUpdateCommand { get; set; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="UpdatesViewVM"/> class.
/// </summary>
public UpdatesViewVM()
{
OpenUpdateCommand = new RelayCommand<TangoUpdate>(OpenUpdate);
RefreshCommand = new RelayCommand(RefreshUpdates);
}
#endregion
#region Override Methods
public override void OnNavigatedTo()
{
base.OnNavigatedTo();
LoadMachineUpdates();
}
public override void OnApplicationStarted()
{
base.OnApplicationStarted();
MachineProvider.MachineConnected += MachineProvider_MachineConnected;
}
#endregion
#region Event Handlers
private void MachineProvider_MachineConnected(object sender, Common.Connection.MachineConnectedEventArgs e)
{
_loaded = false;
if (MachineProvider.ConnectionType.IsRemote())
{
if (IsVisible)
{
InvokeUI(() =>
{
LoadMachineUpdates();
});
}
}
}
#endregion
#region Private Methods
private void RefreshUpdates()
{
_loaded = false;
LoadMachineUpdates();
}
private async void OpenUpdate(TangoUpdate update)
{
await NotificationProvider.ShowDialog(new MachineUpdateViewVM() { Update = update });
}
private void OnFilterChanged()
{
_updatesView?.Refresh();
_packagesView?.Refresh();
}
private async void LoadMachineUpdates()
{
if (!MachineProvider.IsConnected || !MachineProvider.ConnectionType.IsRemote()) return;
if (!_loaded)
{
try
{
IsFree = false;
await Task.Delay(1000);
var result = await MachineUpdatesProvider.GetUpdates();
Updates = result.Updates.Where(x => !x.IsOfflineFirmwareUpgrade).ToList();
Packages = result.Packages.ToList();
_filter = null;
RaisePropertyChanged(nameof(Filter));
_updatesView = CollectionViewSource.GetDefaultView(Updates);
_updatesView.Filter = OnUpdatesFilter;
_packagesView = CollectionViewSource.GetDefaultView(Packages);
_packagesView.Filter = OnPackagesFilter;
_loaded = true;
}
catch (Exception ex)
{
LogManager.Log(ex, "Error retrieving machine updates.");
NotificationProvider.PushErrorReportingSnackbar(ex, "PPC Module Error", "Error occurred while trying to retrieve the machine software updates history.");
}
finally
{
IsFree = true;
}
}
}
private bool OnPackagesFilter(object obj)
{
PackageInstallation package = obj as PackageInstallation;
return String.IsNullOrWhiteSpace(Filter) || package.PackageName.ToLower().Contains(Filter.ToLower());
}
private bool OnUpdatesFilter(object obj)
{
TangoUpdate update = obj as TangoUpdate;
return String.IsNullOrWhiteSpace(Filter) || update.UpdateStatus.ToDescription().ToLower().Contains(Filter.ToLower());
}
#endregion
}
}
|