Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FinalizeViewModel.cs
1using System.ComponentModel;
2using CommunityToolkit.Mvvm.ComponentModel;
3using CommunityToolkit.Mvvm.Input;
9using Waher.Content;
10
12{
13 public partial class FinalizeViewModel : BaseRegistrationViewModel
14 {
15 public FinalizeViewModel()
16 : base(RegistrationStep.Finalize)
17 {
18 }
19
20 protected override async Task OnInitialize()
21 {
22 await base.OnInitialize();
23
24 LocalizationManager.Current.PropertyChanged += this.Localization_Changed;
25 }
26
28 protected override async Task OnDispose()
29 {
30 LocalizationManager.Current.PropertyChanged -= this.Localization_Changed;
31
32 await base.OnDispose();
33 }
34
35
36 public override async Task DoAssignProperties()
37 {
38 await base.DoAssignProperties();
39 await this.SetDomainName();
40 this.NetworkID = $"{ServiceRef.TagProfile.Account}@{ServiceRef.TagProfile.Domain}";
41 }
42
43 private async void Localization_Changed(object? Sender, PropertyChangedEventArgs e)
44 {
45 await this.SetDomainName();
46 }
47
48 private async Task SetDomainName()
49 {
50 this.DomainName = ServiceRef.TagProfile.Domain!;
51
52 try
53 {
54 Uri DomainInfo = new("https://" + this.DomainName + "/Agent/Account/DomainInfo");
55 string AcceptLanguage = App.SelectedLanguage.TwoLetterISOLanguageName;
56
57 if (AcceptLanguage != "en")
58 AcceptLanguage += ";q=1,en;q=0.9";
59
60 object Result = await InternetContent.GetAsync(DomainInfo,
61 new KeyValuePair<string, string>("Accept", "application/json"),
62 new KeyValuePair<string, string>("Accept-Language", AcceptLanguage),
63 new KeyValuePair<string, string>("Accept-Encoding", "0"));
64 if (Result is Dictionary<string, object> Response)
65 {
66 if (Response.TryGetValue("humanReadableName", out object? Obj) && Obj is string LocalizedName)
67 this.LocalizedDomainName = LocalizedName;
68
69 if (Response.TryGetValue("humanReadableDescription", out Obj) && Obj is string LocalizedDescription)
70 this.LocalizedDomainDescription = LocalizedDescription;
71 }
72 }
73 catch (Exception ex)
74 {
75 ServiceRef.LogService.LogException(ex);
76 }
77 }
78
79
83 public double CheckmarkBackgroundSize => 120.0;
84
88 public double CheckmarkBackgroundCornerRadius => this.CheckmarkBackgroundSize / 2;
92 public double CheckmarkIconSize => 60.0;
93
97 [ObservableProperty]
98 private string? networkID;
99
100 [RelayCommand]
101 private void Continue()
102 {
103 GoToRegistrationStep(RegistrationStep.Complete);
104 }
105
109 [RelayCommand]
110 private async Task Copy(object Item)
111 {
112 try
113 {
114 this.SetIsBusy(true);
115
116 if (Item is string Label)
117 {
118 await Clipboard.SetTextAsync(Label);
119 await ServiceRef.UiService.DisplayAlert(
120 ServiceRef.Localizer[nameof(AppResources.SuccessTitle)],
121 ServiceRef.Localizer[nameof(AppResources.TagValueCopiedToClipboard)]);
122 }
123 }
124 catch (Exception ex)
125 {
126 ServiceRef.LogService.LogException(ex);
127 await ServiceRef.UiService.DisplayException(ex);
128 }
129 finally
130 {
131 this.SetIsBusy(false);
132 }
133 }
134
135
136 [ObservableProperty]
137 private string domainName = string.Empty;
138
139 [ObservableProperty]
140 private string localizedDomainName = string.Empty;
141
142 [ObservableProperty]
143 private string localizedDomainDescription = string.Empty;
144
145 [RelayCommand]
146 private async Task ServiceProviderInfo()
147 {
148 string title = this.LocalizedDomainName;
149 string message = this.LocalizedDomainDescription;
150 ShowInfoPopup infoPage = new(title, message);
151 await ServiceRef.UiService.PushAsync(infoPage);
152 }
153 }
154}
The Application class, representing an instance of the Neuro-Access app.
Definition: App.xaml.cs:69
static LanguageInfo SelectedLanguage
Selected language.
Definition: App.xaml.cs:196
Base class that references services in the app.
Definition: ServiceRef.cs:31
static ILogService LogService
Log service.
Definition: ServiceRef.cs:91
static IUiService UiService
Service serializing and managing UI-related tasks.
Definition: ServiceRef.cs:55
static ITagProfile TagProfile
TAG Profile service.
Definition: ServiceRef.cs:79
static IStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:235
double CheckmarkIconSize
Gets the size of the icon for the checkmark.
double CheckmarkBackgroundSize
Gets the size of the background for the checkmark.
double CheckmarkBackgroundCornerRadius
Gets the size of the background for the checkmark.
Static class managing encoding and decoding of internet content.
static Task< object > GetAsync(Uri Uri, params KeyValuePair< string, string >[] Headers)
Gets a resource, given its URI.
string? Domain
The domain this profile is connected to.
Definition: ITagProfile.cs:51
RegistrationStep
The different steps of a TAG Profile registration journey.