/
LicenseViewModel.cs
69 lines (52 loc) · 2.1 KB
/
LicenseViewModel.cs
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
namespace ServiceControl.Config.UI.License
{
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Caliburn.Micro;
using Commands;
using Events;
using Framework.Rx;
using Microsoft.WindowsAPICodePack.Dialogs;
using ServiceControl.LicenseManagement;
class LicenseViewModel : RxScreen
{
public LicenseViewModel(IEventAggregator eventAggregator) => EventAggregator = eventAggregator;
public string ApplyLicenseError { get; set; }
public string ApplyLicenseSuccess { get; set; }
public List<LicenseComponent> Components { get; set; }
public ICommand OpenUrl => new OpenURLCommand();
public ICommand BrowseForFile => new AwaitableSelectPathCommand(OpenLicenseFile, "Select License File", filters: new[] { new CommonFileDialogFilter("License File", "xml") });
public bool CanExtendTrial { get; set; }
public string ExtendLicenseUrl { get; set; }
protected override Task OnActivate()
{
RefreshLicenseInfo();
return Task.CompletedTask;
}
void RefreshLicenseInfo()
{
license = LicenseManager.FindLicense();
Components = LicenseComponentFactory.CreateComponents(license.Details).ToList();
CanExtendTrial = license.Details.IsTrialLicense;
ExtendLicenseUrl = $"https://particular.net/license/nservicebus?t={(license.IsEvaluationLicense ? 0 : 1)}&p=servicecontrol";
}
async Task OpenLicenseFile(string path)
{
if (LicenseManager.TryImportLicense(path, out var importError))
{
ApplyLicenseError = null;
RefreshLicenseInfo();
ApplyLicenseSuccess = "License imported successfully";
await EventAggregator.PublishOnUIThreadAsync(new LicenseUpdated());
}
else
{
ApplyLicenseSuccess = null;
ApplyLicenseError = importError;
}
}
DetectedLicense license;
}
}