Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmppStateExtensions.cs
5
7{
11 public static class XmppStateExtensions
12 {
18 public static Color ToColor(this XmppState State)
19 {
20 return State switch
21 {
22 XmppState.Error or
23 XmppState.Offline => Colors.Red,
24
25 XmppState.Authenticating or
26 XmppState.Connecting or
27 XmppState.Registering or
28 XmppState.StartingEncryption or
29 XmppState.StreamNegotiation or
30 XmppState.StreamOpened => Colors.Yellow,
31
32 XmppState.Binding or
33 XmppState.FetchingRoster or
34 XmppState.RequestingSession or
35 XmppState.SettingPresence => Blend(Colors.Yellow, connectedColor, 0.5),
36
37 XmppState.Connected => connectedColor,
38
39 _ => Colors.Gray,
40 };
41 }
42
43 private static readonly Color connectedColor = Color.FromRgb(146, 208, 80);
44
52 public static Color Blend(Color Color1, Color Color2, double p)
53 {
54 int R = (int)(Color1.Red * (1 - p) + Color2.Red * p + 0.5);
55 int G = (int)(Color1.Green * (1 - p) + Color2.Green * p + 0.5);
56 int B = (int)(Color1.Blue * (1 - p) + Color2.Blue * p + 0.5);
57 int A = (int)(Color1.Alpha * (1 - p) + Color2.Alpha * p + 0.5);
58
59 return new Color(R, G, B, A);
60 }
61
67 public static string ToDisplayText(this XmppState State)
68 {
69 return State switch
70 {
71 XmppState.Authenticating => ServiceRef.Localizer[nameof(AppResources.XmppState_Authenticating)],
72 XmppState.Binding => ServiceRef.Localizer[nameof(AppResources.XmppState_Binding)],
73 XmppState.Connected => ServiceRef.Localizer[nameof(AppResources.XmppState_Connected)],
74 XmppState.Connecting => ServiceRef.Localizer[nameof(AppResources.XmppState_Connecting)],
75 XmppState.Error => ServiceRef.Localizer[nameof(AppResources.XmppState_Error)],
76 XmppState.FetchingRoster => ServiceRef.Localizer[nameof(AppResources.XmppState_FetchingRoster)],
77 XmppState.Registering => ServiceRef.Localizer[nameof(AppResources.XmppState_Registering)],
78 XmppState.RequestingSession => ServiceRef.Localizer[nameof(AppResources.XmppState_RequestingSession)],
79 XmppState.SettingPresence => ServiceRef.Localizer[nameof(AppResources.XmppState_SettingPresence)],
80 XmppState.StartingEncryption => ServiceRef.Localizer[nameof(AppResources.XmppState_StartingEncryption)],
81 XmppState.StreamNegotiation => ServiceRef.Localizer[nameof(AppResources.XmppState_StreamNegotiation)],
82 XmppState.StreamOpened => ServiceRef.Localizer[nameof(AppResources.XmppState_StreamOpened)],
83 _ => ServiceRef.Localizer[nameof(AppResources.XmppState_Offline)],
84 };
85 }
86
92 public static string ToDisplayText(this IdentityState State)
93 {
94 return State switch
95 {
96 IdentityState.Approved => ServiceRef.Localizer[nameof(AppResources.IdentityState_Approved)],
97 IdentityState.Compromised => ServiceRef.Localizer[nameof(AppResources.IdentityState_Compromised)],
98 IdentityState.Created => ServiceRef.Localizer[nameof(AppResources.IdentityState_Created)],
99 IdentityState.Obsoleted => ServiceRef.Localizer[nameof(AppResources.IdentityState_Obsoleted)],
100 IdentityState.Rejected => ServiceRef.Localizer[nameof(AppResources.IdentityState_Rejected)],
101 _ => string.Empty,
102 };
103 }
104 }
105}
static Color ToColor(this XmppState State)
Returns a color matching the current connection state.
static string ToDisplayText(this XmppState State)
Converts the state to a localized string.
static Color Blend(Color Color1, Color Color2, double p)
Blends two colors.
static string ToDisplayText(this IdentityState State)
Converts the state to a localized string.
Base class that references services in the app.
Definition: ServiceRef.cs:31
static IStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:235
IdentityState
Lists recognized legal identity states.
XmppState
State of XMPP connection.
Definition: XmppState.cs:7