-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathInventoryLocalIdentificationViewModel.cs
More file actions
184 lines (148 loc) · 6.94 KB
/
InventoryLocalIdentificationViewModel.cs
File metadata and controls
184 lines (148 loc) · 6.94 KB
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
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia.Media;
using ByteSync.Assets.Resources;
using ByteSync.Business.Inventories;
using ByteSync.Interfaces.Controls.Inventories;
using ByteSync.Interfaces.Controls.Themes;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
namespace ByteSync.ViewModels.Sessions.Inventories;
public class InventoryLocalIdentificationViewModel : ActivatableViewModelBase
{
private readonly IInventoryService _inventoryService = null!;
private readonly IThemeService _themeService = null!;
public InventoryLocalIdentificationViewModel()
{
}
public InventoryLocalIdentificationViewModel(IInventoryService inventoryService)
{
_inventoryService = inventoryService;
this.WhenActivated(HandleActivation);
}
public InventoryLocalIdentificationViewModel(IInventoryService inventoryService, IThemeService themeService)
: this(inventoryService)
{
_themeService = themeService;
IdentificationIconBrush = _themeService.GetBrush("HomeCloudSynchronizationBackGround");
}
private void HandleActivation(CompositeDisposable disposables)
{
_inventoryService.InventoryProcessData.IdentificationStatus
.ToPropertyEx(this, x => x.IdentificationStatus)
.DisposeWith(disposables);
_inventoryService.InventoryProcessData.IdentificationStatus
.Select(ms => ms == InventoryTaskStatus.Running)
.ToPropertyEx(this, x => x.IsIdentificationRunning)
.DisposeWith(disposables);
_inventoryService.InventoryProcessData.InventoryMonitorObservable
.Sample(TimeSpan.FromMilliseconds(500))
.Subscribe(m =>
{
IdentifiedFiles = m.IdentifiedFiles;
IdentifiedDirectories = m.IdentifiedDirectories;
IdentifiedVolume = m.IdentifiedVolume;
IdentificationErrors = m.IdentificationErrors;
SkippedEntriesCount = m.SkippedEntriesCount;
})
.DisposeWith(disposables);
this.WhenAnyValue(x => x.IdentificationErrors)
.Select(v => v > 0)
.ToPropertyEx(this, x => x.HasIdentificationErrors)
.DisposeWith(disposables);
this.WhenAnyValue(x => x.SkippedEntriesCount)
.Select(v => v > 0)
.ToPropertyEx(this, x => x.ShowSkippedEntriesCount)
.DisposeWith(disposables);
_inventoryService.InventoryProcessData.IdentificationStatus
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(status =>
{
switch (status)
{
case InventoryTaskStatus.Error:
case InventoryTaskStatus.Cancelled:
case InventoryTaskStatus.NotLaunched:
IdentificationIcon = "SolidXCircle";
SetIdentificationBrush(status);
break;
case InventoryTaskStatus.Success:
IdentificationIcon = "SolidCheckCircle";
SetIdentificationBrush(status);
break;
case InventoryTaskStatus.Pending:
IdentificationIcon = "RegularPauseCircle";
SetIdentificationBrush(status);
break;
case InventoryTaskStatus.Running:
IdentificationIcon = "None";
SetIdentificationBrush(status);
break;
default:
IdentificationIcon = "None";
SetIdentificationBrush(status);
break;
}
string key = status switch
{
InventoryTaskStatus.Success => "InventoryProcess_IdentificationSuccess",
InventoryTaskStatus.Cancelled => "InventoryProcess_IdentificationCancelled",
InventoryTaskStatus.Error => "InventoryProcess_IdentificationError",
InventoryTaskStatus.Pending => "InventoryProcess_IdentificationRunning",
InventoryTaskStatus.Running => "InventoryProcess_IdentificationRunning",
InventoryTaskStatus.NotLaunched => "InventoryProcess_IdentificationCancelled",
_ => string.Empty
};
IdentificationStatusText = string.IsNullOrEmpty(key)
? string.Empty
: Resources.ResourceManager.GetString(key, Resources.Culture) ?? string.Empty;
})
.DisposeWith(disposables);
_themeService.SelectedTheme
.Skip(1)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(_ => { SetIdentificationBrush(IdentificationStatus); })
.DisposeWith(disposables);
}
public extern InventoryTaskStatus IdentificationStatus { [ObservableAsProperty] get; }
public extern bool IsIdentificationRunning { [ObservableAsProperty] get; }
[Reactive]
public int IdentifiedFiles { get; set; }
[Reactive]
public int IdentifiedDirectories { get; set; }
[Reactive]
public long IdentifiedVolume { get; set; }
[Reactive]
public int IdentificationErrors { get; set; }
public extern bool HasIdentificationErrors { [ObservableAsProperty] get; }
[Reactive]
public int SkippedEntriesCount { get; set; }
public extern bool ShowSkippedEntriesCount { [ObservableAsProperty] get; }
[Reactive]
public string IdentificationIcon { get; set; } = "None";
[Reactive]
public string IdentificationStatusText { get; set; } = string.Empty;
[Reactive]
public IBrush? IdentificationIconBrush { get; set; }
private void SetIdentificationBrush(InventoryTaskStatus status)
{
switch (status)
{
case InventoryTaskStatus.Error:
case InventoryTaskStatus.Cancelled:
case InventoryTaskStatus.NotLaunched:
IdentificationIconBrush = _theme_service_get_secondary();
break;
case InventoryTaskStatus.Success:
IdentificationIconBrush = _theme_service_get_background();
break;
case InventoryTaskStatus.Pending:
case InventoryTaskStatus.Running:
default:
IdentificationIconBrush = _theme_service_get_background();
break;
}
}
private IBrush _theme_service_get_background() => _themeService.GetBrush("HomeCloudSynchronizationBackGround");
private IBrush _theme_service_get_secondary() => _themeService.GetBrush("MainSecondaryColor");
}