blob: f0bcc521b1192b80ca19b82ba9bc36a5a21cd1ee (
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
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
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.Firmware.Dialogs;
using static Tango.SharedUI.Controls.NavigationControl;
namespace Tango.FSE.Firmware.ViewModels
{
public class UpdatesViewVM : FSEViewModel, INavigationViewModel
{
private bool _loaded;
private ICollectionView _updatesView;
#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 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();
LoadFirmwareUpdates();
}
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(() =>
{
LoadFirmwareUpdates();
});
}
}
}
#endregion
#region Private Methods
private void RefreshUpdates()
{
_loaded = false;
LoadFirmwareUpdates();
}
private async void OpenUpdate(TangoUpdate update)
{
await NotificationProvider.ShowDialog(new FirmwareUpdateViewVM() { Update = update });
}
private void OnFilterChanged()
{
_updatesView?.Refresh();
}
private async void LoadFirmwareUpdates()
{
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 || x.IsUpdate || x.IsOfflineUpdate || x.IsSetup).ToList();
_filter = null;
RaisePropertyChanged(nameof(Filter));
_updatesView = CollectionViewSource.GetDefaultView(Updates);
_updatesView.Filter = OnUpdatesFilter;
_loaded = true;
}
catch (Exception ex)
{
LogManager.Log(ex, "Error retrieving machine firmware updates.");
NotificationProvider.PushErrorReportingSnackbar(ex, "Firmware Module Error", "Error occurred while trying to retrieve the machine firmware updates history.");
}
finally
{
IsFree = true;
}
}
}
private bool OnUpdatesFilter(object obj)
{
TangoUpdate update = obj as TangoUpdate;
return String.IsNullOrWhiteSpace(Filter) || update.UpdateStatus.ToDescription().ToLower().Contains(Filter.ToLower());
}
#endregion
}
}
|