2using System.Collections.Generic;
4using System.Threading.Tasks;
6using System.Windows.Controls;
7using System.Windows.Media;
8using System.Windows.Media.Imaging;
22 : base(
Parent, JID, Name, Node, Features)
26 public static async Task<LegalService> Create(
TreeNode Parent,
string JID,
string Name,
string Node, Dictionary<string, bool> Features)
30 Result.contractsClient =
new ContractsClient(Result.Account.Client, JID);
33 await Result.contractsClient.
LoadKeys(
true);
36 Result.contractsClient.IdentityUpdated += Result.ContractsClient_IdentityUpdated;
45 this.contractsClient?.
Dispose();
46 this.contractsClient =
null;
53 public override string ToolTip
57 return "Legal Services";
63 base.AddContexMenuItems(ref CurrentGroup, Menu);
67 this.GroupSeparator(ref CurrentGroup,
"Database", Menu);
69 Menu.Items.Add(Item =
new MenuItem()
71 Header =
"_Register Legal Identity...",
75 Source =
new BitmapImage(
new Uri(
"../Graphics/Places-user-identity-icon_16.png", UriKind.Relative)),
81 Item.Click += this.RegisterLegalIdentity_Click;
83 Menu.Items.Add(Item =
new MenuItem()
85 Header =
"M_y legal identities...",
89 Item.Click += this.MyLegalIdentities_Click;
91 Menu.Items.Add(Item =
new MenuItem()
93 Header =
"_Obsolete legal identities...",
97 Item.Click += this.ObsoleteLegalIdentities_Click;
99 Menu.Items.Add(Item =
new MenuItem()
101 Header =
"Report legal identities as _compromized...",
105 Item.Click += this.CompromizedLegalIdentities_Click;
108 private async
void RegisterLegalIdentity_Click(
object Sender, RoutedEventArgs e)
114 Owner = MainWindow.currentInstance
116 bool? Result = Form.ShowDialog();
119 if (Result.HasValue && Result.Value)
121 List<Property> Properties =
new List<Property>();
123 if (!
string.IsNullOrEmpty(s = Form.FirstName.Text))
124 Properties.Add(
new Property(
"FIRST", s));
126 if (!
string.IsNullOrEmpty(s = Form.MiddleNames.Text))
127 Properties.Add(
new Property(
"MIDDLE", s));
129 if (!
string.IsNullOrEmpty(s = Form.LastName.Text))
130 Properties.Add(
new Property(
"LAST", s));
132 if (!
string.IsNullOrEmpty(s = Form.PersonalNumber.Text))
133 Properties.Add(
new Property(
"PNR", s));
135 if (!
string.IsNullOrEmpty(s = Form.Address.Text))
136 Properties.Add(
new Property(
"ADDR", s));
138 if (!
string.IsNullOrEmpty(s = Form.Address2.Text))
139 Properties.Add(
new Property(
"ADDR2", s));
141 if (!
string.IsNullOrEmpty(s = Form.PostalCode.Text))
142 Properties.Add(
new Property(
"ZIP", s));
144 if (!
string.IsNullOrEmpty(s = Form.Area.Text))
145 Properties.Add(
new Property(
"AREA", s));
147 if (!
string.IsNullOrEmpty(s = Form.City.Text))
148 Properties.Add(
new Property(
"CITY", s));
150 if (!
string.IsNullOrEmpty(s = Form.Region.Text))
151 Properties.Add(
new Property(
"REGION", s));
153 if (!
string.IsNullOrEmpty(s = Form.Country.Text))
154 Properties.Add(
new Property(
"COUNTRY", s));
157 await this.contractsClient.
Apply(Properties.ToArray(), (sender2, e2) =>
160 MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ?
"Unable to register legal identity." : e2.ErrorText);
162 return Task.CompletedTask;
175 StringBuilder Markdown =
new StringBuilder();
177 Markdown.AppendLine(
"Legal identity updated:");
178 Markdown.AppendLine();
184 Markdown.ToString(),
string.Empty,
true, DateTime.Now);
187 return Task.CompletedTask;
190 internal static void Output(
string JID, StringBuilder Markdown, KeyValuePair<string, object>[] Tags)
192 Markdown.AppendLine(
"| Legal Identity ||");
193 Markdown.AppendLine(
"|:------|:--------|");
194 Markdown.Append(
"| JID | ");
196 Markdown.AppendLine(
" |");
198 foreach (KeyValuePair<string, object> P
in Tags)
204 case "FIRST": s =
"First Name";
break;
205 case "MIDDLE": s =
"Middle Name(s)";
break;
206 case "LAST": s =
"Last Name";
break;
207 case "PNR": s =
"Personal Number";
break;
208 case "ADDR": s =
"Address";
break;
209 case "ADDR2": s =
"Address, row 2";
break;
210 case "ZIP": s =
"Postal Code (ZIP)";
break;
211 case "AREA": s =
"Area";
break;
212 case "CITY": s =
"City";
break;
213 case "REGION": s =
"Region (State)";
break;
214 case "COUNTRY": s =
"Country";
break;
217 Markdown.Append(
"| ");
218 Markdown.Append(
MarkdownDocument.
Encode(s).Replace(
"\r\n",
"\n").Replace(
"\n",
"<br/>").Replace(
"\r",
"<br/>"));
219 Markdown.Append(
" | ");
220 Markdown.Append(
MarkdownDocument.
Encode(P.Value.ToString()).Replace(
"\r\n",
"\n").Replace(
"\n",
"<br/>").Replace(
"\r",
"<br/>"));
221 Markdown.AppendLine(
" |");
225 private void MyLegalIdentities_Click(
object Sender, RoutedEventArgs e)
231 if (e2.Identities is null || e2.Identities.Length == 0)
232 MainWindow.MessageBox(
"No legal identities are regitered.",
"Identities", MessageBoxButton.OK, MessageBoxImage.Information);
235 foreach (LegalIdentity Identity in e2.Identities)
237 StringBuilder Markdown = new StringBuilder();
239 Output(XmppClient.GetBareJID(e2.To), Markdown, Identity.GetTags());
241 MainWindow.UpdateGui(() =>
243 return MainWindow.currentInstance.ChatMessage(XmppClient.GetBareJID(e2.From), XmppClient.GetBareJID(e2.To),
244 Markdown.ToString(), string.Empty, true, DateTime.Now);
250 MainWindow.ErrorBox(
string.IsNullOrEmpty(e2.ErrorText) ?
"Unable to get list of identities." : e2.ErrorText);
252 return Task.CompletedTask;
257 private void ObsoleteLegalIdentities_Click(
object Sender, RoutedEventArgs e)
259 if (MessageBox.Show(
MainWindow.currentInstance,
"Are you sure you want to obsolete registered legal identities?",
260 "Confirmation", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes) != MessageBoxResult.Yes)
269 if (e2.Identities is null || e2.Identities.Length == 0)
270 MainWindow.MessageBox(
"No legal identities are regitered.",
"Identities", MessageBoxButton.OK, MessageBoxImage.Information);
275 foreach (LegalIdentity Identity in e2.Identities)
277 if (Identity.State == IdentityState.Approved || Identity.State == IdentityState.Created)
279 this.contractsClient.ObsoleteLegalIdentity(Identity.Id, null, null);
285 MainWindow.MessageBox(
"No legal identities found to obsolete.",
"Identities", MessageBoxButton.OK, MessageBoxImage.Information);
289 MainWindow.ErrorBox(
string.IsNullOrEmpty(e2.ErrorText) ?
"Unable to get list of identities." : e2.ErrorText);
291 return Task.CompletedTask;
296 private void CompromizedLegalIdentities_Click(
object Sender, RoutedEventArgs e)
298 if (MessageBox.Show(
MainWindow.currentInstance,
"Are you sure you want to report your registered legal identities as compromized?",
299 "Confirmation", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes) != MessageBoxResult.Yes)
308 if (e2.Identities is null || e2.Identities.Length == 0)
309 MainWindow.MessageBox(
"No legal identities are regitered.",
"Identities", MessageBoxButton.OK, MessageBoxImage.Information);
314 foreach (LegalIdentity Identity in e2.Identities)
316 if (Identity.State == IdentityState.Approved ||
317 Identity.State == IdentityState.Created ||
318 Identity.State == IdentityState.Obsoleted)
320 this.contractsClient.CompromisedLegalIdentity(Identity.Id, null, null);
326 MainWindow.MessageBox(
"No legal identities found to report as compromized.",
"Identities", MessageBoxButton.OK, MessageBoxImage.Information);
330 MainWindow.ErrorBox(
string.IsNullOrEmpty(e2.ErrorText) ?
"Unable to get list of identities." : e2.ErrorText);
332 return Task.CompletedTask;
Interaction logic for xaml
override void AddContexMenuItems(ref string CurrentGroup, ContextMenu Menu)
Adds context sensitive menu items to a context menu.
override void Dispose()
Disposes of the node and its resources.
Abstract base class for tree nodes in the connection view.
TreeNode Parent
Parent node. May be null if a root node.
Class representing a normal XMPP account.
Contains a markdown document. This markdown document class supports original markdown,...
static string Encode(string s)
Encodes all special characters in a string so that it can be included in a markdown document without ...
Adds support for legal identities, smart contracts and signatures to an XMPP client.
async Task GenerateNewKeys()
Generates new keys for the contracts clients.
Task< bool > LoadKeys(bool CreateIfNone)
Loads keys from the underlying persistence layer.
override void Dispose()
Disposes of the extension.
Task EnableE2eEncryption(bool UseLocalKeys)
Defines if End-to-End encryption should use the keys used by the contracts client to perform signatur...
Task GetLegalIdentities(EventHandlerAsync< LegalIdentitiesEventArgs > Callback, object State)
Gets legal identities registered with the account.
Task Apply(Property[] Properties, EventHandlerAsync< LegalIdentityEventArgs > Callback, object State)
Applies for a legal identity to be registered.
void SetKeySettingsInstance(string InstanceName, bool Locked)
Sets the key settings instance name.
Event arguments for legal identity responses
LegalIdentity Identity
Legal Identity
KeyValuePair< string, object >[] GetTags()
Gets tags describing the legal identity.
string From
From address attribute
string To
To address attribute
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
static string GetBareJID(string JID)
Gets the Bare JID from a JID, which may be a Full JID.