Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NeuroFeaturesClient.cs
3using System;
4using System.Collections.Generic;
5using System.Text;
6using System.Threading.Tasks;
7using System.Xml;
8using Waher.Content;
10using Waher.Events;
16using Waher.Script;
17
18namespace NeuroFeatures
19{
24 {
28 public const string NamespaceNeuroFeatures = "https://paiwise.tagroot.io/Schema/NeuroFeatures.xsd";
29
33 public const string NamespaceStateMachine = "https://paiwise.tagroot.io/Schema/StateMachines.xsd";
34
38 public const string DefinitionStateMachine = "StateMachine";
39
40 private readonly ContractsClient contractsClient;
41 private readonly string componentAddress;
42
43 #region Setup
44
52 : base(Client)
53 {
54 this.componentAddress = ComponentAddress;
55 this.contractsClient = ContractsClient;
56
57 Client.RegisterMessageHandler("tokenAdded", NamespaceNeuroFeatures, this.TokenAddedHandler, true);
58 Client.RegisterMessageHandler("tokenRemoved", NamespaceNeuroFeatures, this.TokenRemovedHandler, false);
59
60 Client.RegisterMessageHandler("stateUpdated", NamespaceStateMachine, this.StateUpdatedHandler, true);
61 Client.RegisterMessageHandler("variablesUpdated", NamespaceStateMachine, this.VariablesUpdatedHandler, false);
62 }
63
67 public ContractsClient ContractsClient => this.contractsClient;
68
72 public override void Dispose()
73 {
74 this.Client.UnregisterMessageHandler("tokenAdded", NamespaceNeuroFeatures, this.TokenAddedHandler, true);
75 this.Client.UnregisterMessageHandler("tokenRemoved", NamespaceNeuroFeatures, this.TokenRemovedHandler, false);
76
77 this.Client.UnregisterMessageHandler("stateUpdated", NamespaceStateMachine, this.StateUpdatedHandler, true);
78 this.Client.UnregisterMessageHandler("variablesUpdated", NamespaceStateMachine, this.VariablesUpdatedHandler, false);
79
80 base.Dispose();
81 }
82
86 public string ComponentAddress => this.componentAddress;
87
91 public override string[] Extensions => new string[] { };
92
93 #endregion
94
95 #region Tokens
96
97 #region GetToken
98
105 public Task GetToken(string TokenId, EventHandlerAsync<TokenResultEventArgs> Callback, object State)
106 {
107 string Domain = this.GetDomain(TokenId);
108 StringBuilder Xml = new StringBuilder();
109
110 Xml.Append("<token id='");
111 Xml.Append(XML.Encode(TokenId));
112 Xml.Append("' xmlns='");
113 Xml.Append(NamespaceNeuroFeatures);
114 Xml.Append("'/>");
115
116 return this.client.SendIqGet(Domain, Xml.ToString(), async (Sender, e) =>
117 {
118 Token ResultToken = null;
119
120 if (e.Ok)
121 {
122 if (e.FirstElement is null || e.FirstElement.LocalName != "token" || e.FirstElement.NamespaceURI != NamespaceNeuroFeatures)
123 {
124 e.Ok = false;
125 await this.client.Error("Unexpected response.");
126 }
127 else if (!Token.TryParse(e.FirstElement, out ResultToken))
128 {
129 e.Ok = false;
130 await this.client.Error("Unable to parse token.");
131 }
132 }
133
134 TokenResultEventArgs e2 = new TokenResultEventArgs(e, ResultToken);
135 await Callback.Raise(this, e2);
136 }, State);
137 }
138
139 private string GetDomain(string TokenId)
140 {
141 int i = TokenId.IndexOf('@');
142
143 if (i < 0)
144 return this.componentAddress;
145 else
146 return TokenId.Substring(i + 1);
147 }
148
153 public async Task<Token> GetTokenAsync(string TokenId)
154 {
155 TaskCompletionSource<Token> Result = new TaskCompletionSource<Token>();
156
157 await this.GetToken(TokenId, (Sender, e) =>
158 {
159 if (e.Ok)
160 Result.TrySetResult(e.Token);
161 else
162 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get token."));
163
164 return Task.CompletedTask;
165 }, null);
166
167 return await Result.Task;
168 }
169
170 #endregion
171
172 #region Get Token References
173
179 public Task GetTokenReferences(EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
180 {
181 return this.GetTokenReferences(this.componentAddress, 0, int.MaxValue, Callback, State);
182 }
183
190 public Task GetTokenReferences(string Address, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
191 {
192 return this.GetTokenReferences(Address, 0, int.MaxValue, Callback, State);
193 }
194
202 public Task GetTokenReferences(int Offset, int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
203 {
204 return this.GetTokenReferences(this.componentAddress, Offset, MaxCount, Callback, State);
205 }
206
215 public Task GetTokenReferences(string Address, int Offset, int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
216 {
217 if (Offset < 0)
218 throw new ArgumentException("Offsets cannot be negative.", nameof(Offset));
219
220 if (MaxCount <= 0)
221 throw new ArgumentException("Must be postitive.", nameof(MaxCount));
222
223 StringBuilder Xml = new StringBuilder();
224
225 Xml.Append("<tokens references='true' xmlns='");
226 Xml.Append(NamespaceNeuroFeatures);
227
228 if (Offset > 0)
229 {
230 Xml.Append("' offset='");
231 Xml.Append(Offset.ToString());
232 }
233
234 if (MaxCount < int.MaxValue)
235 {
236 Xml.Append("' maxCount='");
237 Xml.Append(MaxCount.ToString());
238 }
239
240 Xml.Append("'/>");
241
242 return this.client.SendIqGet(Address, Xml.ToString(), this.TokenReferencesResponse, new object[] { Callback, State });
243 }
244
245 private async Task TokenReferencesResponse(object Sender, IqResultEventArgs e)
246 {
247 object[] P = (object[])e.State;
248 EventHandlerAsync<IdReferencesEventArgs> Callback = (EventHandlerAsync<IdReferencesEventArgs>)P[0];
249 XmlElement E = e.FirstElement;
250 List<string> IDs = new List<string>();
251
252 if (e.Ok && !(E is null))
253 {
254 foreach (XmlNode N in E.ChildNodes)
255 {
256 if (N is XmlElement E2 && E2.LocalName == "ref" && E2.NamespaceURI == NamespaceNeuroFeatures)
257 {
258 string Id = XML.Attribute(E2, "id");
259 IDs.Add(Id);
260 }
261 }
262 }
263 else
264 e.Ok = false;
265
266 e.State = P[1];
267 await Callback.Raise(this, new IdReferencesEventArgs(e, IDs.ToArray()));
268 }
269
274 public Task<string[]> GetTokenReferencesAsync()
275 {
276 return this.GetTokenReferencesAsync(this.componentAddress, 0, int.MaxValue);
277 }
278
284 public Task<string[]> GetTokenReferencesAsync(string Address)
285 {
286 return this.GetTokenReferencesAsync(Address, 0, int.MaxValue);
287 }
288
295 public Task<string[]> GetTokenReferencesAsync(int Offset, int MaxCount)
296 {
297 return this.GetTokenReferencesAsync(this.componentAddress, Offset, MaxCount);
298 }
299
307 public async Task<string[]> GetTokenReferencesAsync(string Address, int Offset, int MaxCount)
308 {
309 TaskCompletionSource<string[]> Result = new TaskCompletionSource<string[]>();
310
311 await this.GetTokenReferences(Address, Offset, MaxCount, (Sender, e) =>
312 {
313 if (e.Ok)
314 Result.TrySetResult(e.References);
315 else
316 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get token references."));
317
318 return Task.CompletedTask;
319
320 }, null);
321
322 return await Result.Task;
323 }
324
325
326
327 #endregion
328 #region Get Tokens
334 public Task GetTokens(EventHandlerAsync<TokensEventArgs> Callback, object State)
335 {
336 return this.GetTokens(this.componentAddress, 0, int.MaxValue, Callback, State);
337 }
338
345 public Task GetTokens(string Address, EventHandlerAsync<TokensEventArgs> Callback, object State)
346 {
347 return this.GetTokens(Address, 0, int.MaxValue, Callback, State);
348 }
349
357 public Task GetTokens(int Offset, int MaxCount, EventHandlerAsync<TokensEventArgs> Callback, object State)
358 {
359 return this.GetTokens(this.componentAddress, Offset, MaxCount, Callback, State);
360 }
361
370 public Task GetTokens(string Address, int Offset, int MaxCount, EventHandlerAsync<TokensEventArgs> Callback, object State)
371 {
372 if (Offset < 0)
373 throw new ArgumentException("Offsets cannot be negative.", nameof(Offset));
374
375 if (MaxCount <= 0)
376 throw new ArgumentException("Must be postitive.", nameof(MaxCount));
377
378 StringBuilder Xml = new StringBuilder();
379
380 Xml.Append("<tokens references='false' xmlns='");
381 Xml.Append(NamespaceNeuroFeatures);
382
383 if (Offset > 0)
384 {
385 Xml.Append("' offset='");
386 Xml.Append(Offset.ToString());
387 }
388
389 if (MaxCount < int.MaxValue)
390 {
391 Xml.Append("' maxCount='");
392 Xml.Append(MaxCount.ToString());
393 }
394
395 Xml.Append("'/>");
396
397 return this.client.SendIqGet(Address, Xml.ToString(), this.TokensResponse, new object[] { Callback, State });
398 }
399
400 private async Task TokensResponse(object Sender, IqResultEventArgs e)
401 {
402 object[] P = (object[])e.State;
403 EventHandlerAsync<TokensEventArgs> Callback = (EventHandlerAsync<TokensEventArgs>)P[0];
404 XmlElement E = e.FirstElement;
405 List<Token> Tokens = new List<Token>();
406 List<string> References = new List<string>();
407
408 if (e.Ok && !(E is null))
409 {
410 foreach (XmlNode N in E.ChildNodes)
411 {
412 if (N is XmlElement E2 && E2.NamespaceURI == NamespaceNeuroFeatures)
413 {
414 switch (E2.LocalName)
415 {
416 case "token":
417 if (Token.TryParse(E2, out Token ParsedToken))
418 Tokens.Add(ParsedToken);
419 break;
420
421 case "ref":
422 string TokenId = XML.Attribute(E2, "id");
423 References.Add(TokenId);
424 break;
425 }
426 }
427 }
428 }
429 else
430 e.Ok = false;
431
432 e.State = P[1];
433 await Callback.Raise(this, new TokensEventArgs(e, Tokens.ToArray(), References.ToArray()));
434 }
435
440 public Task<TokensEventArgs> GetTokensAsync()
441 {
442 return this.GetTokensAsync(this.componentAddress, 0, int.MaxValue);
443 }
444
450 public Task<TokensEventArgs> GetTokensAsync(string Address)
451 {
452 return this.GetTokensAsync(Address, 0, int.MaxValue);
453 }
454
461 public Task<TokensEventArgs> GetTokensAsync(int Offset, int MaxCount)
462 {
463 return this.GetTokensAsync(this.componentAddress, Offset, MaxCount);
464 }
465
473 public async Task<TokensEventArgs> GetTokensAsync(string Address, int Offset, int MaxCount)
474 {
475 TaskCompletionSource<TokensEventArgs> Result = new TaskCompletionSource<TokensEventArgs>();
476
477 await this.GetTokens(Address, Offset, MaxCount, (Sender, e) =>
478 {
479 Result.TrySetResult(e);
480 return Task.CompletedTask;
481
482 }, null);
483
484 return await Result.Task;
485 }
486
487 #endregion
488
489 #region Get Contract Token References
490
497 public Task GetContractTokenReferences(string ContractId, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
498 {
499 return this.GetContractTokenReferences(this.contractsClient.GetTrustProvider(ContractId),
500 ContractId, 0, int.MaxValue, Callback, State);
501 }
502
510 public Task GetContractTokenReferences(string Address, string ContractId, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
511 {
512 return this.GetContractTokenReferences(Address, ContractId, 0, int.MaxValue, Callback, State);
513 }
514
523 public Task GetContractTokenReferences(string ContractId, int Offset, int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
524 {
525 return this.GetContractTokenReferences(this.contractsClient.GetTrustProvider(ContractId),
526 ContractId, Offset, MaxCount, Callback, State);
527 }
528
538 public Task GetContractTokenReferences(string Address, string ContractId, int Offset, int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
539 {
540 if (Offset < 0)
541 throw new ArgumentException("Offsets cannot be negative.", nameof(Offset));
542
543 if (MaxCount <= 0)
544 throw new ArgumentException("Must be postitive.", nameof(MaxCount));
545
546 StringBuilder Xml = new StringBuilder();
547
548 Xml.Append("<contractTokens contractId='");
549 Xml.Append(XML.Encode(ContractId));
550 Xml.Append("' references='true' xmlns='");
551 Xml.Append(NamespaceNeuroFeatures);
552
553 if (Offset > 0)
554 {
555 Xml.Append("' offset='");
556 Xml.Append(Offset.ToString());
557 }
558
559 if (MaxCount < int.MaxValue)
560 {
561 Xml.Append("' maxCount='");
562 Xml.Append(MaxCount.ToString());
563 }
564
565 Xml.Append("'/>");
566
567 return this.client.SendIqGet(Address, Xml.ToString(), this.TokenReferencesResponse, new object[] { Callback, State });
568 }
569
575 public Task<string[]> GetContractTokenReferencesAsync(string ContractId)
576 {
577 return this.GetContractTokenReferencesAsync(this.contractsClient.GetTrustProvider(ContractId),
578 ContractId, 0, int.MaxValue);
579 }
580
587 public Task<string[]> GetContractTokenReferencesAsync(string Address, string ContractId)
588 {
589 return this.GetContractTokenReferencesAsync(Address, ContractId, 0, int.MaxValue);
590 }
591
599 public Task<string[]> GetContractTokenReferencesAsync(string ContractId, int Offset, int MaxCount)
600 {
601 return this.GetContractTokenReferencesAsync(this.contractsClient.GetTrustProvider(ContractId),
602 ContractId, Offset, MaxCount);
603 }
604
613 public async Task<string[]> GetContractTokenReferencesAsync(string Address, string ContractId, int Offset, int MaxCount)
614 {
615 TaskCompletionSource<string[]> Result = new TaskCompletionSource<string[]>();
616
617 await this.GetContractTokenReferences(Address, ContractId, Offset, MaxCount, (Sender, e) =>
618 {
619 if (e.Ok)
620 Result.TrySetResult(e.References);
621 else
622 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get token references."));
623
624 return Task.CompletedTask;
625
626 }, null);
627
628 return await Result.Task;
629 }
630
631 #endregion
632
633 #region Get Contract Tokens
634
641 public Task GetContractTokens(string ContractId, EventHandlerAsync<TokensEventArgs> Callback, object State)
642 {
643 return this.GetContractTokens(this.contractsClient.GetTrustProvider(ContractId),
644 ContractId, 0, int.MaxValue, Callback, State);
645 }
646
654 public Task GetContractTokens(string Address, string ContractId, EventHandlerAsync<TokensEventArgs> Callback, object State)
655 {
656 return this.GetContractTokens(Address, ContractId, 0, int.MaxValue, Callback, State);
657 }
658
667 public Task GetContractTokens(string ContractId, int Offset, int MaxCount, EventHandlerAsync<TokensEventArgs> Callback, object State)
668 {
669 return this.GetContractTokens(this.contractsClient.GetTrustProvider(ContractId),
670 ContractId, Offset, MaxCount, Callback, State);
671 }
672
682 public Task GetContractTokens(string Address, string ContractId, int Offset, int MaxCount, EventHandlerAsync<TokensEventArgs> Callback, object State)
683 {
684 if (Offset < 0)
685 throw new ArgumentException("Offsets cannot be negative.", nameof(Offset));
686
687 if (MaxCount <= 0)
688 throw new ArgumentException("Must be postitive.", nameof(MaxCount));
689
690 StringBuilder Xml = new StringBuilder();
691
692 Xml.Append("<contractTokens contractId='");
693 Xml.Append(XML.Encode(ContractId));
694 Xml.Append("' references='false' xmlns='");
695 Xml.Append(NamespaceNeuroFeatures);
696
697 if (Offset > 0)
698 {
699 Xml.Append("' offset='");
700 Xml.Append(Offset.ToString());
701 }
702
703 if (MaxCount < int.MaxValue)
704 {
705 Xml.Append("' maxCount='");
706 Xml.Append(MaxCount.ToString());
707 }
708
709 Xml.Append("'/>");
710
711 return this.client.SendIqGet(Address, Xml.ToString(), this.TokensResponse, new object[] { Callback, State });
712 }
713
719 public Task<TokensEventArgs> GetContractTokensAsync(string ContractId)
720 {
721 return this.GetContractTokensAsync(this.contractsClient.GetTrustProvider(ContractId),
722 ContractId, 0, int.MaxValue);
723 }
724
731 public Task<TokensEventArgs> GetContractTokensAsync(string Address, string ContractId)
732 {
733 return this.GetContractTokensAsync(Address, ContractId, 0, int.MaxValue);
734 }
735
743 public Task<TokensEventArgs> GetContractTokensAsync(string ContractId, int Offset, int MaxCount)
744 {
745 return this.GetContractTokensAsync(this.contractsClient.GetTrustProvider(ContractId),
746 ContractId, Offset, MaxCount);
747 }
748
757 public async Task<TokensEventArgs> GetContractTokensAsync(string Address, string ContractId, int Offset, int MaxCount)
758 {
759 TaskCompletionSource<TokensEventArgs> Result = new TaskCompletionSource<TokensEventArgs>();
760
761 await this.GetContractTokens(Address, ContractId, Offset, MaxCount, (Sender, e) =>
762 {
763 Result.TrySetResult(e);
764 return Task.CompletedTask;
765
766 }, null);
767
768 return await Result.Task;
769 }
770
771 #endregion
772
773 #region TokenAdded
774
775 private async Task TokenAddedHandler(object Sender, MessageEventArgs e)
776 {
777 foreach (XmlNode N in e.Content.ChildNodes)
778 {
779 if (N is XmlElement E &&
780 E.LocalName == "token" &&
781 E.NamespaceURI == NamespaceNeuroFeatures &&
782 Token.TryParse(E, out Token TokenAdded))
783 {
784 await this.TokenAdded.Raise(this, new TokenEventArgs(e, TokenAdded));
785 }
786 }
787 }
788
792 public event EventHandlerAsync<TokenEventArgs> TokenAdded;
793
794 #endregion
795
796 #region TokenRemoved
797
798 private async Task TokenRemovedHandler(object Sender, MessageEventArgs e)
799 {
800 foreach (XmlNode N in e.Content.ChildNodes)
801 {
802 if (N is XmlElement E &&
803 E.LocalName == "token" &&
804 E.NamespaceURI == NamespaceNeuroFeatures &&
805 Token.TryParse(E, out Token TokenRemoved))
806 {
807 await this.TokenRemoved.Raise(this, new TokenEventArgs(e, TokenRemoved));
808 }
809 }
810 }
811
815 public event EventHandlerAsync<TokenEventArgs> TokenRemoved;
816
817 #endregion
818
819 #region Get Total
820
826 public Task GetTotals(EventHandlerAsync<TokenTotalsEventArgs> Callback, object State)
827 {
828 return this.GetTotals(this.componentAddress, Callback, State);
829 }
830
837 public Task GetTotals(string Address, EventHandlerAsync<TokenTotalsEventArgs> Callback, object State)
838 {
839 StringBuilder Xml = new StringBuilder();
840
841 Xml.Append("<totals xmlns='");
842 Xml.Append(NamespaceNeuroFeatures);
843 Xml.Append("'/>");
844
845 return this.client.SendIqGet(Address, Xml.ToString(), this.TotalsResponse, new object[] { Callback, State });
846 }
847
848 private async Task TotalsResponse(object Sender, IqResultEventArgs e)
849 {
850 object[] P = (object[])e.State;
851 EventHandlerAsync<TokenTotalsEventArgs> Callback = (EventHandlerAsync<TokenTotalsEventArgs>)P[0];
852 XmlElement E = e.FirstElement;
853 List<TokenTotal> Totals = new List<TokenTotal>();
854
855 if (e.Ok && !(E is null) && E.LocalName == "totals" && E.NamespaceURI == NamespaceNeuroFeatures)
856 {
857 foreach (XmlNode N in E.ChildNodes)
858 {
859 if (N is XmlElement E2 && E2.NamespaceURI == NamespaceNeuroFeatures && E2.LocalName == "total")
860 {
861 Totals.Add(new TokenTotal()
862 {
863 NrTokens = XML.Attribute(E2, "nr", 0),
864 Total = XML.Attribute(E2, "total", 0.0m),
865 Currency = XML.Attribute(E2, "currency")
866 });
867 }
868 }
869 }
870 else
871 e.Ok = false;
872
873 e.State = P[1];
874 await Callback.Raise(this, new TokenTotalsEventArgs(e, Totals.ToArray()));
875 }
876
881 public Task<TokenTotalsEventArgs> GetTotalsAsync()
882 {
883 return this.GetTotalsAsync(this.componentAddress);
884 }
885
891 public async Task<TokenTotalsEventArgs> GetTotalsAsync(string Address)
892 {
893 TaskCompletionSource<TokenTotalsEventArgs> Result = new TaskCompletionSource<TokenTotalsEventArgs>();
894
895 await this.GetTotals(Address, (Sender, e) =>
896 {
897 Result.TrySetResult(e);
898 return Task.CompletedTask;
899
900 }, null);
901
902 return await Result.Task;
903 }
904
905 #endregion
906
907 #region AddTextNote
908
916 public Task AddTextNote(string TokenId, string Note, EventHandlerAsync<IqResultEventArgs> Callback, object State)
917 {
918 return this.AddTextNote(TokenId, Note, false, Callback, State);
919 }
920
930 public Task AddTextNote(string TokenId, string Note, bool Personal, EventHandlerAsync<IqResultEventArgs> Callback, object State)
931 {
932 string Domain = this.GetDomain(TokenId);
933 StringBuilder Xml = new StringBuilder();
934
935 Xml.Append("<noteText xmlns='");
936 Xml.Append(NamespaceNeuroFeatures);
937 Xml.Append("' id='");
938 Xml.Append(XML.Encode(TokenId));
939 Xml.Append("' personal='");
940 Xml.Append(CommonTypes.Encode(Personal));
941 Xml.Append("'>");
942 Xml.Append(XML.Encode(Note));
943 Xml.Append("</noteText>");
944
945 return this.client.SendIqSet(Domain, Xml.ToString(), Callback, State);
946 }
947
953 public Task AddTextNoteAsync(string TokenId, string Note)
954 {
955 return this.AddTextNoteAsync(TokenId, Note, false);
956 }
957
965 public async Task AddTextNoteAsync(string TokenId, string Note, bool Personal)
966 {
967 TaskCompletionSource<bool> Result = new TaskCompletionSource<bool>();
968
969 await this.AddTextNote(TokenId, Note, Personal, (Sender, e) =>
970 {
971 if (e.Ok)
972 Result.TrySetResult(true);
973 else
974 Result.TrySetException(e.StanzaError ?? new Exception("Unable to add text note."));
975
976 return Task.CompletedTask;
977 }, null);
978
979 await Result.Task;
980 }
981
982 #endregion
983
984 #region AddXmlNote
985
993 public Task AddXmlNote(string TokenId, string Note, EventHandlerAsync<IqResultEventArgs> Callback, object State)
994 {
995 return this.AddXmlNote(TokenId, Note, false, Callback, State);
996 }
997
1007 public Task AddXmlNote(string TokenId, string Note, bool Personal, EventHandlerAsync<IqResultEventArgs> Callback, object State)
1008 {
1009 if (!XML.IsValidXml(Note))
1010 throw new ArgumentException("Note is not valid XML.", nameof(Note));
1011
1012 string Domain = this.GetDomain(TokenId);
1013 StringBuilder Xml = new StringBuilder();
1014
1015 Xml.Append("<noteXml xmlns='");
1016 Xml.Append(NamespaceNeuroFeatures);
1017 Xml.Append("' id='");
1018 Xml.Append(XML.Encode(TokenId));
1019 Xml.Append("' personal='");
1020 Xml.Append(CommonTypes.Encode(Personal));
1021 Xml.Append("'>");
1022 Xml.Append(Note);
1023 Xml.Append("</noteXml>");
1024
1025 return this.client.SendIqSet(Domain, Xml.ToString(), Callback, State);
1026 }
1027
1033 public Task AddXmlNoteAsync(string TokenId, string Note)
1034 {
1035 return this.AddXmlNoteAsync(TokenId, Note, false);
1036 }
1037
1045 public async Task AddXmlNoteAsync(string TokenId, string Note, bool Personal)
1046 {
1047 TaskCompletionSource<bool> Result = new TaskCompletionSource<bool>();
1048
1049 await this.AddXmlNote(TokenId, Note, Personal, (Sender, e) =>
1050 {
1051 if (e.Ok)
1052 Result.TrySetResult(true);
1053 else
1054 Result.TrySetException(e.StanzaError ?? new Exception("Unable to add xml note."));
1055
1056 return Task.CompletedTask;
1057 }, null);
1058
1059 await Result.Task;
1060 }
1061
1062 #endregion
1063
1064 #region GetEvents
1065
1072 public Task GetEvents(string TokenId, EventHandlerAsync<EventsEventArgs> Callback, object State)
1073 {
1074 return this.GetEvents(TokenId, 0, int.MaxValue, Callback, State);
1075 }
1076
1085 public Task GetEvents(string TokenId, int Offset, int MaxCount, EventHandlerAsync<EventsEventArgs> Callback, object State)
1086 {
1087 if (Offset < 0)
1088 throw new ArgumentException("Offsets cannot be negative.", nameof(Offset));
1089
1090 if (MaxCount <= 0)
1091 throw new ArgumentException("Must be postitive.", nameof(MaxCount));
1092
1093 StringBuilder Xml = new StringBuilder();
1094
1095 Xml.Append("<events xmlns='");
1096 Xml.Append(NamespaceNeuroFeatures);
1097 Xml.Append("' id='");
1098 Xml.Append(XML.Encode(TokenId));
1099
1100 if (Offset > 0)
1101 {
1102 Xml.Append("' offset='");
1103 Xml.Append(Offset.ToString());
1104 }
1105
1106 if (MaxCount < int.MaxValue)
1107 {
1108 Xml.Append("' maxCount='");
1109 Xml.Append(MaxCount.ToString());
1110 }
1111
1112 Xml.Append("'/>");
1113
1114 return this.client.SendIqGet(this.GetDomain(TokenId), Xml.ToString(), async (Sender, e) =>
1115 {
1116 XmlElement E = e.FirstElement;
1117 List<TokenEvent> Events = new List<TokenEvent>();
1118
1119 if (e.Ok && !(E is null))
1120 {
1121 foreach (XmlNode N in E.ChildNodes)
1122 {
1123 if (N is XmlElement E2 && E2.NamespaceURI == NamespaceNeuroFeatures)
1124 {
1125 if (TokenEvent.TryParse(E2, out TokenEvent Event))
1126 Events.Add(Event);
1127 }
1128 }
1129 }
1130 else
1131 e.Ok = false;
1132
1133 e.State = State;
1134 await Callback.Raise(this, new EventsEventArgs(e, Events.ToArray()));
1135
1136 }, null);
1137 }
1138
1143 public Task<TokenEvent[]> GetEventsAsync(string TokenId)
1144 {
1145 return this.GetEventsAsync(TokenId, 0, int.MaxValue);
1146 }
1147
1154 public async Task<TokenEvent[]> GetEventsAsync(string TokenId, int Offset, int MaxCount)
1155 {
1156 TaskCompletionSource<TokenEvent[]> Result = new TaskCompletionSource<TokenEvent[]>();
1157
1158 await this.GetEvents(TokenId, Offset, MaxCount, (Sender, e) =>
1159 {
1160 if (e.Ok)
1161 Result.TrySetResult(e.Events);
1162 else
1163 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get token events."));
1164
1165 return Task.CompletedTask;
1166 }, null);
1167
1168 return await Result.Task;
1169 }
1170
1171 #endregion
1172
1173 #region GetCreationAttributes
1174
1180 public Task GetCreationAttributes(EventHandlerAsync<CreationAttributesEventArgs> Callback, object State)
1181 {
1182 return this.client.SendIqGet(this.componentAddress, "<creationAttributes xmlns='" + NamespaceNeuroFeatures + "'/>", (Sender, e) =>
1183 {
1184 return Callback.Raise(this, new CreationAttributesEventArgs(e));
1185 }, State);
1186 }
1187
1192 public async Task<CreationAttributesEventArgs> GetCreationAttributesAsync()
1193 {
1194 TaskCompletionSource<CreationAttributesEventArgs> Result = new TaskCompletionSource<CreationAttributesEventArgs>();
1195
1196 await this.GetCreationAttributes((Sender, e) =>
1197 {
1198 if (e.Ok)
1199 Result.TrySetResult(e);
1200 else
1201 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get creation attributes."));
1202
1203 return Task.CompletedTask;
1204 }, null);
1205
1206 return await Result.Task;
1207 }
1208
1209 #endregion
1210
1211 #region GenerateDescription
1212
1220 public Task GenerateDescription(string TokenId, ReportFormat Format,
1221 EventHandlerAsync<ReportEventArgs> Callback, object State)
1222 {
1223 string Domain = this.GetDomain(TokenId);
1224 StringBuilder Xml = new StringBuilder();
1225
1226 Xml.Append("<description xmlns='");
1227 Xml.Append(NamespaceNeuroFeatures);
1228 Xml.Append("' id='");
1229 Xml.Append(XML.Encode(TokenId));
1230 Xml.Append("' format='");
1231 Xml.Append(Format.ToString());
1232 Xml.Append("'/>");
1233
1234 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) => this.ReportResponse(e, Callback), State);
1235 }
1236
1237 private async Task ReportResponse(IqResultEventArgs e, EventHandlerAsync<ReportEventArgs> Callback)
1238 {
1239 try
1240 {
1241 string ReportText = null;
1242
1243 if (e.Ok && e.FirstElement.LocalName == "report" &&
1244 (e.FirstElement.NamespaceURI == NamespaceStateMachine ||
1245 e.FirstElement.NamespaceURI == NamespaceNeuroFeatures))
1246 {
1247 ReportText = e.FirstElement.InnerText;
1248 }
1249 else
1250 e.Ok = false;
1251
1252 await Callback.Raise(this, new ReportEventArgs(ReportText, e));
1253 }
1254 catch (Exception ex)
1255 {
1256 await this.client.Exception(ex);
1257 Log.Exception(ex);
1258 }
1259 }
1260
1266 public async Task<ReportEventArgs> GenerateDescriptionAsync(string TokenId, ReportFormat Format)
1267 {
1268 TaskCompletionSource<ReportEventArgs> Result = new TaskCompletionSource<ReportEventArgs>();
1269
1270 await this.GenerateDescription(TokenId, Format, (Sender, e) =>
1271 {
1272 if (e.Ok)
1273 Result.TrySetResult(e);
1274 else
1275 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get the description of the token."));
1276
1277 return Task.CompletedTask;
1278 }, null);
1279
1280 return await Result.Task;
1281 }
1282
1283 #endregion
1284
1285 #endregion
1286
1287 #region State-Machines
1288
1289 #region GetCurrentState
1290
1297 public Task GetCurrentState(string TokenId, EventHandlerAsync<CurrentStateEventArgs> Callback, object State)
1298 {
1299 string Domain = this.GetDomain(TokenId);
1300 StringBuilder Xml = new StringBuilder();
1301
1302 Xml.Append("<currentState xmlns='");
1303 Xml.Append(NamespaceStateMachine);
1304 Xml.Append("' tokenId='");
1305 Xml.Append(XML.Encode(TokenId));
1306 Xml.Append("'/>");
1307
1308 return this.client.SendIqGet(Domain, Xml.ToString(), async (Sender, e) =>
1309 {
1310 try
1311 {
1312 string CurrentState = null;
1313 bool Ended = false;
1314 bool Running = false;
1315 DateTime Expires = DateTime.MinValue;
1316 Variables Variables = null;
1317
1318 if (e.Ok && e.FirstElement.LocalName == "currentState" && e.FirstElement.NamespaceURI == NamespaceStateMachine)
1319 {
1320 CurrentState = XML.Attribute(e.FirstElement, "state");
1321 Ended = XML.Attribute(e.FirstElement, "ended", false);
1322 Running = XML.Attribute(e.FirstElement, "running", false);
1323 Expires = XML.Attribute(e.FirstElement, "expires", DateTime.MaxValue);
1324 Variables = await ParseVariables(e.FirstElement);
1325 }
1326 else
1327 e.Ok = false;
1328
1329 await Callback.Raise(this, new CurrentStateEventArgs(CurrentState, Ended, Running,
1330 Expires, Variables, e));
1331 }
1332 catch (Exception ex)
1333 {
1334 await this.client.Exception(ex);
1335 Log.Exception(ex);
1336 }
1337 }, State);
1338 }
1339
1340 private async static Task<Variables> ParseVariables(XmlElement VariablesDefinition)
1341 {
1343
1344 foreach (XmlNode N in VariablesDefinition.ChildNodes)
1345 {
1346 if (N is XmlElement E &&
1347 E.LocalName == "variable" &&
1348 E.NamespaceURI == NamespaceStateMachine)
1349 {
1350 string Name = XML.Attribute(E, "name");
1351 object Value = await ParseVariable(E, Variables);
1352
1353 Variables[Name] = Value;
1354 }
1355 }
1356
1357 return Variables;
1358 }
1359
1360 private async static Task<object> ParseVariable(XmlElement VariableDefinition, Variables Variables)
1361 {
1362 object Value = null;
1363
1364 foreach (XmlNode N2 in VariableDefinition.ChildNodes)
1365 {
1366 if (!(N2 is XmlElement E2))
1367 continue;
1368
1369 switch (E2.LocalName)
1370 {
1371 case "null":
1372 Value = null;
1373 break;
1374
1375 case "dbl":
1376 if (CommonTypes.TryParse(E2.InnerText, out double dbl))
1377 Value = dbl;
1378 break;
1379
1380 case "fl":
1381 if (CommonTypes.TryParse(E2.InnerText, out float fl))
1382 Value = fl;
1383 break;
1384
1385 case "dec":
1386 if (CommonTypes.TryParse(E2.InnerText, out decimal dec))
1387 Value = dec;
1388 break;
1389
1390 case "i8":
1391 if (sbyte.TryParse(E2.InnerText, out sbyte i8))
1392 Value = i8;
1393 break;
1394
1395 case "i16":
1396 if (short.TryParse(E2.InnerText, out short i16))
1397 Value = i16;
1398 break;
1399
1400 case "i32":
1401 if (int.TryParse(E2.InnerText, out int i32))
1402 Value = i32;
1403 break;
1404
1405 case "i64":
1406 if (long.TryParse(E2.InnerText, out long i64))
1407 Value = i64;
1408 break;
1409
1410 case "ui8":
1411 if (byte.TryParse(E2.InnerText, out byte ui8))
1412 Value = ui8;
1413 break;
1414
1415 case "ui16":
1416 if (ushort.TryParse(E2.InnerText, out ushort ui16))
1417 Value = ui16;
1418 break;
1419
1420 case "ui32":
1421 if (uint.TryParse(E2.InnerText, out uint ui32))
1422 Value = ui32;
1423 break;
1424
1425 case "ui64":
1426 if (ulong.TryParse(E2.InnerText, out ulong ui64))
1427 Value = ui64;
1428 break;
1429
1430 case "b":
1431 if (CommonTypes.TryParse(E2.InnerText, out bool b))
1432 Value = b;
1433 break;
1434
1435 case "dt":
1436 if (XML.TryParse(E2.InnerText, out DateTime TP))
1437 Value = TP;
1438 break;
1439
1440 case "dto":
1441 if (XML.TryParse(E2.InnerText, out DateTimeOffset TPO))
1442 Value = TPO;
1443 break;
1444
1445 case "ts":
1446 if (TimeSpan.TryParse(E2.InnerText, out TimeSpan TS))
1447 Value = TS;
1448 break;
1449
1450 case "d":
1451 if (Duration.TryParse(E2.InnerText, out Duration D))
1452 Value = D;
1453 break;
1454
1455 case "s":
1456 Value = E2.InnerText;
1457 break;
1458
1459 case "exp":
1460 try
1461 {
1462 Expression Exp = new Expression(E2.InnerText);
1463 Value = await Exp.EvaluateAsync(Variables);
1464 }
1465 catch (Exception)
1466 {
1467 Value = E2.InnerText;
1468 }
1469 break;
1470 }
1471 }
1472
1473 return Value;
1474 }
1475
1480 public async Task<CurrentStateEventArgs> GetCurrentStateAsync(string TokenId)
1481 {
1482 TaskCompletionSource<CurrentStateEventArgs> Result = new TaskCompletionSource<CurrentStateEventArgs>();
1483
1484 await this.GetCurrentState(TokenId, (Sender, e) =>
1485 {
1486 if (e.Ok)
1487 Result.TrySetResult(e);
1488 else
1489 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get current state of state-machine."));
1490
1491 return Task.CompletedTask;
1492 }, null);
1493
1494 return await Result.Task;
1495 }
1496
1497 #endregion
1498
1499 #region GenerateProfilingReport
1500
1508 public Task GenerateProfilingReport(string TokenId, ReportFormat Format,
1509 EventHandlerAsync<ReportEventArgs> Callback, object State)
1510 {
1511 string Domain = this.GetDomain(TokenId);
1512 StringBuilder Xml = new StringBuilder();
1513
1514 Xml.Append("<profilingReport xmlns='");
1515 Xml.Append(NamespaceStateMachine);
1516 Xml.Append("' tokenId='");
1517 Xml.Append(XML.Encode(TokenId));
1518 Xml.Append("' format='");
1519 Xml.Append(Format.ToString());
1520 Xml.Append("'/>");
1521
1522 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) => this.ReportResponse(e, Callback), State);
1523 }
1524
1530 public async Task<ReportEventArgs> GenerateProfilingReportAsync(string TokenId, ReportFormat Format)
1531 {
1532 TaskCompletionSource<ReportEventArgs> Result = new TaskCompletionSource<ReportEventArgs>();
1533
1534 await this.GenerateProfilingReport(TokenId, Format, (Sender, e) =>
1535 {
1536 if (e.Ok)
1537 Result.TrySetResult(e);
1538 else
1539 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get the profiling report of the state-machine."));
1540
1541 return Task.CompletedTask;
1542 }, null);
1543
1544 return await Result.Task;
1545 }
1546
1547 #endregion
1548
1549 #region GeneratePresentReport
1550
1558 public Task GeneratePresentReport(string TokenId, ReportFormat Format,
1559 EventHandlerAsync<ReportEventArgs> Callback, object State)
1560 {
1561 string Domain = this.GetDomain(TokenId);
1562 StringBuilder Xml = new StringBuilder();
1563
1564 Xml.Append("<presentReport xmlns='");
1565 Xml.Append(NamespaceStateMachine);
1566 Xml.Append("' tokenId='");
1567 Xml.Append(XML.Encode(TokenId));
1568 Xml.Append("' format='");
1569 Xml.Append(Format.ToString());
1570 Xml.Append("'/>");
1571
1572 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) => this.ReportResponse(e, Callback), State);
1573 }
1574
1580 public async Task<ReportEventArgs> GeneratePresentReportAsync(string TokenId, ReportFormat Format)
1581 {
1582 TaskCompletionSource<ReportEventArgs> Result = new TaskCompletionSource<ReportEventArgs>();
1583
1584 await this.GeneratePresentReport(TokenId, Format, (Sender, e) =>
1585 {
1586 if (e.Ok)
1587 Result.TrySetResult(e);
1588 else
1589 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get the profiling report of the state-machine."));
1590
1591 return Task.CompletedTask;
1592 }, null);
1593
1594 return await Result.Task;
1595 }
1596
1597 #endregion
1598
1599 #region GenerateHistoryReport
1600
1608 public Task GenerateHistoryReport(string TokenId, ReportFormat Format,
1609 EventHandlerAsync<ReportEventArgs> Callback, object State)
1610 {
1611 string Domain = this.GetDomain(TokenId);
1612 StringBuilder Xml = new StringBuilder();
1613
1614 Xml.Append("<historyReport xmlns='");
1615 Xml.Append(NamespaceStateMachine);
1616 Xml.Append("' tokenId='");
1617 Xml.Append(XML.Encode(TokenId));
1618 Xml.Append("' format='");
1619 Xml.Append(Format.ToString());
1620 Xml.Append("'/>");
1621
1622 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) => this.ReportResponse(e, Callback), State);
1623 }
1624
1630 public async Task<ReportEventArgs> GenerateHistoryReportAsync(string TokenId, ReportFormat Format)
1631 {
1632 TaskCompletionSource<ReportEventArgs> Result = new TaskCompletionSource<ReportEventArgs>();
1633
1634 await this.GenerateHistoryReport(TokenId, Format, (Sender, e) =>
1635 {
1636 if (e.Ok)
1637 Result.TrySetResult(e);
1638 else
1639 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get the profiling report of the state-machine."));
1640
1641 return Task.CompletedTask;
1642 }, null);
1643
1644 return await Result.Task;
1645 }
1646
1647 #endregion
1648
1649 #region GenerateStateDiagram
1650
1658 public Task GenerateStateDiagram(string TokenId, ReportFormat Format,
1659 EventHandlerAsync<ReportEventArgs> Callback, object State)
1660 {
1661 string Domain = this.GetDomain(TokenId);
1662 StringBuilder Xml = new StringBuilder();
1663
1664 Xml.Append("<stateDiagram xmlns='");
1665 Xml.Append(NamespaceStateMachine);
1666 Xml.Append("' tokenId='");
1667 Xml.Append(XML.Encode(TokenId));
1668 Xml.Append("' format='");
1669 Xml.Append(Format.ToString());
1670 Xml.Append("'/>");
1671
1672 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) => this.ReportResponse(e, Callback), State);
1673 }
1674
1680 public async Task<ReportEventArgs> GenerateStateDiagramAsync(string TokenId, ReportFormat Format)
1681 {
1682 TaskCompletionSource<ReportEventArgs> Result = new TaskCompletionSource<ReportEventArgs>();
1683
1684 await this.GenerateStateDiagram(TokenId, Format, (Sender, e) =>
1685 {
1686 if (e.Ok)
1687 Result.TrySetResult(e);
1688 else
1689 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get the state diagram of the state-machine."));
1690
1691 return Task.CompletedTask;
1692 }, null);
1693
1694 return await Result.Task;
1695 }
1696
1697 #endregion
1698
1699 #region StateUpdated
1700
1701 private Task StateUpdatedHandler(object Sender, MessageEventArgs e)
1702 {
1703 string TokenId = XML.Attribute(e.Content, "tokenId");
1704 string MachineId = XML.Attribute(e.Content, "machineId");
1705 string NewState = XML.Attribute(e.Content, "state");
1706
1707 return this.StateUpdated.Raise(this, new NewStateEventArgs(TokenId, MachineId, NewState, e));
1708 }
1709
1713 public event EventHandlerAsync<NewStateEventArgs> StateUpdated;
1714
1715 #endregion
1716
1717 #region VariablesUpdated
1718
1719 private async Task VariablesUpdatedHandler(object Sender, MessageEventArgs e)
1720 {
1721 string TokenId = XML.Attribute(e.Content, "tokenId");
1722 string MachineId = XML.Attribute(e.Content, "machineId");
1723 Variables Variables = await ParseVariables(e.Content);
1724
1725 await this.VariablesUpdated.Raise(this, new VariablesUpdatedEventArgs(TokenId, MachineId, Variables, e));
1726 }
1727
1731 public event EventHandlerAsync<VariablesUpdatedEventArgs> VariablesUpdated;
1732
1733 #endregion
1734
1735 #endregion
1736 }
1737}
Event arguments for callback methods to token creation attributes queries.
Event arguments for current state callback methods.
Event arguments for Token events responses
Event arguments events when the current state of a state-machine has changed.
Event arguments for report callback methods.
Event arguments for token events.
Event arguments for callback methods to token queries.
Event arguments to totals response callback methods.
Event arguments for Tokens responses
Event arguments events when the variables of a state-machine has changed.
Abstract base class for token events.
Definition: TokenEvent.cs:13
static bool TryParse(XmlElement Xml, out TokenEvent Event)
Tries to parse a token event from its XML definition.
Definition: TokenEvent.cs:100
Task GetContractTokens(string Address, string ContractId, int Offset, int MaxCount, EventHandlerAsync< TokensEventArgs > Callback, object State)
Get tokens created by a contract the account has access to.
async Task< ReportEventArgs > GenerateHistoryReportAsync(string TokenId, ReportFormat Format)
Generates a history report of a state-machine belonging to a token.
Task< TokensEventArgs > GetTokensAsync()
Get tokens the account owns.
async Task< string[]> GetTokenReferencesAsync(string Address, int Offset, int MaxCount)
Get references to tokens the account owns.
Task GetContractTokens(string Address, string ContractId, EventHandlerAsync< TokensEventArgs > Callback, object State)
Get tokens created by a contract the account has access to.
async Task< TokensEventArgs > GetContractTokensAsync(string Address, string ContractId, int Offset, int MaxCount)
Get tokens created by a contract the account has access to.
Task GetTokenReferences(EventHandlerAsync< IdReferencesEventArgs > Callback, object State)
Get references to tokens the account owns.
Task GetCurrentState(string TokenId, EventHandlerAsync< CurrentStateEventArgs > Callback, object State)
Gets the current state of a state-machine belonging to a token.
Task AddXmlNote(string TokenId, string Note, bool Personal, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Adds a xml note to a token. Notes attached to a token can be retrieved by calling GetEvents.
async Task< TokenEvent[]> GetEventsAsync(string TokenId, int Offset, int MaxCount)
Get events registered for a token the account owns.
EventHandlerAsync< TokenEventArgs > TokenAdded
Event raised when a token has been added to the account.
Task< TokensEventArgs > GetContractTokensAsync(string ContractId)
Get tokens created by a contract the account has access to.
Task GetContractTokenReferences(string ContractId, int Offset, int MaxCount, EventHandlerAsync< IdReferencesEventArgs > Callback, object State)
Get references to tokens created by a contract the account has access to.
Task< TokensEventArgs > GetTokensAsync(int Offset, int MaxCount)
Get tokens the account owns.
async Task< string[]> GetContractTokenReferencesAsync(string Address, string ContractId, int Offset, int MaxCount)
Get references to tokens created by a contract the account has access to.
Task GenerateDescription(string TokenId, ReportFormat Format, EventHandlerAsync< ReportEventArgs > Callback, object State)
Gets a description of a token.
Task< string[]> GetContractTokenReferencesAsync(string ContractId)
Get references to tokens created by a contract the account has access to.
Task GetTokens(EventHandlerAsync< TokensEventArgs > Callback, object State)
Get tokens the account owns.
Task< string[]> GetContractTokenReferencesAsync(string Address, string ContractId)
Get references to tokens created by a contract the account has access to.
EventHandlerAsync< NewStateEventArgs > StateUpdated
Event raised when the state of a state-machine has been updated.
Task< TokensEventArgs > GetContractTokensAsync(string Address, string ContractId)
Get tokens created by a contract the account has access to.
Task GetContractTokens(string ContractId, EventHandlerAsync< TokensEventArgs > Callback, object State)
Get tokens created by a contract the account has access to.
override void Dispose()
IDisposable.Dispose
async Task< ReportEventArgs > GeneratePresentReportAsync(string TokenId, ReportFormat Format)
Generates a present report of a state-machine belonging to a token.
Task GetTokenReferences(string Address, int Offset, int MaxCount, EventHandlerAsync< IdReferencesEventArgs > Callback, object State)
Get references to tokens the account owns.
Task GetContractTokenReferences(string ContractId, EventHandlerAsync< IdReferencesEventArgs > Callback, object State)
Get references to tokens created by a contract the account has access to.
Task GetEvents(string TokenId, EventHandlerAsync< EventsEventArgs > Callback, object State)
Get events registered for a token the account owns.
async Task< CurrentStateEventArgs > GetCurrentStateAsync(string TokenId)
Gets the current state of a state-machine belonging to a token.
Task GetEvents(string TokenId, int Offset, int MaxCount, EventHandlerAsync< EventsEventArgs > Callback, object State)
Get events registered for a token the account owns.
async Task< CreationAttributesEventArgs > GetCreationAttributesAsync()
Gets attributes relevant for creating tokens on the broker.
async Task< TokensEventArgs > GetTokensAsync(string Address, int Offset, int MaxCount)
Get tokens the account owns.
async Task< ReportEventArgs > GenerateProfilingReportAsync(string TokenId, ReportFormat Format)
Generates a profiling report of a state-machine belonging to a token.
Task< TokensEventArgs > GetContractTokensAsync(string ContractId, int Offset, int MaxCount)
Get tokens created by a contract the account has access to.
Task AddTextNoteAsync(string TokenId, string Note)
Adds a text note to a token. Notes attached to a token can be retrieved by calling GetEvents.
Task< string[]> GetContractTokenReferencesAsync(string ContractId, int Offset, int MaxCount)
Get references to tokens created by a contract the account has access to.
EventHandlerAsync< TokenEventArgs > TokenRemoved
Event raised when a token has been removed from the account.
Task GetTokens(string Address, int Offset, int MaxCount, EventHandlerAsync< TokensEventArgs > Callback, object State)
Get tokens the account owns.
const string NamespaceNeuroFeatures
Namespace for Neuro-Features.
Task< TokenTotalsEventArgs > GetTotalsAsync()
Get totals of tokens the sender owns.
Task< string[]> GetTokenReferencesAsync()
Get references to tokens the account owns.
Task< TokensEventArgs > GetTokensAsync(string Address)
Get tokens the account owns.
Task GenerateProfilingReport(string TokenId, ReportFormat Format, EventHandlerAsync< ReportEventArgs > Callback, object State)
Gets a profiling report of a state-machine belonging to a token.
Task AddTextNote(string TokenId, string Note, bool Personal, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Adds a text note to a token. Notes attached to a token can be retrieved by calling GetEvents.
Task GetContractTokenReferences(string Address, string ContractId, int Offset, int MaxCount, EventHandlerAsync< IdReferencesEventArgs > Callback, object State)
Get references to tokens created by a contract the account has access to.
Task AddXmlNote(string TokenId, string Note, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Adds a xml note to a token. Notes attached to a token can be retrieved by calling GetEvents.
string ComponentAddress
Address of eDaler component
Task< TokenEvent[]> GetEventsAsync(string TokenId)
Get events registered for a token the account owns.
async Task AddXmlNoteAsync(string TokenId, string Note, bool Personal)
Adds a xml note to a token. Notes attached to a token can be retrieved by calling GetEvents.
override string[] Extensions
Implemented extensions.
Task GenerateStateDiagram(string TokenId, ReportFormat Format, EventHandlerAsync< ReportEventArgs > Callback, object State)
Gets a state diagram of a state-machine belonging to a token.
Task GeneratePresentReport(string TokenId, ReportFormat Format, EventHandlerAsync< ReportEventArgs > Callback, object State)
Gets a present report of a state-machine belonging to a token.
Task GetTokenReferences(string Address, EventHandlerAsync< IdReferencesEventArgs > Callback, object State)
Get references to tokens the account owns.
Task GenerateHistoryReport(string TokenId, ReportFormat Format, EventHandlerAsync< ReportEventArgs > Callback, object State)
Gets a history report of a state-machine belonging to a token.
ContractsClient ContractsClient
Reference to the Smart Contracts client.
NeuroFeaturesClient(XmppClient Client, ContractsClient ContractsClient, string ComponentAddress)
Neuro-Features XMPP client.
Task GetTokens(string Address, EventHandlerAsync< TokensEventArgs > Callback, object State)
Get tokens the account owns.
Task GetTokens(int Offset, int MaxCount, EventHandlerAsync< TokensEventArgs > Callback, object State)
Get tokens the account owns.
async Task< ReportEventArgs > GenerateStateDiagramAsync(string TokenId, ReportFormat Format)
Generates a state diagram of a state-machine belonging to a token.
Task GetTotals(string Address, EventHandlerAsync< TokenTotalsEventArgs > Callback, object State)
Get totals of tokens the sender owns.
Task GetToken(string TokenId, EventHandlerAsync< TokenResultEventArgs > Callback, object State)
Gets a token, given its full ID.
async Task AddTextNoteAsync(string TokenId, string Note, bool Personal)
Adds a text note to a token. Notes attached to a token can be retrieved by calling GetEvents.
async Task< Token > GetTokenAsync(string TokenId)
Gets a token, given its full ID.
Task GetTokenReferences(int Offset, int MaxCount, EventHandlerAsync< IdReferencesEventArgs > Callback, object State)
Get references to tokens the account owns.
Task< string[]> GetTokenReferencesAsync(string Address)
Get references to tokens the account owns.
const string DefinitionStateMachine
Local name of state-machine definition
Task< string[]> GetTokenReferencesAsync(int Offset, int MaxCount)
Get references to tokens the account owns.
Task GetContractTokenReferences(string Address, string ContractId, EventHandlerAsync< IdReferencesEventArgs > Callback, object State)
Get references to tokens created by a contract the account has access to.
async Task< ReportEventArgs > GenerateDescriptionAsync(string TokenId, ReportFormat Format)
Gets a description of a token.
async Task< TokenTotalsEventArgs > GetTotalsAsync(string Address)
Get totals of tokens the sender owns.
Task AddXmlNoteAsync(string TokenId, string Note)
Adds a xml note to a token. Notes attached to a token can be retrieved by calling GetEvents.
Task GetTotals(EventHandlerAsync< TokenTotalsEventArgs > Callback, object State)
Get totals of tokens the sender owns.
Task GetContractTokens(string ContractId, int Offset, int MaxCount, EventHandlerAsync< TokensEventArgs > Callback, object State)
Get tokens created by a contract the account has access to.
EventHandlerAsync< VariablesUpdatedEventArgs > VariablesUpdated
Event raised when variables in a state-machine have been updated.
Task GetCreationAttributes(EventHandlerAsync< CreationAttributesEventArgs > Callback, object State)
Gets attributes relevant for creating tokens on the broker.
Task AddTextNote(string TokenId, string Note, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Adds a text note to a token. Notes attached to a token can be retrieved by calling GetEvents.
const string NamespaceStateMachine
Namespace for State-Machines.
Neuro-Feature Token
Definition: Token.cs:43
static bool TryParse(XmlElement Xml, out Token Token)
Serializes the Token, in normalized form.
Definition: Token.cs:523
Contains one token total, i.e. sum of token values, for a given currency.
Definition: TokenTotal.cs:7
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:594
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Definition: CommonTypes.cs:46
Helps with common XML-related tasks.
Definition: XML.cs:19
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Definition: XML.cs:914
static string Encode(string s)
Encodes a string for use in XML.
Definition: XML.cs:27
static bool TryParse(string s, out DateTime Value)
Tries to decode a string encoded DateTime.
Definition: XML.cs:744
static bool IsValidXml(string Xml)
Checks if a string is valid XML
Definition: XML.cs:1223
Class representing an event.
Definition: Event.cs:10
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Definition: Log.cs:1647
Adds support for legal identities, smart contracts and signatures to an XMPP client.
Event arguments for responses to IQ queries.
bool Ok
If the response is an OK result response (true), or an error response (false).
object State
State object passed to the original request.
XmppException StanzaError
Any stanza error returned.
XmlElement FirstElement
First child element of the Response element.
Event arguments for message events.
XmlElement Content
Content of the message. For messages that are processed by registered message handlers,...
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:59
bool UnregisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool RemoveNamespaceAsClientFeature)
Unregisters a Message handler.
Definition: XmppClient.cs:2855
void RegisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool PublishNamespaceAsClientFeature)
Registers a Message handler.
Definition: XmppClient.cs:2828
Task< uint > SendIqGet(string To, string Xml, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends an IQ Get request.
Definition: XmppClient.cs:3559
Base class for XMPP Extensions.
XmppClient client
XMPP Client used by the extension.
XmppClient Client
XMPP Client.
Class managing a script expression.
Definition: Expression.cs:39
async Task< object > EvaluateAsync(Variables Variables)
Evaluates the expression, using the variables provided in the Variables collection....
Definition: Expression.cs:4275
Collection of variables.
Definition: Variables.cs:25
ReportFormat
Desired report format
Definition: ReportFormat.cs:7
Represents a duration value, as defined by the xsd:duration data type: http://www....
Definition: Duration.cs:13
static bool TryParse(string s, out Duration Result)
Tries to parse a duration value.
Definition: Duration.cs:85