6using System.Threading.Tasks;
40 private readonly
string componentAddress;
104 public Task
GetToken(
string TokenId, EventHandlerAsync<TokenResultEventArgs> Callback,
object State)
106 string Domain = this.GetDomain(TokenId);
107 StringBuilder Xml =
new StringBuilder();
109 Xml.Append(
"<token id='");
111 Xml.Append(
"' xmlns='");
115 return this.
client.
SendIqGet(Domain, Xml.ToString(), async (Sender, e) =>
117 Token ResultToken =
null;
121 if (e.FirstElement is null || e.FirstElement.LocalName !=
"token" || e.FirstElement.NamespaceURI != NamespaceNeuroFeatures)
124 this.client.Error(
"Unexpected response.");
126 else if ((ResultToken = await
Token.
TryParse(e.FirstElement)) is
null)
129 this.client.Error(
"Unable to parse token.");
134 await Callback.Raise(
this, e2);
138 private string GetDomain(
string TokenId)
140 int i = TokenId.IndexOf(
'@');
143 return this.componentAddress;
145 return TokenId[(i + 1)..];
154 TaskCompletionSource<Token> Result =
new TaskCompletionSource<Token>();
156 await this.GetToken(TokenId, (Sender, e) =>
159 Result.TrySetResult(e.Token);
161 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to get token."));
163 return Task.CompletedTask;
166 return await Result.Task;
171 #region Get Token References
180 return this.GetTokenReferences(this.componentAddress, 0,
int.MaxValue, Callback, State);
189 public Task
GetTokenReferences(
string Address, EventHandlerAsync<IdReferencesEventArgs> Callback,
object State)
191 return this.GetTokenReferences(Address, 0,
int.MaxValue, Callback, State);
201 public Task
GetTokenReferences(
int Offset,
int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback,
object State)
203 return this.GetTokenReferences(this.componentAddress, Offset, MaxCount, Callback, State);
214 public Task
GetTokenReferences(
string Address,
int Offset,
int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback,
object State)
217 throw new ArgumentException(
"Offsets cannot be negative.", nameof(Offset));
220 throw new ArgumentException(
"Must be postitive.", nameof(MaxCount));
222 StringBuilder Xml =
new StringBuilder();
224 Xml.Append(
"<tokens references='true' xmlns='");
225 Xml.Append(NamespaceNeuroFeatures);
229 Xml.Append(
"' offset='");
230 Xml.Append(Offset.ToString());
233 if (MaxCount <
int.MaxValue)
235 Xml.Append(
"' maxCount='");
236 Xml.Append(MaxCount.ToString());
241 return this.client.SendIqGet(Address, Xml.ToString(),
this.TokenReferencesResponse,
new object[] { Callback, State });
246 object[] P = (
object[])e.
State;
247 EventHandlerAsync<IdReferencesEventArgs> Callback = (EventHandlerAsync<IdReferencesEventArgs>)P[0];
249 List<string> IDs =
new List<string>();
251 if (e.
Ok && !(E is
null))
253 foreach (XmlNode N
in E.ChildNodes)
255 if (N is XmlElement E2 && E2.LocalName ==
"ref" && E2.NamespaceURI == NamespaceNeuroFeatures)
275 return this.GetTokenReferencesAsync(this.componentAddress, 0,
int.MaxValue);
285 return this.GetTokenReferencesAsync(Address, 0,
int.MaxValue);
296 return this.GetTokenReferencesAsync(this.componentAddress, Offset, MaxCount);
308 TaskCompletionSource<string[]> Result =
new TaskCompletionSource<string[]>();
310 await this.GetTokenReferences(Address, Offset, MaxCount, (Sender, e) =>
313 Result.TrySetResult(e.References);
315 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get token references."));
317 return Task.CompletedTask;
321 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 if (!(ParsedToken is
null))
419 Tokens.Add(ParsedToken);
424 References.Add(TokenId);
434 await Callback.Raise(
this,
new TokensEventArgs(e, Tokens.ToArray(), References.ToArray()));
443 return this.GetTokensAsync(this.componentAddress, 0,
int.MaxValue);
453 return this.GetTokensAsync(Address, 0,
int.MaxValue);
464 return this.GetTokensAsync(this.componentAddress, Offset, MaxCount);
474 public async Task<TokensEventArgs>
GetTokensAsync(
string Address,
int Offset,
int MaxCount)
476 TaskCompletionSource<TokensEventArgs> Result =
new TaskCompletionSource<TokensEventArgs>();
478 await this.GetTokens(Address, Offset, MaxCount, (Sender, e) =>
480 Result.TrySetResult(e);
481 return Task.CompletedTask;
485 return await Result.Task;
490 #region Get Contract Token References
500 return this.GetContractTokenReferences(this.contractsClient.GetTrustProvider(ContractId),
501 ContractId, 0,
int.MaxValue, Callback, State);
513 return this.GetContractTokenReferences(Address, ContractId, 0,
int.MaxValue, Callback, State);
524 public Task
GetContractTokenReferences(
string ContractId,
int Offset,
int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback,
object State)
526 return this.GetContractTokenReferences(this.contractsClient.GetTrustProvider(ContractId),
527 ContractId, Offset, MaxCount, Callback, State);
539 public Task
GetContractTokenReferences(
string Address,
string ContractId,
int Offset,
int MaxCount, EventHandlerAsync<IdReferencesEventArgs> Callback,
object State)
542 throw new ArgumentException(
"Offsets cannot be negative.", nameof(Offset));
545 throw new ArgumentException(
"Must be postitive.", nameof(MaxCount));
547 StringBuilder Xml =
new StringBuilder();
549 Xml.Append(
"<contractTokens contractId='");
551 Xml.Append(
"' references='true' xmlns='");
552 Xml.Append(NamespaceNeuroFeatures);
556 Xml.Append(
"' offset='");
557 Xml.Append(Offset.ToString());
560 if (MaxCount <
int.MaxValue)
562 Xml.Append(
"' maxCount='");
563 Xml.Append(MaxCount.ToString());
568 return this.client.SendIqGet(Address, Xml.ToString(),
this.TokenReferencesResponse,
new object[] { Callback, State });
578 return this.GetContractTokenReferencesAsync(this.contractsClient.GetTrustProvider(ContractId),
579 ContractId, 0,
int.MaxValue);
590 return this.GetContractTokenReferencesAsync(Address, ContractId, 0,
int.MaxValue);
602 return this.GetContractTokenReferencesAsync(this.contractsClient.GetTrustProvider(ContractId),
603 ContractId, Offset, MaxCount);
616 TaskCompletionSource<string[]> Result =
new TaskCompletionSource<string[]>();
618 await this.GetContractTokenReferences(Address, ContractId, Offset, MaxCount, (Sender, e) =>
621 Result.TrySetResult(e.References);
623 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get token references."));
625 return Task.CompletedTask;
629 return await Result.Task;
634 #region Get Contract Tokens
642 public Task
GetContractTokens(
string ContractId, EventHandlerAsync<TokensEventArgs> Callback,
object State)
644 return this.GetContractTokens(this.contractsClient.GetTrustProvider(ContractId),
645 ContractId, 0,
int.MaxValue, Callback, State);
655 public Task
GetContractTokens(
string Address,
string ContractId, EventHandlerAsync<TokensEventArgs> Callback,
object State)
657 return this.GetContractTokens(Address, ContractId, 0,
int.MaxValue, Callback, State);
668 public Task
GetContractTokens(
string ContractId,
int Offset,
int MaxCount, EventHandlerAsync<TokensEventArgs> Callback,
object State)
670 return this.GetContractTokens(this.contractsClient.GetTrustProvider(ContractId),
671 ContractId, Offset, MaxCount, Callback, State);
683 public Task
GetContractTokens(
string Address,
string ContractId,
int Offset,
int MaxCount, EventHandlerAsync<TokensEventArgs> Callback,
object State)
686 throw new ArgumentException(
"Offsets cannot be negative.", nameof(Offset));
689 throw new ArgumentException(
"Must be postitive.", nameof(MaxCount));
691 StringBuilder Xml =
new StringBuilder();
693 Xml.Append(
"<contractTokens contractId='");
695 Xml.Append(
"' references='false' xmlns='");
696 Xml.Append(NamespaceNeuroFeatures);
700 Xml.Append(
"' offset='");
701 Xml.Append(Offset.ToString());
704 if (MaxCount <
int.MaxValue)
706 Xml.Append(
"' maxCount='");
707 Xml.Append(MaxCount.ToString());
712 return this.client.SendIqGet(Address, Xml.ToString(),
this.TokensResponse,
new object[] { Callback, State });
722 return this.GetContractTokensAsync(this.contractsClient.GetTrustProvider(ContractId),
723 ContractId, 0,
int.MaxValue);
734 return this.GetContractTokensAsync(Address, ContractId, 0,
int.MaxValue);
746 return this.GetContractTokensAsync(this.contractsClient.GetTrustProvider(ContractId),
747 ContractId, Offset, MaxCount);
760 TaskCompletionSource<TokensEventArgs> Result =
new TaskCompletionSource<TokensEventArgs>();
762 await this.GetContractTokens(Address, ContractId, Offset, MaxCount, (Sender, e) =>
764 Result.TrySetResult(e);
765 return Task.CompletedTask;
769 return await Result.Task;
780 foreach (XmlNode N
in e.
Content.ChildNodes)
782 if (N is XmlElement E &&
783 E.LocalName ==
"token" &&
784 E.NamespaceURI == NamespaceNeuroFeatures &&
787 await this.TokenAdded.Raise(
this,
new TokenEventArgs(e, TokenAdded));
805 foreach (XmlNode N
in e.
Content.ChildNodes)
807 if (N is XmlElement E &&
808 E.LocalName ==
"token" &&
809 E.NamespaceURI == NamespaceNeuroFeatures &&
812 await this.TokenRemoved.Raise(
this,
new TokenEventArgs(e, TokenRemoved));
831 public Task
GetTotals(EventHandlerAsync<TokenTotalsEventArgs> Callback,
object State)
833 return this.GetTotals(this.componentAddress, Callback, State);
842 public Task
GetTotals(
string Address, EventHandlerAsync<TokenTotalsEventArgs> Callback,
object State)
844 StringBuilder Xml =
new StringBuilder();
846 Xml.Append(
"<totals xmlns='");
847 Xml.Append(NamespaceNeuroFeatures);
850 return this.client.SendIqGet(Address, Xml.ToString(),
this.TotalsResponse,
new object[] { Callback, State });
855 object[] P = (
object[])e.
State;
856 EventHandlerAsync<TokenTotalsEventArgs> Callback = (EventHandlerAsync<TokenTotalsEventArgs>)P[0];
858 List<TokenTotal> Totals =
new List<TokenTotal>();
860 if (e.
Ok && !(E is
null) && E.LocalName ==
"totals" && E.NamespaceURI == NamespaceNeuroFeatures)
862 foreach (XmlNode N
in E.ChildNodes)
864 if (N is XmlElement E2 && E2.NamespaceURI == NamespaceNeuroFeatures && E2.LocalName ==
"total")
888 return this.GetTotalsAsync(this.componentAddress);
898 TaskCompletionSource<TokenTotalsEventArgs> Result =
new TaskCompletionSource<TokenTotalsEventArgs>();
900 await this.GetTotals(Address, (Sender, e) =>
902 Result.TrySetResult(e);
903 return Task.CompletedTask;
907 return await Result.Task;
921 public Task
AddTextNote(
string TokenId,
string Note, EventHandlerAsync<IqResultEventArgs> Callback,
object State)
923 return this.AddTextNote(TokenId, Note,
false, Callback, State);
935 public Task
AddTextNote(
string TokenId,
string Note,
bool Personal, EventHandlerAsync<IqResultEventArgs> Callback,
object State)
937 string Domain = this.GetDomain(TokenId);
938 StringBuilder Xml =
new StringBuilder();
940 Xml.Append(
"<noteText xmlns='");
941 Xml.Append(NamespaceNeuroFeatures);
942 Xml.Append(
"' id='");
944 Xml.Append(
"' personal='");
948 Xml.Append(
"</noteText>");
950 return this.client.SendIqSet(Domain, Xml.ToString(), Callback, State);
960 return this.AddTextNoteAsync(TokenId, Note,
false);
972 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
974 await this.AddTextNote(TokenId, Note, Personal, (Sender, e) =>
977 Result.TrySetResult(
true);
979 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to add text note."));
981 return Task.CompletedTask;
998 public Task
AddXmlNote(
string TokenId,
string Note, EventHandlerAsync<IqResultEventArgs> Callback,
object State)
1000 return this.AddXmlNote(TokenId, Note,
false, Callback, State);
1012 public Task
AddXmlNote(
string TokenId,
string Note,
bool Personal, EventHandlerAsync<IqResultEventArgs> Callback,
object State)
1015 throw new ArgumentException(
"Note is not valid XML.", nameof(Note));
1017 string Domain = this.GetDomain(TokenId);
1018 StringBuilder Xml =
new StringBuilder();
1020 Xml.Append(
"<noteXml xmlns='");
1021 Xml.Append(NamespaceNeuroFeatures);
1022 Xml.Append(
"' id='");
1024 Xml.Append(
"' personal='");
1028 Xml.Append(
"</noteXml>");
1030 return this.client.SendIqSet(Domain, Xml.ToString(), Callback, State);
1040 return this.AddXmlNoteAsync(TokenId, Note,
false);
1052 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
1054 await this.AddXmlNote(TokenId, Note, Personal, (Sender, e) =>
1057 Result.TrySetResult(
true);
1059 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to add xml note."));
1061 return Task.CompletedTask;
1077 public Task
GetEvents(
string TokenId, EventHandlerAsync<EventsEventArgs> Callback,
object State)
1079 return this.GetEvents(TokenId, 0,
int.MaxValue, Callback, State);
1090 public Task
GetEvents(
string TokenId,
int Offset,
int MaxCount, EventHandlerAsync<EventsEventArgs> Callback,
object State)
1093 throw new ArgumentException(
"Offsets cannot be negative.", nameof(Offset));
1096 throw new ArgumentException(
"Must be postitive.", nameof(MaxCount));
1098 StringBuilder Xml =
new StringBuilder();
1100 Xml.Append(
"<events xmlns='");
1101 Xml.Append(NamespaceNeuroFeatures);
1102 Xml.Append(
"' id='");
1107 Xml.Append(
"' offset='");
1108 Xml.Append(Offset.ToString());
1111 if (MaxCount <
int.MaxValue)
1113 Xml.Append(
"' maxCount='");
1114 Xml.Append(MaxCount.ToString());
1119 return this.client.SendIqGet(this.GetDomain(TokenId), Xml.ToString(), async (Sender, e) =>
1122 List<TokenEvent> Events =
new List<TokenEvent>();
1124 if (e.
Ok && !(E is
null))
1126 foreach (XmlNode N
in E.ChildNodes)
1128 if (N is XmlElement E2 && E2.NamespaceURI == NamespaceNeuroFeatures)
1150 return this.GetEventsAsync(TokenId, 0,
int.MaxValue);
1159 public async Task<TokenEvent[]>
GetEventsAsync(
string TokenId,
int Offset,
int MaxCount)
1161 TaskCompletionSource<TokenEvent[]> Result =
new TaskCompletionSource<TokenEvent[]>();
1163 await this.GetEvents(TokenId, Offset, MaxCount, (Sender, e) =>
1166 Result.TrySetResult(e.Events);
1168 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get token events."));
1170 return Task.CompletedTask;
1173 return await Result.Task;
1178 #region GetCreationAttributes
1187 return this.client.SendIqGet(this.componentAddress,
"<creationAttributes xmlns='" + NamespaceNeuroFeatures +
"'/>", (Sender, e) =>
1199 TaskCompletionSource<CreationAttributesEventArgs> Result =
new TaskCompletionSource<CreationAttributesEventArgs>();
1201 await this.GetCreationAttributes((Sender, e) =>
1204 Result.TrySetResult(e);
1206 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get creation attributes."));
1208 return Task.CompletedTask;
1211 return await Result.Task;
1216 #region GenerateDescription
1226 EventHandlerAsync<ReportEventArgs> Callback,
object State)
1228 string Domain = this.GetDomain(TokenId);
1229 StringBuilder Xml =
new StringBuilder();
1231 Xml.Append(
"<description xmlns='");
1232 Xml.Append(NamespaceNeuroFeatures);
1233 Xml.Append(
"' id='");
1235 Xml.Append(
"' format='");
1236 Xml.Append(Format.ToString());
1239 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) =>
this.ReportResponse(e, Callback), State);
1242 private async Task ReportResponse(
IqResultEventArgs e, EventHandlerAsync<ReportEventArgs> Callback)
1246 string ReportText =
null;
1249 (e.
FirstElement.NamespaceURI == NamespaceStateMachine ||
1250 e.
FirstElement.NamespaceURI == NamespaceNeuroFeatures))
1259 catch (Exception ex)
1261 this.client.Exception(ex);
1273 TaskCompletionSource<ReportEventArgs> Result =
new TaskCompletionSource<ReportEventArgs>();
1275 await this.GenerateDescription(TokenId, Format, (Sender, e) =>
1278 Result.TrySetResult(e);
1280 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get the description of the token."));
1282 return Task.CompletedTask;
1285 return await Result.Task;
1292 #region State-Machines
1294 #region GetCurrentState
1302 public Task
GetCurrentState(
string TokenId, EventHandlerAsync<CurrentStateEventArgs> Callback,
object State)
1304 string Domain = this.GetDomain(TokenId);
1305 StringBuilder Xml =
new StringBuilder();
1307 Xml.Append(
"<currentState xmlns='");
1308 Xml.Append(NamespaceStateMachine);
1309 Xml.Append(
"' tokenId='");
1313 return this.client.SendIqGet(Domain, Xml.ToString(), async (Sender, e) =>
1317 string CurrentState =
null;
1319 bool Running =
false;
1320 DateTime Expires = DateTime.MinValue;
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);
1337 catch (Exception ex)
1339 this.client.Exception(ex);
1345 private async
static Task<Variables> ParseVariables(XmlElement VariablesDefinition)
1349 foreach (XmlNode N
in VariablesDefinition.ChildNodes)
1351 if (N is XmlElement E &&
1352 E.LocalName ==
"variable" &&
1353 E.NamespaceURI == NamespaceStateMachine)
1356 object Value = await ParseVariable(E,
Variables);
1365 private async
static Task<object> ParseVariable(XmlElement VariableDefinition,
Variables Variables)
1367 object Value =
null;
1369 foreach (XmlNode N2
in VariableDefinition.ChildNodes)
1371 if (!(N2 is XmlElement E2))
1374 switch (E2.LocalName)
1396 if (sbyte.TryParse(E2.InnerText, out sbyte i8))
1401 if (
short.TryParse(E2.InnerText, out
short i16))
1406 if (
int.TryParse(E2.InnerText, out
int i32))
1411 if (
long.TryParse(E2.InnerText, out
long i64))
1416 if (
byte.TryParse(E2.InnerText, out
byte ui8))
1421 if (ushort.TryParse(E2.InnerText, out ushort ui16))
1426 if (uint.TryParse(E2.InnerText, out uint ui32))
1431 if (ulong.TryParse(E2.InnerText, out ulong ui64))
1446 if (
XML.
TryParse(E2.InnerText, out DateTimeOffset TPO))
1451 if (TimeSpan.TryParse(E2.InnerText, out TimeSpan TS))
1461 Value = E2.InnerText;
1472 Value = E2.InnerText;
1487 TaskCompletionSource<CurrentStateEventArgs> Result =
new TaskCompletionSource<CurrentStateEventArgs>();
1489 await this.GetCurrentState(TokenId, (Sender, e) =>
1492 Result.TrySetResult(e);
1494 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get current state of state-machine."));
1496 return Task.CompletedTask;
1499 return await Result.Task;
1504 #region GenerateProfilingReport
1514 EventHandlerAsync<ReportEventArgs> Callback,
object State)
1516 string Domain = this.GetDomain(TokenId);
1517 StringBuilder Xml =
new StringBuilder();
1519 Xml.Append(
"<profilingReport xmlns='");
1520 Xml.Append(NamespaceStateMachine);
1521 Xml.Append(
"' tokenId='");
1523 Xml.Append(
"' format='");
1524 Xml.Append(Format.ToString());
1527 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) =>
this.ReportResponse(e, Callback), State);
1537 TaskCompletionSource<ReportEventArgs> Result =
new TaskCompletionSource<ReportEventArgs>();
1539 await this.GenerateProfilingReport(TokenId, Format, (Sender, e) =>
1542 Result.TrySetResult(e);
1544 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get the profiling report of the state-machine."));
1546 return Task.CompletedTask;
1549 return await Result.Task;
1554 #region GeneratePresentReport
1564 EventHandlerAsync<ReportEventArgs> Callback,
object State)
1566 string Domain = this.GetDomain(TokenId);
1567 StringBuilder Xml =
new StringBuilder();
1569 Xml.Append(
"<presentReport xmlns='");
1570 Xml.Append(NamespaceStateMachine);
1571 Xml.Append(
"' tokenId='");
1573 Xml.Append(
"' format='");
1574 Xml.Append(Format.ToString());
1577 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) =>
this.ReportResponse(e, Callback), State);
1587 TaskCompletionSource<ReportEventArgs> Result =
new TaskCompletionSource<ReportEventArgs>();
1589 await this.GeneratePresentReport(TokenId, Format, (Sender, e) =>
1592 Result.TrySetResult(e);
1594 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get the profiling report of the state-machine."));
1596 return Task.CompletedTask;
1599 return await Result.Task;
1604 #region GenerateHistoryReport
1614 EventHandlerAsync<ReportEventArgs> Callback,
object State)
1616 string Domain = this.GetDomain(TokenId);
1617 StringBuilder Xml =
new StringBuilder();
1619 Xml.Append(
"<historyReport xmlns='");
1620 Xml.Append(NamespaceStateMachine);
1621 Xml.Append(
"' tokenId='");
1623 Xml.Append(
"' format='");
1624 Xml.Append(Format.ToString());
1627 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) =>
this.ReportResponse(e, Callback), State);
1637 TaskCompletionSource<ReportEventArgs> Result =
new TaskCompletionSource<ReportEventArgs>();
1639 await this.GenerateHistoryReport(TokenId, Format, (Sender, e) =>
1642 Result.TrySetResult(e);
1644 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get the profiling report of the state-machine."));
1646 return Task.CompletedTask;
1649 return await Result.Task;
1654 #region GenerateStateDiagram
1664 EventHandlerAsync<ReportEventArgs> Callback,
object State)
1666 string Domain = this.GetDomain(TokenId);
1667 StringBuilder Xml =
new StringBuilder();
1669 Xml.Append(
"<stateDiagram xmlns='");
1670 Xml.Append(NamespaceStateMachine);
1671 Xml.Append(
"' tokenId='");
1673 Xml.Append(
"' format='");
1674 Xml.Append(Format.ToString());
1677 return this.client.SendIqGet(Domain, Xml.ToString(), (Sender, e) =>
this.ReportResponse(e, Callback), State);
1687 TaskCompletionSource<ReportEventArgs> Result =
new TaskCompletionSource<ReportEventArgs>();
1689 await this.GenerateStateDiagram(TokenId, Format, (Sender, e) =>
1692 Result.TrySetResult(e);
1694 Result.TrySetException(e.
StanzaError ??
new Exception(
"Unable to get the state diagram of the state-machine."));
1696 return Task.CompletedTask;
1699 return await Result.Task;
1704 #region StateUpdated
1712 return this.StateUpdated.Raise(
this,
new NewStateEventArgs(TokenId, MachineId, NewState, e));
1722 #region VariablesUpdated
1724 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 async Task< Token > TryParse(XmlElement Xml)
Tries to parse a Token.
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.