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;
5using System.Text;
6using System.Threading.Tasks;
7using System.Xml;
8using Waher.Content;
10using Waher.Events;
15using Waher.Script;
16
17namespace NeuroFeatures
18{
23 {
27 public const string NamespaceNeuroFeatures = "https://paiwise.tagroot.io/Schema/NeuroFeatures.xsd";
28
32 public const string NamespaceStateMachine = "https://paiwise.tagroot.io/Schema/StateMachines.xsd";
33
37 public const string DefinitionStateMachine = "StateMachine";
38
39 private readonly ContractsClient contractsClient;
40 private readonly string componentAddress;
41
42 #region Setup
43
51 : base(Client)
52 {
53 this.componentAddress = ComponentAddress;
54 this.contractsClient = ContractsClient;
55
56 Client.RegisterMessageHandler("tokenAdded", NamespaceNeuroFeatures, this.TokenAddedHandler, true);
57 Client.RegisterMessageHandler("tokenRemoved", NamespaceNeuroFeatures, this.TokenRemovedHandler, false);
58
59 Client.RegisterMessageHandler("stateUpdated", NamespaceStateMachine, this.StateUpdatedHandler, true);
60 Client.RegisterMessageHandler("variablesUpdated", NamespaceStateMachine, this.VariablesUpdatedHandler, false);
61 }
62
66 public ContractsClient ContractsClient => this.contractsClient;
67
71 public override void Dispose()
72 {
73 this.Client.UnregisterMessageHandler("tokenAdded", NamespaceNeuroFeatures, this.TokenAddedHandler, true);
74 this.Client.UnregisterMessageHandler("tokenRemoved", NamespaceNeuroFeatures, this.TokenRemovedHandler, false);
75
76 this.Client.UnregisterMessageHandler("stateUpdated", NamespaceStateMachine, this.StateUpdatedHandler, true);
77 this.Client.UnregisterMessageHandler("variablesUpdated", NamespaceStateMachine, this.VariablesUpdatedHandler, false);
78
79 base.Dispose();
80 }
81
85 public string ComponentAddress => this.componentAddress;
86
90 public override string[] Extensions => new string[] { };
91
92 #endregion
93
94 #region Tokens
95
96 #region GetToken
97
104 public Task GetToken(string TokenId, EventHandlerAsync<TokenResultEventArgs> Callback, object State)
105 {
106 string Domain = this.GetDomain(TokenId);
107 StringBuilder Xml = new StringBuilder();
108
109 Xml.Append("<token id='");
110 Xml.Append(XML.Encode(TokenId));
111 Xml.Append("' xmlns='");
112 Xml.Append(NamespaceNeuroFeatures);
113 Xml.Append("'/>");
114
115 return this.client.SendIqGet(Domain, Xml.ToString(), async (Sender, e) =>
116 {
117 Token ResultToken = null;
118
119 if (e.Ok)
120 {
121 if (e.FirstElement is null || e.FirstElement.LocalName != "token" || e.FirstElement.NamespaceURI != NamespaceNeuroFeatures)
122 {
123 e.Ok = false;
124 this.client.Error("Unexpected response.");
125 }
126 else if ((ResultToken = await Token.TryParse(e.FirstElement)) is null)
127 {
128 e.Ok = false;
129 this.client.Error("Unable to parse token.");
130 }
131 }
132
133 TokenResultEventArgs e2 = new TokenResultEventArgs(e, ResultToken);
134 await Callback.Raise(this, e2);
135 }, State);
136 }
137
138 private string GetDomain(string TokenId)
139 {
140 int i = TokenId.IndexOf('@');
141
142 if (i < 0)
143 return this.componentAddress;
144 else
145 return TokenId[(i + 1)..];
146 }
147
152 public async Task<Token> GetTokenAsync(string TokenId)
153 {
154 TaskCompletionSource<Token> Result = new TaskCompletionSource<Token>();
155
156 await this.GetToken(TokenId, (Sender, e) =>
157 {
158 if (e.Ok)
159 Result.TrySetResult(e.Token);
160 else
161 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get token."));
162
163 return Task.CompletedTask;
164 }, null);
165
166 return await Result.Task;
167 }
168
169 #endregion
170
171 #region Get Token References
172
178 public Task GetTokenReferences(EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
179 {
180 return this.GetTokenReferences(this.componentAddress, 0, int.MaxValue, Callback, State);
181 }
182
189 public Task GetTokenReferences(string Address, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
190 {
191 return this.GetTokenReferences(Address, 0, int.MaxValue, Callback, State);
192 }
193
201 public Task GetTokenReferences(int Offset, int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
202 {
203 return this.GetTokenReferences(this.componentAddress, Offset, MaxCount, Callback, State);
204 }
205
214 public Task GetTokenReferences(string Address, int Offset, int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
215 {
216 if (Offset < 0)
217 throw new ArgumentException("Offsets cannot be negative.", nameof(Offset));
218
219 if (MaxCount <= 0)
220 throw new ArgumentException("Must be postitive.", nameof(MaxCount));
221
222 StringBuilder Xml = new StringBuilder();
223
224 Xml.Append("<tokens references='true' xmlns='");
225 Xml.Append(NamespaceNeuroFeatures);
226
227 if (Offset > 0)
228 {
229 Xml.Append("' offset='");
230 Xml.Append(Offset.ToString());
231 }
232
233 if (MaxCount < int.MaxValue)
234 {
235 Xml.Append("' maxCount='");
236 Xml.Append(MaxCount.ToString());
237 }
238
239 Xml.Append("'/>");
240
241 return this.client.SendIqGet(Address, Xml.ToString(), this.TokenReferencesResponse, new object[] { Callback, State });
242 }
243
244 private async Task TokenReferencesResponse(object Sender, IqResultEventArgs e)
245 {
246 object[] P = (object[])e.State;
247 EventHandlerAsync<IdReferencesEventArgs> Callback = (EventHandlerAsync<IdReferencesEventArgs>)P[0];
248 XmlElement E = e.FirstElement;
249 List<string> IDs = new List<string>();
250
251 if (e.Ok && !(E is null))
252 {
253 foreach (XmlNode N in E.ChildNodes)
254 {
255 if (N is XmlElement E2 && E2.LocalName == "ref" && E2.NamespaceURI == NamespaceNeuroFeatures)
256 {
257 string Id = XML.Attribute(E2, "id");
258 IDs.Add(Id);
259 }
260 }
261 }
262 else
263 e.Ok = false;
264
265 e.State = P[1];
266 await Callback.Raise(this, new IdReferencesEventArgs(e, IDs.ToArray()));
267 }
268
273 public Task<string[]> GetTokenReferencesAsync()
274 {
275 return this.GetTokenReferencesAsync(this.componentAddress, 0, int.MaxValue);
276 }
277
283 public Task<string[]> GetTokenReferencesAsync(string Address)
284 {
285 return this.GetTokenReferencesAsync(Address, 0, int.MaxValue);
286 }
287
294 public Task<string[]> GetTokenReferencesAsync(int Offset, int MaxCount)
295 {
296 return this.GetTokenReferencesAsync(this.componentAddress, Offset, MaxCount);
297 }
298
306 public async Task<string[]> GetTokenReferencesAsync(string Address, int Offset, int MaxCount)
307 {
308 TaskCompletionSource<string[]> Result = new TaskCompletionSource<string[]>();
309
310 await this.GetTokenReferences(Address, Offset, MaxCount, (Sender, e) =>
311 {
312 if (e.Ok)
313 Result.TrySetResult(e.References);
314 else
315 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get token references."));
316
317 return Task.CompletedTask;
318
319 }, null);
320
321 return await Result.Task;
322 }
323
324
325
326 #endregion
327
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 Token ParsedToken = await Token.TryParse(E2);
418 if (!(ParsedToken is null))
419 Tokens.Add(ParsedToken);
420 break;
421
422 case "ref":
423 string TokenId = XML.Attribute(E2, "id");
424 References.Add(TokenId);
425 break;
426 }
427 }
428 }
429 }
430 else
431 e.Ok = false;
432
433 e.State = P[1];
434 await Callback.Raise(this, new TokensEventArgs(e, Tokens.ToArray(), References.ToArray()));
435 }
436
441 public Task<TokensEventArgs> GetTokensAsync()
442 {
443 return this.GetTokensAsync(this.componentAddress, 0, int.MaxValue);
444 }
445
451 public Task<TokensEventArgs> GetTokensAsync(string Address)
452 {
453 return this.GetTokensAsync(Address, 0, int.MaxValue);
454 }
455
462 public Task<TokensEventArgs> GetTokensAsync(int Offset, int MaxCount)
463 {
464 return this.GetTokensAsync(this.componentAddress, Offset, MaxCount);
465 }
466
474 public async Task<TokensEventArgs> GetTokensAsync(string Address, int Offset, int MaxCount)
475 {
476 TaskCompletionSource<TokensEventArgs> Result = new TaskCompletionSource<TokensEventArgs>();
477
478 await this.GetTokens(Address, Offset, MaxCount, (Sender, e) =>
479 {
480 Result.TrySetResult(e);
481 return Task.CompletedTask;
482
483 }, null);
484
485 return await Result.Task;
486 }
487
488 #endregion
489
490 #region Get Contract Token References
491
498 public Task GetContractTokenReferences(string ContractId, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
499 {
500 return this.GetContractTokenReferences(this.contractsClient.GetTrustProvider(ContractId),
501 ContractId, 0, int.MaxValue, Callback, State);
502 }
503
511 public Task GetContractTokenReferences(string Address, string ContractId, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
512 {
513 return this.GetContractTokenReferences(Address, ContractId, 0, int.MaxValue, Callback, State);
514 }
515
524 public Task GetContractTokenReferences(string ContractId, int Offset, int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
525 {
526 return this.GetContractTokenReferences(this.contractsClient.GetTrustProvider(ContractId),
527 ContractId, Offset, MaxCount, Callback, State);
528 }
529
539 public Task GetContractTokenReferences(string Address, string ContractId, int Offset, int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback, object State)
540 {
541 if (Offset < 0)
542 throw new ArgumentException("Offsets cannot be negative.", nameof(Offset));
543
544 if (MaxCount <= 0)
545 throw new ArgumentException("Must be postitive.", nameof(MaxCount));
546
547 StringBuilder Xml = new StringBuilder();
548
549 Xml.Append("<contractTokens contractId='");
550 Xml.Append(XML.Encode(ContractId));
551 Xml.Append("' references='true' xmlns='");
552 Xml.Append(NamespaceNeuroFeatures);
553
554 if (Offset > 0)
555 {
556 Xml.Append("' offset='");
557 Xml.Append(Offset.ToString());
558 }
559
560 if (MaxCount < int.MaxValue)
561 {
562 Xml.Append("' maxCount='");
563 Xml.Append(MaxCount.ToString());
564 }
565
566 Xml.Append("'/>");
567
568 return this.client.SendIqGet(Address, Xml.ToString(), this.TokenReferencesResponse, new object[] { Callback, State });
569 }
570
576 public Task<string[]> GetContractTokenReferencesAsync(string ContractId)
577 {
578 return this.GetContractTokenReferencesAsync(this.contractsClient.GetTrustProvider(ContractId),
579 ContractId, 0, int.MaxValue);
580 }
581
588 public Task<string[]> GetContractTokenReferencesAsync(string Address, string ContractId)
589 {
590 return this.GetContractTokenReferencesAsync(Address, ContractId, 0, int.MaxValue);
591 }
592
600 public Task<string[]> GetContractTokenReferencesAsync(string ContractId, int Offset, int MaxCount)
601 {
602 return this.GetContractTokenReferencesAsync(this.contractsClient.GetTrustProvider(ContractId),
603 ContractId, Offset, MaxCount);
604 }
605
614 public async Task<string[]> GetContractTokenReferencesAsync(string Address, string ContractId, int Offset, int MaxCount)
615 {
616 TaskCompletionSource<string[]> Result = new TaskCompletionSource<string[]>();
617
618 await this.GetContractTokenReferences(Address, ContractId, Offset, MaxCount, (Sender, e) =>
619 {
620 if (e.Ok)
621 Result.TrySetResult(e.References);
622 else
623 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get token references."));
624
625 return Task.CompletedTask;
626
627 }, null);
628
629 return await Result.Task;
630 }
631
632 #endregion
633
634 #region Get Contract Tokens
635
642 public Task GetContractTokens(string ContractId, EventHandlerAsync<TokensEventArgs> Callback, object State)
643 {
644 return this.GetContractTokens(this.contractsClient.GetTrustProvider(ContractId),
645 ContractId, 0, int.MaxValue, Callback, State);
646 }
647
655 public Task GetContractTokens(string Address, string ContractId, EventHandlerAsync<TokensEventArgs> Callback, object State)
656 {
657 return this.GetContractTokens(Address, ContractId, 0, int.MaxValue, Callback, State);
658 }
659
668 public Task GetContractTokens(string ContractId, int Offset, int MaxCount, EventHandlerAsync<TokensEventArgs> Callback, object State)
669 {
670 return this.GetContractTokens(this.contractsClient.GetTrustProvider(ContractId),
671 ContractId, Offset, MaxCount, Callback, State);
672 }
673
683 public Task GetContractTokens(string Address, string ContractId, int Offset, int MaxCount, EventHandlerAsync<TokensEventArgs> Callback, object State)
684 {
685 if (Offset < 0)
686 throw new ArgumentException("Offsets cannot be negative.", nameof(Offset));
687
688 if (MaxCount <= 0)
689 throw new ArgumentException("Must be postitive.", nameof(MaxCount));
690
691 StringBuilder Xml = new StringBuilder();
692
693 Xml.Append("<contractTokens contractId='");
694 Xml.Append(XML.Encode(ContractId));
695 Xml.Append("' references='false' xmlns='");
696 Xml.Append(NamespaceNeuroFeatures);
697
698 if (Offset > 0)
699 {
700 Xml.Append("' offset='");
701 Xml.Append(Offset.ToString());
702 }
703
704 if (MaxCount < int.MaxValue)
705 {
706 Xml.Append("' maxCount='");
707 Xml.Append(MaxCount.ToString());
708 }
709
710 Xml.Append("'/>");
711
712 return this.client.SendIqGet(Address, Xml.ToString(), this.TokensResponse, new object[] { Callback, State });
713 }
714
720 public Task<TokensEventArgs> GetContractTokensAsync(string ContractId)
721 {
722 return this.GetContractTokensAsync(this.contractsClient.GetTrustProvider(ContractId),
723 ContractId, 0, int.MaxValue);
724 }
725
732 public Task<TokensEventArgs> GetContractTokensAsync(string Address, string ContractId)
733 {
734 return this.GetContractTokensAsync(Address, ContractId, 0, int.MaxValue);
735 }
736
744 public Task<TokensEventArgs> GetContractTokensAsync(string ContractId, int Offset, int MaxCount)
745 {
746 return this.GetContractTokensAsync(this.contractsClient.GetTrustProvider(ContractId),
747 ContractId, Offset, MaxCount);
748 }
749
758 public async Task<TokensEventArgs> GetContractTokensAsync(string Address, string ContractId, int Offset, int MaxCount)
759 {
760 TaskCompletionSource<TokensEventArgs> Result = new TaskCompletionSource<TokensEventArgs>();
761
762 await this.GetContractTokens(Address, ContractId, Offset, MaxCount, (Sender, e) =>
763 {
764 Result.TrySetResult(e);
765 return Task.CompletedTask;
766
767 }, null);
768
769 return await Result.Task;
770 }
771
772 #endregion
773
774 #region TokenAdded
775
776 private async Task TokenAddedHandler(object Sender, MessageEventArgs e)
777 {
778 Token TokenAdded;
779
780 foreach (XmlNode N in e.Content.ChildNodes)
781 {
782 if (N is XmlElement E &&
783 E.LocalName == "token" &&
784 E.NamespaceURI == NamespaceNeuroFeatures &&
785 !((TokenAdded = await Token.TryParse(E)) is null))
786 {
787 await this.TokenAdded.Raise(this, new TokenEventArgs(e, TokenAdded));
788 }
789 }
790 }
791
795 public event EventHandlerAsync<TokenEventArgs> TokenAdded;
796
797 #endregion
798
799 #region TokenRemoved
800
801 private async Task TokenRemovedHandler(object Sender, MessageEventArgs e)
802 {
803 Token TokenRemoved;
804
805 foreach (XmlNode N in e.Content.ChildNodes)
806 {
807 if (N is XmlElement E &&
808 E.LocalName == "token" &&
809 E.NamespaceURI == NamespaceNeuroFeatures &&
810 !((TokenRemoved = await Token.TryParse(E)) is null))
811 {
812 await this.TokenRemoved.Raise(this, new TokenEventArgs(e, TokenRemoved));
813 }
814 }
815 }
816
820 public event EventHandlerAsync<TokenEventArgs> TokenRemoved;
821
822 #endregion
823
824 #region Get Total
825
831 public Task GetTotals(EventHandlerAsync<TokenTotalsEventArgs> Callback, object State)
832 {
833 return this.GetTotals(this.componentAddress, Callback, State);
834 }
835
842 public Task GetTotals(string Address, EventHandlerAsync<TokenTotalsEventArgs> Callback, object State)
843 {
844 StringBuilder Xml = new StringBuilder();
845
846 Xml.Append("<totals xmlns='");
847 Xml.Append(NamespaceNeuroFeatures);
848 Xml.Append("'/>");
849
850 return this.client.SendIqGet(Address, Xml.ToString(), this.TotalsResponse, new object[] { Callback, State });
851 }
852
853 private async Task TotalsResponse(object Sender, IqResultEventArgs e)
854 {
855 object[] P = (object[])e.State;
856 EventHandlerAsync<TokenTotalsEventArgs> Callback = (EventHandlerAsync<TokenTotalsEventArgs>)P[0];
857 XmlElement E = e.FirstElement;
858 List<TokenTotal> Totals = new List<TokenTotal>();
859
860 if (e.Ok && !(E is null) && E.LocalName == "totals" && E.NamespaceURI == NamespaceNeuroFeatures)
861 {
862 foreach (XmlNode N in E.ChildNodes)
863 {
864 if (N is XmlElement E2 && E2.NamespaceURI == NamespaceNeuroFeatures && E2.LocalName == "total")
865 {
866 Totals.Add(new TokenTotal()
867 {
868 NrTokens = XML.Attribute(E2, "nr", 0),
869 Total = XML.Attribute(E2, "total", 0.0m),
870 Currency = XML.Attribute(E2, "currency")
871 });
872 }
873 }
874 }
875 else
876 e.Ok = false;
877
878 e.State = P[1];
879 await Callback.Raise(this, new TokenTotalsEventArgs(e, Totals.ToArray()));
880 }
881
886 public Task<TokenTotalsEventArgs> GetTotalsAsync()
887 {
888 return this.GetTotalsAsync(this.componentAddress);
889 }
890
896 public async Task<TokenTotalsEventArgs> GetTotalsAsync(string Address)
897 {
898 TaskCompletionSource<TokenTotalsEventArgs> Result = new TaskCompletionSource<TokenTotalsEventArgs>();
899
900 await this.GetTotals(Address, (Sender, e) =>
901 {
902 Result.TrySetResult(e);
903 return Task.CompletedTask;
904
905 }, null);
906
907 return await Result.Task;
908 }
909
910 #endregion
911
912 #region AddTextNote
913
921 public Task AddTextNote(string TokenId, string Note, EventHandlerAsync<IqResultEventArgs> Callback, object State)
922 {
923 return this.AddTextNote(TokenId, Note, false, Callback, State);
924 }
925
935 public Task AddTextNote(string TokenId, string Note, bool Personal, EventHandlerAsync<IqResultEventArgs> Callback, object State)
936 {
937 string Domain = this.GetDomain(TokenId);
938 StringBuilder Xml = new StringBuilder();
939
940 Xml.Append("<noteText xmlns='");
941 Xml.Append(NamespaceNeuroFeatures);
942 Xml.Append("' id='");
943 Xml.Append(XML.Encode(TokenId));
944 Xml.Append("' personal='");
945 Xml.Append(CommonTypes.Encode(Personal));
946 Xml.Append("'>");
947 Xml.Append(XML.Encode(Note));
948 Xml.Append("</noteText>");
949
950 return this.client.SendIqSet(Domain, Xml.ToString(), Callback, State);
951 }
952
958 public Task AddTextNoteAsync(string TokenId, string Note)
959 {
960 return this.AddTextNoteAsync(TokenId, Note, false);
961 }
962
970 public async Task AddTextNoteAsync(string TokenId, string Note, bool Personal)
971 {
972 TaskCompletionSource<bool> Result = new TaskCompletionSource<bool>();
973
974 await this.AddTextNote(TokenId, Note, Personal, (Sender, e) =>
975 {
976 if (e.Ok)
977 Result.TrySetResult(true);
978 else
979 Result.TrySetException(e.StanzaError ?? new Exception("Unable to add text note."));
980
981 return Task.CompletedTask;
982 }, null);
983
984 await Result.Task;
985 }
986
987 #endregion
988
989 #region AddXmlNote
990
998 public Task AddXmlNote(string TokenId, string Note, EventHandlerAsync<IqResultEventArgs> Callback, object State)
999 {
1000 return this.AddXmlNote(TokenId, Note, false, Callback, State);
1001 }
1002
1012 public Task AddXmlNote(string TokenId, string Note, bool Personal, EventHandlerAsync<IqResultEventArgs> Callback, object State)
1013 {
1014 if (!XML.IsValidXml(Note))
1015 throw new ArgumentException("Note is not valid XML.", nameof(Note));
1016
1017 string Domain = this.GetDomain(TokenId);
1018 StringBuilder Xml = new StringBuilder();
1019
1020 Xml.Append("<noteXml xmlns='");
1021 Xml.Append(NamespaceNeuroFeatures);
1022 Xml.Append("' id='");
1023 Xml.Append(XML.Encode(TokenId));
1024 Xml.Append("' personal='");
1025 Xml.Append(CommonTypes.Encode(Personal));
1026 Xml.Append("'>");
1027 Xml.Append(Note);
1028 Xml.Append("</noteXml>");
1029
1030 return this.client.SendIqSet(Domain, Xml.ToString(), Callback, State);
1031 }
1032
1038 public Task AddXmlNoteAsync(string TokenId, string Note)
1039 {
1040 return this.AddXmlNoteAsync(TokenId, Note, false);
1041 }
1042
1050 public async Task AddXmlNoteAsync(string TokenId, string Note, bool Personal)
1051 {
1052 TaskCompletionSource<bool> Result = new TaskCompletionSource<bool>();
1053
1054 await this.AddXmlNote(TokenId, Note, Personal, (Sender, e) =>
1055 {
1056 if (e.Ok)
1057 Result.TrySetResult(true);
1058 else
1059 Result.TrySetException(e.StanzaError ?? new Exception("Unable to add xml note."));
1060
1061 return Task.CompletedTask;
1062 }, null);
1063
1064 await Result.Task;
1065 }
1066
1067 #endregion
1068
1069 #region GetEvents
1070
1077 public Task GetEvents(string TokenId, EventHandlerAsync<EventsEventArgs> Callback, object State)
1078 {
1079 return this.GetEvents(TokenId, 0, int.MaxValue, Callback, State);
1080 }
1081
1090 public Task GetEvents(string TokenId, int Offset, int MaxCount, EventHandlerAsync<EventsEventArgs> Callback, object State)
1091 {
1092 if (Offset < 0)
1093 throw new ArgumentException("Offsets cannot be negative.", nameof(Offset));
1094
1095 if (MaxCount <= 0)
1096 throw new ArgumentException("Must be postitive.", nameof(MaxCount));
1097
1098 StringBuilder Xml = new StringBuilder();
1099
1100 Xml.Append("<events xmlns='");
1101 Xml.Append(NamespaceNeuroFeatures);
1102 Xml.Append("' id='");
1103 Xml.Append(XML.Encode(TokenId));
1104
1105 if (Offset > 0)
1106 {
1107 Xml.Append("' offset='");
1108 Xml.Append(Offset.ToString());
1109 }
1110
1111 if (MaxCount < int.MaxValue)
1112 {
1113 Xml.Append("' maxCount='");
1114 Xml.Append(MaxCount.ToString());
1115 }
1116
1117 Xml.Append("'/>");
1118
1119 return this.client.SendIqGet(this.GetDomain(TokenId), Xml.ToString(), async (Sender, e) =>
1120 {
1121 XmlElement E = e.FirstElement;
1122 List<TokenEvent> Events = new List<TokenEvent>();
1123
1124 if (e.Ok && !(E is null))
1125 {
1126 foreach (XmlNode N in E.ChildNodes)
1127 {
1128 if (N is XmlElement E2 && E2.NamespaceURI == NamespaceNeuroFeatures)
1129 {
1130 if (TokenEvent.TryParse(E2, out TokenEvent Event))
1131 Events.Add(Event);
1132 }
1133 }
1134 }
1135 else
1136 e.Ok = false;
1137
1138 e.State = State;
1139 await Callback.Raise(this, new EventsEventArgs(e, Events.ToArray()));
1140
1141 }, null);
1142 }
1143
1148 public Task<TokenEvent[]> GetEventsAsync(string TokenId)
1149 {
1150 return this.GetEventsAsync(TokenId, 0, int.MaxValue);
1151 }
1152
1159 public async Task<TokenEvent[]> GetEventsAsync(string TokenId, int Offset, int MaxCount)
1160 {
1161 TaskCompletionSource<TokenEvent[]> Result = new TaskCompletionSource<TokenEvent[]>();
1162
1163 await this.GetEvents(TokenId, Offset, MaxCount, (Sender, e) =>
1164 {
1165 if (e.Ok)
1166 Result.TrySetResult(e.Events);
1167 else
1168 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get token events."));
1169
1170 return Task.CompletedTask;
1171 }, null);
1172
1173 return await Result.Task;
1174 }
1175
1176 #endregion
1177
1178 #region GetCreationAttributes
1179
1185 public Task GetCreationAttributes(EventHandlerAsync<CreationAttributesEventArgs> Callback, object State)
1186 {
1187 return this.client.SendIqGet(this.componentAddress, "<creationAttributes xmlns='" + NamespaceNeuroFeatures + "'/>", (Sender, e) =>
1188 {
1189 return Callback.Raise(this, new CreationAttributesEventArgs(e));
1190 }, State);
1191 }
1192
1197 public async Task<CreationAttributesEventArgs> GetCreationAttributesAsync()
1198 {
1199 TaskCompletionSource<CreationAttributesEventArgs> Result = new TaskCompletionSource<CreationAttributesEventArgs>();
1200
1201 await this.GetCreationAttributes((Sender, e) =>
1202 {
1203 if (e.Ok)
1204 Result.TrySetResult(e);
1205 else
1206 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get creation attributes."));
1207
1208 return Task.CompletedTask;
1209 }, null);
1210
1211 return await Result.Task;
1212 }
1213
1214 #endregion
1215
1216 #region GenerateDescription
1217
1225 public Task GenerateDescription(string TokenId, ReportFormat Format,
1226 EventHandlerAsync<ReportEventArgs> Callback, object State)
1227 {
1228 string Domain = this.GetDomain(TokenId);
1229 StringBuilder Xml = new StringBuilder();
1230
1231 Xml.Append("<description xmlns='");
1232 Xml.Append(NamespaceNeuroFeatures);
1233 Xml.Append("' id='");
1234 Xml.Append(XML.Encode(TokenId));
1235 Xml.Append("' format='");
1236 Xml.Append(Format.ToString());
1237 Xml.Append("'/>");
1238
1239 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) => this.ReportResponse(e, Callback), State);
1240 }
1241
1242 private async Task ReportResponse(IqResultEventArgs e, EventHandlerAsync<ReportEventArgs> Callback)
1243 {
1244 try
1245 {
1246 string ReportText = null;
1247
1248 if (e.Ok && e.FirstElement.LocalName == "report" &&
1249 (e.FirstElement.NamespaceURI == NamespaceStateMachine ||
1250 e.FirstElement.NamespaceURI == NamespaceNeuroFeatures))
1251 {
1252 ReportText = e.FirstElement.InnerText;
1253 }
1254 else
1255 e.Ok = false;
1256
1257 await Callback.Raise(this, new ReportEventArgs(ReportText, e));
1258 }
1259 catch (Exception ex)
1260 {
1261 this.client.Exception(ex);
1262 Log.Exception(ex);
1263 }
1264 }
1265
1271 public async Task<ReportEventArgs> GenerateDescriptionAsync(string TokenId, ReportFormat Format)
1272 {
1273 TaskCompletionSource<ReportEventArgs> Result = new TaskCompletionSource<ReportEventArgs>();
1274
1275 await this.GenerateDescription(TokenId, Format, (Sender, e) =>
1276 {
1277 if (e.Ok)
1278 Result.TrySetResult(e);
1279 else
1280 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get the description of the token."));
1281
1282 return Task.CompletedTask;
1283 }, null);
1284
1285 return await Result.Task;
1286 }
1287
1288 #endregion
1289
1290 #endregion
1291
1292 #region State-Machines
1293
1294 #region GetCurrentState
1295
1302 public Task GetCurrentState(string TokenId, EventHandlerAsync<CurrentStateEventArgs> Callback, object State)
1303 {
1304 string Domain = this.GetDomain(TokenId);
1305 StringBuilder Xml = new StringBuilder();
1306
1307 Xml.Append("<currentState xmlns='");
1308 Xml.Append(NamespaceStateMachine);
1309 Xml.Append("' tokenId='");
1310 Xml.Append(XML.Encode(TokenId));
1311 Xml.Append("'/>");
1312
1313 return this.client.SendIqGet(Domain, Xml.ToString(), async (Sender, e) =>
1314 {
1315 try
1316 {
1317 string CurrentState = null;
1318 bool Ended = false;
1319 bool Running = false;
1320 DateTime Expires = DateTime.MinValue;
1321 Variables Variables = null;
1322
1323 if (e.Ok && e.FirstElement.LocalName == "currentState" && e.FirstElement.NamespaceURI == NamespaceStateMachine)
1324 {
1325 CurrentState = XML.Attribute(e.FirstElement, "state");
1326 Ended = XML.Attribute(e.FirstElement, "ended", false);
1327 Running = XML.Attribute(e.FirstElement, "running", false);
1328 Expires = XML.Attribute(e.FirstElement, "expires", DateTime.MaxValue);
1329 Variables = await ParseVariables(e.FirstElement);
1330 }
1331 else
1332 e.Ok = false;
1333
1334 await Callback.Raise(this, new CurrentStateEventArgs(CurrentState, Ended, Running,
1335 Expires, Variables, e));
1336 }
1337 catch (Exception ex)
1338 {
1339 this.client.Exception(ex);
1340 Log.Exception(ex);
1341 }
1342 }, State);
1343 }
1344
1345 private async static Task<Variables> ParseVariables(XmlElement VariablesDefinition)
1346 {
1348
1349 foreach (XmlNode N in VariablesDefinition.ChildNodes)
1350 {
1351 if (N is XmlElement E &&
1352 E.LocalName == "variable" &&
1353 E.NamespaceURI == NamespaceStateMachine)
1354 {
1355 string Name = XML.Attribute(E, "name");
1356 object Value = await ParseVariable(E, Variables);
1357
1358 Variables[Name] = Value;
1359 }
1360 }
1361
1362 return Variables;
1363 }
1364
1365 private async static Task<object> ParseVariable(XmlElement VariableDefinition, Variables Variables)
1366 {
1367 object Value = null;
1368
1369 foreach (XmlNode N2 in VariableDefinition.ChildNodes)
1370 {
1371 if (!(N2 is XmlElement E2))
1372 continue;
1373
1374 switch (E2.LocalName)
1375 {
1376 case "null":
1377 Value = null;
1378 break;
1379
1380 case "dbl":
1381 if (CommonTypes.TryParse(E2.InnerText, out double dbl))
1382 Value = dbl;
1383 break;
1384
1385 case "fl":
1386 if (CommonTypes.TryParse(E2.InnerText, out float fl))
1387 Value = fl;
1388 break;
1389
1390 case "dec":
1391 if (CommonTypes.TryParse(E2.InnerText, out decimal dec))
1392 Value = dec;
1393 break;
1394
1395 case "i8":
1396 if (sbyte.TryParse(E2.InnerText, out sbyte i8))
1397 Value = i8;
1398 break;
1399
1400 case "i16":
1401 if (short.TryParse(E2.InnerText, out short i16))
1402 Value = i16;
1403 break;
1404
1405 case "i32":
1406 if (int.TryParse(E2.InnerText, out int i32))
1407 Value = i32;
1408 break;
1409
1410 case "i64":
1411 if (long.TryParse(E2.InnerText, out long i64))
1412 Value = i64;
1413 break;
1414
1415 case "ui8":
1416 if (byte.TryParse(E2.InnerText, out byte ui8))
1417 Value = ui8;
1418 break;
1419
1420 case "ui16":
1421 if (ushort.TryParse(E2.InnerText, out ushort ui16))
1422 Value = ui16;
1423 break;
1424
1425 case "ui32":
1426 if (uint.TryParse(E2.InnerText, out uint ui32))
1427 Value = ui32;
1428 break;
1429
1430 case "ui64":
1431 if (ulong.TryParse(E2.InnerText, out ulong ui64))
1432 Value = ui64;
1433 break;
1434
1435 case "b":
1436 if (CommonTypes.TryParse(E2.InnerText, out bool b))
1437 Value = b;
1438 break;
1439
1440 case "dt":
1441 if (XML.TryParse(E2.InnerText, out DateTime TP))
1442 Value = TP;
1443 break;
1444
1445 case "dto":
1446 if (XML.TryParse(E2.InnerText, out DateTimeOffset TPO))
1447 Value = TPO;
1448 break;
1449
1450 case "ts":
1451 if (TimeSpan.TryParse(E2.InnerText, out TimeSpan TS))
1452 Value = TS;
1453 break;
1454
1455 case "d":
1456 if (Duration.TryParse(E2.InnerText, out Duration D))
1457 Value = D;
1458 break;
1459
1460 case "s":
1461 Value = E2.InnerText;
1462 break;
1463
1464 case "exp":
1465 try
1466 {
1467 Expression Exp = new Expression(E2.InnerText);
1468 Value = await Exp.EvaluateAsync(Variables);
1469 }
1470 catch (Exception)
1471 {
1472 Value = E2.InnerText;
1473 }
1474 break;
1475 }
1476 }
1477
1478 return Value;
1479 }
1480
1485 public async Task<CurrentStateEventArgs> GetCurrentStateAsync(string TokenId)
1486 {
1487 TaskCompletionSource<CurrentStateEventArgs> Result = new TaskCompletionSource<CurrentStateEventArgs>();
1488
1489 await this.GetCurrentState(TokenId, (Sender, e) =>
1490 {
1491 if (e.Ok)
1492 Result.TrySetResult(e);
1493 else
1494 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get current state of state-machine."));
1495
1496 return Task.CompletedTask;
1497 }, null);
1498
1499 return await Result.Task;
1500 }
1501
1502 #endregion
1503
1504 #region GenerateProfilingReport
1505
1513 public Task GenerateProfilingReport(string TokenId, ReportFormat Format,
1514 EventHandlerAsync<ReportEventArgs> Callback, object State)
1515 {
1516 string Domain = this.GetDomain(TokenId);
1517 StringBuilder Xml = new StringBuilder();
1518
1519 Xml.Append("<profilingReport xmlns='");
1520 Xml.Append(NamespaceStateMachine);
1521 Xml.Append("' tokenId='");
1522 Xml.Append(XML.Encode(TokenId));
1523 Xml.Append("' format='");
1524 Xml.Append(Format.ToString());
1525 Xml.Append("'/>");
1526
1527 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) => this.ReportResponse(e, Callback), State);
1528 }
1529
1535 public async Task<ReportEventArgs> GenerateProfilingReportAsync(string TokenId, ReportFormat Format)
1536 {
1537 TaskCompletionSource<ReportEventArgs> Result = new TaskCompletionSource<ReportEventArgs>();
1538
1539 await this.GenerateProfilingReport(TokenId, Format, (Sender, e) =>
1540 {
1541 if (e.Ok)
1542 Result.TrySetResult(e);
1543 else
1544 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get the profiling report of the state-machine."));
1545
1546 return Task.CompletedTask;
1547 }, null);
1548
1549 return await Result.Task;
1550 }
1551
1552 #endregion
1553
1554 #region GeneratePresentReport
1555
1563 public Task GeneratePresentReport(string TokenId, ReportFormat Format,
1564 EventHandlerAsync<ReportEventArgs> Callback, object State)
1565 {
1566 string Domain = this.GetDomain(TokenId);
1567 StringBuilder Xml = new StringBuilder();
1568
1569 Xml.Append("<presentReport xmlns='");
1570 Xml.Append(NamespaceStateMachine);
1571 Xml.Append("' tokenId='");
1572 Xml.Append(XML.Encode(TokenId));
1573 Xml.Append("' format='");
1574 Xml.Append(Format.ToString());
1575 Xml.Append("'/>");
1576
1577 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) => this.ReportResponse(e, Callback), State);
1578 }
1579
1585 public async Task<ReportEventArgs> GeneratePresentReportAsync(string TokenId, ReportFormat Format)
1586 {
1587 TaskCompletionSource<ReportEventArgs> Result = new TaskCompletionSource<ReportEventArgs>();
1588
1589 await this.GeneratePresentReport(TokenId, Format, (Sender, e) =>
1590 {
1591 if (e.Ok)
1592 Result.TrySetResult(e);
1593 else
1594 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get the profiling report of the state-machine."));
1595
1596 return Task.CompletedTask;
1597 }, null);
1598
1599 return await Result.Task;
1600 }
1601
1602 #endregion
1603
1604 #region GenerateHistoryReport
1605
1613 public Task GenerateHistoryReport(string TokenId, ReportFormat Format,
1614 EventHandlerAsync<ReportEventArgs> Callback, object State)
1615 {
1616 string Domain = this.GetDomain(TokenId);
1617 StringBuilder Xml = new StringBuilder();
1618
1619 Xml.Append("<historyReport xmlns='");
1620 Xml.Append(NamespaceStateMachine);
1621 Xml.Append("' tokenId='");
1622 Xml.Append(XML.Encode(TokenId));
1623 Xml.Append("' format='");
1624 Xml.Append(Format.ToString());
1625 Xml.Append("'/>");
1626
1627 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) => this.ReportResponse(e, Callback), State);
1628 }
1629
1635 public async Task<ReportEventArgs> GenerateHistoryReportAsync(string TokenId, ReportFormat Format)
1636 {
1637 TaskCompletionSource<ReportEventArgs> Result = new TaskCompletionSource<ReportEventArgs>();
1638
1639 await this.GenerateHistoryReport(TokenId, Format, (Sender, e) =>
1640 {
1641 if (e.Ok)
1642 Result.TrySetResult(e);
1643 else
1644 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get the profiling report of the state-machine."));
1645
1646 return Task.CompletedTask;
1647 }, null);
1648
1649 return await Result.Task;
1650 }
1651
1652 #endregion
1653
1654 #region GenerateStateDiagram
1655
1663 public Task GenerateStateDiagram(string TokenId, ReportFormat Format,
1664 EventHandlerAsync<ReportEventArgs> Callback, object State)
1665 {
1666 string Domain = this.GetDomain(TokenId);
1667 StringBuilder Xml = new StringBuilder();
1668
1669 Xml.Append("<stateDiagram xmlns='");
1670 Xml.Append(NamespaceStateMachine);
1671 Xml.Append("' tokenId='");
1672 Xml.Append(XML.Encode(TokenId));
1673 Xml.Append("' format='");
1674 Xml.Append(Format.ToString());
1675 Xml.Append("'/>");
1676
1677 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) => this.ReportResponse(e, Callback), State);
1678 }
1679
1685 public async Task<ReportEventArgs> GenerateStateDiagramAsync(string TokenId, ReportFormat Format)
1686 {
1687 TaskCompletionSource<ReportEventArgs> Result = new TaskCompletionSource<ReportEventArgs>();
1688
1689 await this.GenerateStateDiagram(TokenId, Format, (Sender, e) =>
1690 {
1691 if (e.Ok)
1692 Result.TrySetResult(e);
1693 else
1694 Result.TrySetException(e.StanzaError ?? new Exception("Unable to get the state diagram of the state-machine."));
1695
1696 return Task.CompletedTask;
1697 }, null);
1698
1699 return await Result.Task;
1700 }
1701
1702 #endregion
1703
1704 #region StateUpdated
1705
1706 private Task StateUpdatedHandler(object Sender, MessageEventArgs e)
1707 {
1708 string TokenId = XML.Attribute(e.Content, "tokenId");
1709 string MachineId = XML.Attribute(e.Content, "machineId");
1710 string NewState = XML.Attribute(e.Content, "state");
1711
1712 return this.StateUpdated.Raise(this, new NewStateEventArgs(TokenId, MachineId, NewState, e));
1713 }
1714
1718 public event EventHandlerAsync<NewStateEventArgs> StateUpdated;
1719
1720 #endregion
1721
1722 #region VariablesUpdated
1723
1724 private async Task VariablesUpdatedHandler(object Sender, MessageEventArgs e)
1725 {
1726 string TokenId = XML.Attribute(e.Content, "tokenId");
1727 string MachineId = XML.Attribute(e.Content, "machineId");
1728 Variables Variables = await ParseVariables(e.Content);
1729
1730 await this.VariablesUpdated.Raise(this, new VariablesUpdatedEventArgs(TokenId, MachineId, Variables, e));
1731 }
1732
1736 public event EventHandlerAsync<VariablesUpdatedEventArgs> VariablesUpdated;
1737
1738 #endregion
1739
1740 #endregion
1741 }
1742}
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:12
static bool TryParse(XmlElement Xml, out TokenEvent Event)
Tries to parse a token event from its XML definition.
Definition: TokenEvent.cs:99
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:46
static async Task< Token > TryParse(XmlElement Xml)
Tries to parse a Token.
Definition: Token.cs:555
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:15
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:596
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Definition: CommonTypes.cs:48
Helps with common XML-related tasks.
Definition: XML.cs:21
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Definition: XML.cs:1062
static string Encode(string s)
Encodes a string for use in XML.
Definition: XML.cs:29
static bool TryParse(string s, out DateTime Value)
Tries to decode a string encoded DateTime.
Definition: XML.cs:892
static bool IsValidXml(string Xml)
Checks if a string is valid XML
Definition: XML.cs:1397
Class representing an event.
Definition: Event.cs:11
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:14
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:1657
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:58
bool UnregisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool RemoveNamespaceAsClientFeature)
Unregisters a Message handler.
Definition: XmppClient.cs:2884
void RegisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool PublishNamespaceAsClientFeature)
Registers a Message handler.
Definition: XmppClient.cs:2852
Task< uint > SendIqGet(string To, string Xml, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends an IQ Get request.
Definition: XmppClient.cs:3598
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:41
async Task< object > EvaluateAsync(Variables Variables)
Evaluates the expression, using the variables provided in the Variables collection....
Definition: Expression.cs:4461
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:14
static bool TryParse(string s, out Duration Result)
Tries to parse a duration value.
Definition: Duration.cs:86