4using System.Collections.Generic;
6using System.Threading.Tasks;
41 private readonly
string componentAddress;
105 public Task
GetToken(
string TokenId, EventHandlerAsync<TokenResultEventArgs> Callback,
object State)
107 string Domain = this.GetDomain(TokenId);
108 StringBuilder Xml =
new StringBuilder();
110 Xml.Append(
"<token id='");
112 Xml.Append(
"' xmlns='");
116 return this.
client.
SendIqGet(Domain, Xml.ToString(), async (Sender, e) =>
118 Token ResultToken =
null;
122 if (e.FirstElement is null || e.FirstElement.LocalName !=
"token" || e.FirstElement.NamespaceURI != NamespaceNeuroFeatures)
125 await this.client.Error(
"Unexpected response.");
130 await this.client.Error(
"Unable to parse token.");
135 await Callback.Raise(
this, e2);
139 private string GetDomain(
string TokenId)
141 int i = TokenId.IndexOf(
'@');
144 return this.componentAddress;
146 return TokenId.Substring(i + 1);
155 TaskCompletionSource<Token> Result =
new TaskCompletionSource<Token>();
157 await this.GetToken(TokenId, (Sender, e) =>
160 Result.TrySetResult(e.Token);
162 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to get token."));
164 return Task.CompletedTask;
167 return await Result.Task;
172 #region Get Token References
181 return this.GetTokenReferences(this.componentAddress, 0,
int.MaxValue, Callback, State);
190 public Task
GetTokenReferences(
string Address, EventHandlerAsync<IdReferencesEventArgs> Callback,
object State)
192 return this.GetTokenReferences(Address, 0,
int.MaxValue, Callback, State);
202 public Task
GetTokenReferences(
int Offset,
int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback,
object State)
204 return this.GetTokenReferences(this.componentAddress, Offset, MaxCount, Callback, State);
215 public Task
GetTokenReferences(
string Address,
int Offset,
int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback,
object State)
218 throw new ArgumentException(
"Offsets cannot be negative.", nameof(Offset));
221 throw new ArgumentException(
"Must be postitive.", nameof(MaxCount));
223 StringBuilder Xml =
new StringBuilder();
225 Xml.Append(
"<tokens references='true' xmlns='");
226 Xml.Append(NamespaceNeuroFeatures);
230 Xml.Append(
"' offset='");
231 Xml.Append(Offset.ToString());
234 if (MaxCount <
int.MaxValue)
236 Xml.Append(
"' maxCount='");
237 Xml.Append(MaxCount.ToString());
242 return this.client.SendIqGet(Address, Xml.ToString(),
this.TokenReferencesResponse,
new object[] { Callback, State });
247 object[] P = (
object[])e.
State;
248 EventHandlerAsync<IdReferencesEventArgs> Callback = (EventHandlerAsync<IdReferencesEventArgs>)P[0];
250 List<string> IDs =
new List<string>();
252 if (e.
Ok && !(E is
null))
254 foreach (XmlNode N
in E.ChildNodes)
256 if (N is XmlElement E2 && E2.LocalName ==
"ref" && E2.NamespaceURI == NamespaceNeuroFeatures)
276 return this.GetTokenReferencesAsync(this.componentAddress, 0,
int.MaxValue);
286 return this.GetTokenReferencesAsync(Address, 0,
int.MaxValue);
297 return this.GetTokenReferencesAsync(this.componentAddress, Offset, MaxCount);
309 TaskCompletionSource<string[]> Result =
new TaskCompletionSource<string[]>();
311 await this.GetTokenReferences(Address, Offset, MaxCount, (Sender, e) =>
314 Result.TrySetResult(e.References);
316 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get token references."));
318 return Task.CompletedTask;
322 return await Result.Task;
334 public Task
GetTokens(EventHandlerAsync<TokensEventArgs> Callback,
object State)
336 return this.GetTokens(this.componentAddress, 0,
int.MaxValue, Callback, State);
345 public Task
GetTokens(
string Address, EventHandlerAsync<TokensEventArgs> Callback,
object State)
347 return this.GetTokens(Address, 0,
int.MaxValue, Callback, State);
357 public Task
GetTokens(
int Offset,
int MaxCount, EventHandlerAsync<TokensEventArgs> Callback,
object State)
359 return this.GetTokens(this.componentAddress, Offset, MaxCount, Callback, State);
370 public Task
GetTokens(
string Address,
int Offset,
int MaxCount, EventHandlerAsync<TokensEventArgs> Callback,
object State)
373 throw new ArgumentException(
"Offsets cannot be negative.", nameof(Offset));
376 throw new ArgumentException(
"Must be postitive.", nameof(MaxCount));
378 StringBuilder Xml =
new StringBuilder();
380 Xml.Append(
"<tokens references='false' xmlns='");
381 Xml.Append(NamespaceNeuroFeatures);
385 Xml.Append(
"' offset='");
386 Xml.Append(Offset.ToString());
389 if (MaxCount <
int.MaxValue)
391 Xml.Append(
"' maxCount='");
392 Xml.Append(MaxCount.ToString());
397 return this.client.SendIqGet(Address, Xml.ToString(),
this.TokensResponse,
new object[] { Callback, State });
402 object[] P = (
object[])e.
State;
403 EventHandlerAsync<TokensEventArgs> Callback = (EventHandlerAsync<TokensEventArgs>)P[0];
405 List<Token> Tokens =
new List<Token>();
406 List<string> References =
new List<string>();
408 if (e.
Ok && !(E is
null))
410 foreach (XmlNode N
in E.ChildNodes)
412 if (N is XmlElement E2 && E2.NamespaceURI == NamespaceNeuroFeatures)
414 switch (E2.LocalName)
418 Tokens.Add(ParsedToken);
423 References.Add(TokenId);
433 await Callback.Raise(
this,
new TokensEventArgs(e, Tokens.ToArray(), References.ToArray()));
442 return this.GetTokensAsync(this.componentAddress, 0,
int.MaxValue);
452 return this.GetTokensAsync(Address, 0,
int.MaxValue);
463 return this.GetTokensAsync(this.componentAddress, Offset, MaxCount);
473 public async Task<TokensEventArgs>
GetTokensAsync(
string Address,
int Offset,
int MaxCount)
475 TaskCompletionSource<TokensEventArgs> Result =
new TaskCompletionSource<TokensEventArgs>();
477 await this.GetTokens(Address, Offset, MaxCount, (Sender, e) =>
479 Result.TrySetResult(e);
480 return Task.CompletedTask;
484 return await Result.Task;
489 #region Get Contract Token References
499 return this.GetContractTokenReferences(this.contractsClient.GetTrustProvider(ContractId),
500 ContractId, 0,
int.MaxValue, Callback, State);
512 return this.GetContractTokenReferences(Address, ContractId, 0,
int.MaxValue, Callback, State);
523 public Task
GetContractTokenReferences(
string ContractId,
int Offset,
int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback,
object State)
525 return this.GetContractTokenReferences(this.contractsClient.GetTrustProvider(ContractId),
526 ContractId, Offset, MaxCount, Callback, State);
538 public Task
GetContractTokenReferences(
string Address,
string ContractId,
int Offset,
int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback,
object State)
541 throw new ArgumentException(
"Offsets cannot be negative.", nameof(Offset));
544 throw new ArgumentException(
"Must be postitive.", nameof(MaxCount));
546 StringBuilder Xml =
new StringBuilder();
548 Xml.Append(
"<contractTokens contractId='");
550 Xml.Append(
"' references='true' xmlns='");
551 Xml.Append(NamespaceNeuroFeatures);
555 Xml.Append(
"' offset='");
556 Xml.Append(Offset.ToString());
559 if (MaxCount <
int.MaxValue)
561 Xml.Append(
"' maxCount='");
562 Xml.Append(MaxCount.ToString());
567 return this.client.SendIqGet(Address, Xml.ToString(),
this.TokenReferencesResponse,
new object[] { Callback, State });
577 return this.GetContractTokenReferencesAsync(this.contractsClient.GetTrustProvider(ContractId),
578 ContractId, 0,
int.MaxValue);
589 return this.GetContractTokenReferencesAsync(Address, ContractId, 0,
int.MaxValue);
601 return this.GetContractTokenReferencesAsync(this.contractsClient.GetTrustProvider(ContractId),
602 ContractId, Offset, MaxCount);
615 TaskCompletionSource<string[]> Result =
new TaskCompletionSource<string[]>();
617 await this.GetContractTokenReferences(Address, ContractId, Offset, MaxCount, (Sender, e) =>
620 Result.TrySetResult(e.References);
622 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get token references."));
624 return Task.CompletedTask;
628 return await Result.Task;
633 #region Get Contract Tokens
641 public Task
GetContractTokens(
string ContractId, EventHandlerAsync<TokensEventArgs> Callback,
object State)
643 return this.GetContractTokens(this.contractsClient.GetTrustProvider(ContractId),
644 ContractId, 0,
int.MaxValue, Callback, State);
654 public Task
GetContractTokens(
string Address,
string ContractId, EventHandlerAsync<TokensEventArgs> Callback,
object State)
656 return this.GetContractTokens(Address, ContractId, 0,
int.MaxValue, Callback, State);
667 public Task
GetContractTokens(
string ContractId,
int Offset,
int MaxCount, EventHandlerAsync<TokensEventArgs> Callback,
object State)
669 return this.GetContractTokens(this.contractsClient.GetTrustProvider(ContractId),
670 ContractId, Offset, MaxCount, Callback, State);
682 public Task
GetContractTokens(
string Address,
string ContractId,
int Offset,
int MaxCount, EventHandlerAsync<TokensEventArgs> Callback,
object State)
685 throw new ArgumentException(
"Offsets cannot be negative.", nameof(Offset));
688 throw new ArgumentException(
"Must be postitive.", nameof(MaxCount));
690 StringBuilder Xml =
new StringBuilder();
692 Xml.Append(
"<contractTokens contractId='");
694 Xml.Append(
"' references='false' xmlns='");
695 Xml.Append(NamespaceNeuroFeatures);
699 Xml.Append(
"' offset='");
700 Xml.Append(Offset.ToString());
703 if (MaxCount <
int.MaxValue)
705 Xml.Append(
"' maxCount='");
706 Xml.Append(MaxCount.ToString());
711 return this.client.SendIqGet(Address, Xml.ToString(),
this.TokensResponse,
new object[] { Callback, State });
721 return this.GetContractTokensAsync(this.contractsClient.GetTrustProvider(ContractId),
722 ContractId, 0,
int.MaxValue);
733 return this.GetContractTokensAsync(Address, ContractId, 0,
int.MaxValue);
745 return this.GetContractTokensAsync(this.contractsClient.GetTrustProvider(ContractId),
746 ContractId, Offset, MaxCount);
759 TaskCompletionSource<TokensEventArgs> Result =
new TaskCompletionSource<TokensEventArgs>();
761 await this.GetContractTokens(Address, ContractId, Offset, MaxCount, (Sender, e) =>
763 Result.TrySetResult(e);
764 return Task.CompletedTask;
768 return await Result.Task;
777 foreach (XmlNode N
in e.
Content.ChildNodes)
779 if (N is XmlElement E &&
780 E.LocalName ==
"token" &&
781 E.NamespaceURI == NamespaceNeuroFeatures &&
784 await this.TokenAdded.Raise(
this,
new TokenEventArgs(e, TokenAdded));
800 foreach (XmlNode N
in e.
Content.ChildNodes)
802 if (N is XmlElement E &&
803 E.LocalName ==
"token" &&
804 E.NamespaceURI == NamespaceNeuroFeatures &&
807 await this.TokenRemoved.Raise(
this,
new TokenEventArgs(e, TokenRemoved));
826 public Task
GetTotals(EventHandlerAsync<TokenTotalsEventArgs> Callback,
object State)
828 return this.GetTotals(this.componentAddress, Callback, State);
837 public Task
GetTotals(
string Address, EventHandlerAsync<TokenTotalsEventArgs> Callback,
object State)
839 StringBuilder Xml =
new StringBuilder();
841 Xml.Append(
"<totals xmlns='");
842 Xml.Append(NamespaceNeuroFeatures);
845 return this.client.SendIqGet(Address, Xml.ToString(),
this.TotalsResponse,
new object[] { Callback, State });
850 object[] P = (
object[])e.
State;
851 EventHandlerAsync<TokenTotalsEventArgs> Callback = (EventHandlerAsync<TokenTotalsEventArgs>)P[0];
853 List<TokenTotal> Totals =
new List<TokenTotal>();
855 if (e.
Ok && !(E is
null) && E.LocalName ==
"totals" && E.NamespaceURI == NamespaceNeuroFeatures)
857 foreach (XmlNode N
in E.ChildNodes)
859 if (N is XmlElement E2 && E2.NamespaceURI == NamespaceNeuroFeatures && E2.LocalName ==
"total")
883 return this.GetTotalsAsync(this.componentAddress);
893 TaskCompletionSource<TokenTotalsEventArgs> Result =
new TaskCompletionSource<TokenTotalsEventArgs>();
895 await this.GetTotals(Address, (Sender, e) =>
897 Result.TrySetResult(e);
898 return Task.CompletedTask;
902 return await Result.Task;
916 public Task
AddTextNote(
string TokenId,
string Note, EventHandlerAsync<IqResultEventArgs> Callback,
object State)
918 return this.AddTextNote(TokenId, Note,
false, Callback, State);
930 public Task
AddTextNote(
string TokenId,
string Note,
bool Personal, EventHandlerAsync<IqResultEventArgs> Callback,
object State)
932 string Domain = this.GetDomain(TokenId);
933 StringBuilder Xml =
new StringBuilder();
935 Xml.Append(
"<noteText xmlns='");
936 Xml.Append(NamespaceNeuroFeatures);
937 Xml.Append(
"' id='");
939 Xml.Append(
"' personal='");
943 Xml.Append(
"</noteText>");
945 return this.client.SendIqSet(Domain, Xml.ToString(), Callback, State);
955 return this.AddTextNoteAsync(TokenId, Note,
false);
967 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
969 await this.AddTextNote(TokenId, Note, Personal, (Sender, e) =>
972 Result.TrySetResult(
true);
974 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to add text note."));
976 return Task.CompletedTask;
993 public Task
AddXmlNote(
string TokenId,
string Note, EventHandlerAsync<IqResultEventArgs> Callback,
object State)
995 return this.AddXmlNote(TokenId, Note,
false, Callback, State);
1007 public Task
AddXmlNote(
string TokenId,
string Note,
bool Personal, EventHandlerAsync<IqResultEventArgs> Callback,
object State)
1010 throw new ArgumentException(
"Note is not valid XML.", nameof(Note));
1012 string Domain = this.GetDomain(TokenId);
1013 StringBuilder Xml =
new StringBuilder();
1015 Xml.Append(
"<noteXml xmlns='");
1016 Xml.Append(NamespaceNeuroFeatures);
1017 Xml.Append(
"' id='");
1019 Xml.Append(
"' personal='");
1023 Xml.Append(
"</noteXml>");
1025 return this.client.SendIqSet(Domain, Xml.ToString(), Callback, State);
1035 return this.AddXmlNoteAsync(TokenId, Note,
false);
1047 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
1049 await this.AddXmlNote(TokenId, Note, Personal, (Sender, e) =>
1052 Result.TrySetResult(
true);
1054 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to add xml note."));
1056 return Task.CompletedTask;
1072 public Task
GetEvents(
string TokenId, EventHandlerAsync<EventsEventArgs> Callback,
object State)
1074 return this.GetEvents(TokenId, 0,
int.MaxValue, Callback, State);
1085 public Task
GetEvents(
string TokenId,
int Offset,
int MaxCount, EventHandlerAsync<EventsEventArgs> Callback,
object State)
1088 throw new ArgumentException(
"Offsets cannot be negative.", nameof(Offset));
1091 throw new ArgumentException(
"Must be postitive.", nameof(MaxCount));
1093 StringBuilder Xml =
new StringBuilder();
1095 Xml.Append(
"<events xmlns='");
1096 Xml.Append(NamespaceNeuroFeatures);
1097 Xml.Append(
"' id='");
1102 Xml.Append(
"' offset='");
1103 Xml.Append(Offset.ToString());
1106 if (MaxCount <
int.MaxValue)
1108 Xml.Append(
"' maxCount='");
1109 Xml.Append(MaxCount.ToString());
1114 return this.client.SendIqGet(this.GetDomain(TokenId), Xml.ToString(), async (Sender, e) =>
1117 List<TokenEvent> Events =
new List<TokenEvent>();
1119 if (e.
Ok && !(E is
null))
1121 foreach (XmlNode N
in E.ChildNodes)
1123 if (N is XmlElement E2 && E2.NamespaceURI == NamespaceNeuroFeatures)
1145 return this.GetEventsAsync(TokenId, 0,
int.MaxValue);
1154 public async Task<TokenEvent[]>
GetEventsAsync(
string TokenId,
int Offset,
int MaxCount)
1156 TaskCompletionSource<TokenEvent[]> Result =
new TaskCompletionSource<TokenEvent[]>();
1158 await this.GetEvents(TokenId, Offset, MaxCount, (Sender, e) =>
1161 Result.TrySetResult(e.Events);
1163 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get token events."));
1165 return Task.CompletedTask;
1168 return await Result.Task;
1173 #region GetCreationAttributes
1182 return this.client.SendIqGet(this.componentAddress,
"<creationAttributes xmlns='" + NamespaceNeuroFeatures +
"'/>", (Sender, e) =>
1194 TaskCompletionSource<CreationAttributesEventArgs> Result =
new TaskCompletionSource<CreationAttributesEventArgs>();
1196 await this.GetCreationAttributes((Sender, e) =>
1199 Result.TrySetResult(e);
1201 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get creation attributes."));
1203 return Task.CompletedTask;
1206 return await Result.Task;
1211 #region GenerateDescription
1221 EventHandlerAsync<ReportEventArgs> Callback,
object State)
1223 string Domain = this.GetDomain(TokenId);
1224 StringBuilder Xml =
new StringBuilder();
1226 Xml.Append(
"<description xmlns='");
1227 Xml.Append(NamespaceNeuroFeatures);
1228 Xml.Append(
"' id='");
1230 Xml.Append(
"' format='");
1231 Xml.Append(Format.ToString());
1234 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) =>
this.ReportResponse(e, Callback), State);
1237 private async Task ReportResponse(
IqResultEventArgs e, EventHandlerAsync<ReportEventArgs> Callback)
1241 string ReportText =
null;
1244 (e.
FirstElement.NamespaceURI == NamespaceStateMachine ||
1245 e.
FirstElement.NamespaceURI == NamespaceNeuroFeatures))
1254 catch (Exception ex)
1256 await this.client.Exception(ex);
1268 TaskCompletionSource<ReportEventArgs> Result =
new TaskCompletionSource<ReportEventArgs>();
1270 await this.GenerateDescription(TokenId, Format, (Sender, e) =>
1273 Result.TrySetResult(e);
1275 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get the description of the token."));
1277 return Task.CompletedTask;
1280 return await Result.Task;
1287 #region State-Machines
1289 #region GetCurrentState
1297 public Task
GetCurrentState(
string TokenId, EventHandlerAsync<CurrentStateEventArgs> Callback,
object State)
1299 string Domain = this.GetDomain(TokenId);
1300 StringBuilder Xml =
new StringBuilder();
1302 Xml.Append(
"<currentState xmlns='");
1303 Xml.Append(NamespaceStateMachine);
1304 Xml.Append(
"' tokenId='");
1308 return this.client.SendIqGet(Domain, Xml.ToString(), async (Sender, e) =>
1312 string CurrentState =
null;
1314 bool Running =
false;
1315 DateTime Expires = DateTime.MinValue;
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);
1332 catch (Exception ex)
1334 await this.client.Exception(ex);
1340 private async
static Task<Variables> ParseVariables(XmlElement VariablesDefinition)
1344 foreach (XmlNode N
in VariablesDefinition.ChildNodes)
1346 if (N is XmlElement E &&
1347 E.LocalName ==
"variable" &&
1348 E.NamespaceURI == NamespaceStateMachine)
1351 object Value = await ParseVariable(E,
Variables);
1360 private async
static Task<object> ParseVariable(XmlElement VariableDefinition,
Variables Variables)
1362 object Value =
null;
1364 foreach (XmlNode N2
in VariableDefinition.ChildNodes)
1366 if (!(N2 is XmlElement E2))
1369 switch (E2.LocalName)
1391 if (sbyte.TryParse(E2.InnerText, out sbyte i8))
1396 if (
short.TryParse(E2.InnerText, out
short i16))
1401 if (
int.TryParse(E2.InnerText, out
int i32))
1406 if (
long.TryParse(E2.InnerText, out
long i64))
1411 if (
byte.TryParse(E2.InnerText, out
byte ui8))
1416 if (ushort.TryParse(E2.InnerText, out ushort ui16))
1421 if (uint.TryParse(E2.InnerText, out uint ui32))
1426 if (ulong.TryParse(E2.InnerText, out ulong ui64))
1441 if (
XML.
TryParse(E2.InnerText, out DateTimeOffset TPO))
1446 if (TimeSpan.TryParse(E2.InnerText, out TimeSpan TS))
1456 Value = E2.InnerText;
1467 Value = E2.InnerText;
1482 TaskCompletionSource<CurrentStateEventArgs> Result =
new TaskCompletionSource<CurrentStateEventArgs>();
1484 await this.GetCurrentState(TokenId, (Sender, e) =>
1487 Result.TrySetResult(e);
1489 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get current state of state-machine."));
1491 return Task.CompletedTask;
1494 return await Result.Task;
1499 #region GenerateProfilingReport
1509 EventHandlerAsync<ReportEventArgs> Callback,
object State)
1511 string Domain = this.GetDomain(TokenId);
1512 StringBuilder Xml =
new StringBuilder();
1514 Xml.Append(
"<profilingReport xmlns='");
1515 Xml.Append(NamespaceStateMachine);
1516 Xml.Append(
"' tokenId='");
1518 Xml.Append(
"' format='");
1519 Xml.Append(Format.ToString());
1522 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) =>
this.ReportResponse(e, Callback), State);
1532 TaskCompletionSource<ReportEventArgs> Result =
new TaskCompletionSource<ReportEventArgs>();
1534 await this.GenerateProfilingReport(TokenId, Format, (Sender, e) =>
1537 Result.TrySetResult(e);
1539 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get the profiling report of the state-machine."));
1541 return Task.CompletedTask;
1544 return await Result.Task;
1549 #region GeneratePresentReport
1559 EventHandlerAsync<ReportEventArgs> Callback,
object State)
1561 string Domain = this.GetDomain(TokenId);
1562 StringBuilder Xml =
new StringBuilder();
1564 Xml.Append(
"<presentReport xmlns='");
1565 Xml.Append(NamespaceStateMachine);
1566 Xml.Append(
"' tokenId='");
1568 Xml.Append(
"' format='");
1569 Xml.Append(Format.ToString());
1572 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) =>
this.ReportResponse(e, Callback), State);
1582 TaskCompletionSource<ReportEventArgs> Result =
new TaskCompletionSource<ReportEventArgs>();
1584 await this.GeneratePresentReport(TokenId, Format, (Sender, e) =>
1587 Result.TrySetResult(e);
1589 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get the profiling report of the state-machine."));
1591 return Task.CompletedTask;
1594 return await Result.Task;
1599 #region GenerateHistoryReport
1609 EventHandlerAsync<ReportEventArgs> Callback,
object State)
1611 string Domain = this.GetDomain(TokenId);
1612 StringBuilder Xml =
new StringBuilder();
1614 Xml.Append(
"<historyReport xmlns='");
1615 Xml.Append(NamespaceStateMachine);
1616 Xml.Append(
"' tokenId='");
1618 Xml.Append(
"' format='");
1619 Xml.Append(Format.ToString());
1622 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) =>
this.ReportResponse(e, Callback), State);
1632 TaskCompletionSource<ReportEventArgs> Result =
new TaskCompletionSource<ReportEventArgs>();
1634 await this.GenerateHistoryReport(TokenId, Format, (Sender, e) =>
1637 Result.TrySetResult(e);
1639 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get the profiling report of the state-machine."));
1641 return Task.CompletedTask;
1644 return await Result.Task;
1649 #region GenerateStateDiagram
1659 EventHandlerAsync<ReportEventArgs> Callback,
object State)
1661 string Domain = this.GetDomain(TokenId);
1662 StringBuilder Xml =
new StringBuilder();
1664 Xml.Append(
"<stateDiagram xmlns='");
1665 Xml.Append(NamespaceStateMachine);
1666 Xml.Append(
"' tokenId='");
1668 Xml.Append(
"' format='");
1669 Xml.Append(Format.ToString());
1672 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) =>
this.ReportResponse(e, Callback), State);
1682 TaskCompletionSource<ReportEventArgs> Result =
new TaskCompletionSource<ReportEventArgs>();
1684 await this.GenerateStateDiagram(TokenId, Format, (Sender, e) =>
1687 Result.TrySetResult(e);
1689 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get the state diagram of the state-machine."));
1691 return Task.CompletedTask;
1694 return await Result.Task;
1699 #region StateUpdated
1707 return this.StateUpdated.Raise(
this,
new NewStateEventArgs(TokenId, MachineId, NewState, e));
1717 #region VariablesUpdated
1719 private async Task VariablesUpdatedHandler(
object Sender,
MessageEventArgs e)
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.
static bool TryParse(XmlElement Xml, out TokenEvent Event)
Tries to parse a token event from its XML definition.
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.
static bool TryParse(XmlElement Xml, out Token Token)
Serializes the Token, in normalized form.
Contains one token total, i.e. sum of token values, for a given currency.
Helps with parsing of commong data types.
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
static string Encode(string s)
Encodes a string for use in XML.
static bool TryParse(string s, out DateTime Value)
Tries to decode a string encoded DateTime.
static bool IsValidXml(string Xml)
Checks if a string is valid XML
Class representing an event.
Static class managing the application event log. Applications and services log events on this static ...
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.
Adds support for legal identities, smart contracts and signatures to an XMPP client.
Event arguments for ID References responses
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....
bool UnregisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool RemoveNamespaceAsClientFeature)
Unregisters a Message handler.
void RegisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool PublishNamespaceAsClientFeature)
Registers a Message handler.
Task< uint > SendIqGet(string To, string Xml, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends an IQ Get request.
Base class for XMPP Extensions.
XmppClient client
XMPP Client used by the extension.
XmppClient Client
XMPP Client.
Class managing a script expression.
async Task< object > EvaluateAsync(Variables Variables)
Evaluates the expression, using the variables provided in the Variables collection....
ReportFormat
Desired report format
Represents a duration value, as defined by the xsd:duration data type: http://www....
static bool TryParse(string s, out Duration Result)
Tries to parse a duration value.