2using System.Collections.Generic;
4using System.Threading.Tasks;
52 private static Dictionary<string, IStateMachineNode> stateMachineNodes =
null;
56 internal class CacheRecord
83 XmlDocument Doc =
new XmlDocument();
88 Result.XmlDefinition = Xml;
118 XmlDefinition = Xml.OuterXml,
122 CreatorTokenId = Token.TokenId
139 if (stateMachineNodes is
null)
141 Dictionary<string, IStateMachineNode> ByFqn =
new Dictionary<string, IStateMachineNode>();
145 if (T.IsAbstract || T.IsInterface || T.IsGenericTypeDefinition)
151 ByFqn[Node.Namespace +
"#" + Node.
LocalName] = Node;
159 stateMachineNodes = ByFqn;
162 string Fqn = Xml.NamespaceURI +
"#" + Xml.LocalName;
163 if (!stateMachineNodes.TryGetValue(Fqn, out Node))
164 throw new Exception(
"A State-Machine node named " + Fqn +
" not known.");
166 Node = Node.Create();
182 CacheRecord CacheRecord = await GetStateMachine(
Token);
183 if (CacheRecord is
null)
186 await EventGenerated(
Token,
Event, CacheRecord);
210 if (!(CacheRecord.Profiler is
null))
212 int NoteNr = CacheRecord.Profiler.AddNote(ex);
213 CacheRecord.Profiler?.Exception(ex,
"Note" + NoteNr);
226 internal static async Task EventGenerated(
string StateMachineId,
TokenEvent Event)
228 CacheRecord CacheRecord = await GetStateMachine(StateMachineId);
229 if (CacheRecord is
null)
234 await EventGenerated(
Token,
Event, CacheRecord);
242 internal static Task<CacheRecord> GetStateMachine(
Token Token)
253 internal static async Task<CurrentState> GetOrCreateCurrentState(
StateMachine Machine)
264 State =
string.Empty,
267 ArchiveOptional = Machine.ArchiveOptional
282 internal static async Task<CacheRecord> GetStateMachine(
string MachineId)
284 if (stateMachines.TryGetValue(MachineId, out CacheRecord Result))
295 Result =
new CacheRecord()
304 stateMachines[MachineId] = Result;
306 Result.Profiler.Start();
307 Result.Profiler.Event(
"Reloaded");
322 Ledger.EntryAdded += Ledger_EntryAdded;
323 Ledger.EntryUpdated += Ledger_EntryUpdated;
324 Ledger.EntryDeleted += Ledger_EntryDeleted;
326 LinkedList<TimepointEventHandler> ToDelete =
null;
333 if (await ReregisterOnStart(Handler))
335 if (ToDelete is
null)
336 ToDelete =
new LinkedList<TimepointEventHandler>();
338 ToDelete.AddLast(Handler);
344 if (!(ToDelete is
null))
358 CacheRecord CacheRecord = await GetStateMachine(Handler.
StateMachineId);
359 if (CacheRecord is
null)
390 internal static Task ModuleStopped()
395 Ledger.EntryAdded -= Ledger_EntryAdded;
396 Ledger.EntryUpdated -= Ledger_EntryUpdated;
397 Ledger.EntryDeleted -= Ledger_EntryDeleted;
401 return Task.CompletedTask;
429 await Machine.
Start(Arguments);
438 internal static async Task<CacheRecord> EventRaised(EventHandlers.EventHandler Handler,
Token Token, params KeyValuePair<string, object>[] ToSet)
440 CacheRecord CacheRecord = await GetStateMachine(Handler.
StateMachineId);
441 if (CacheRecord is
null)
459 if (!(ToSet is
null))
461 foreach (KeyValuePair<string, object> P
in ToSet)
470 CacheRecord.EDaler ?? eDaler, CacheRecord.Profiler);
479 await
Event.ExecuteLog(Arguments);
480 StateId = await
Event.GetNewState(Arguments);
484 StateId = await
Event.GetFailureState(Arguments);
486 if (
string.IsNullOrEmpty(StateId))
490 if (
string.IsNullOrEmpty(StateId))
502 if (!(CacheRecord.Profiler is
null))
504 int NoteNr = CacheRecord.Profiler.AddNote(ex);
505 CacheRecord.Profiler?.Exception(ex,
"Note" + NoteNr);
526 if ((Handlers?.Length ?? 0) == 0)
548 if ((Handlers?.Length ?? 0) == 0)
551 XmlDocument Doc =
null;
559 Doc =
new XmlDocument();
560 Doc.LoadXml(
Event.Note);
580 if ((Handlers?.Length ?? 0) == 0)
608 if ((Handlers?.Length ?? 0) == 0)
611 XmlDocument Doc =
null;
622 Doc =
new XmlDocument();
623 Doc.LoadXml(
Event.Note);
631 private static async Task<bool> IsAuthorized(
string Source,
string Privilege)
633 bool CheckPrivilege = !
string.IsNullOrEmpty(
Privilege);
635 if (!CheckPrivilege && Source.IndexOf(
'@') > 0)
645 private static KeyValuePair<string, object>[] GetVariablesToSet(
TokenNoteEventHandler Handler,
object Note,
bool Personal,
string Source)
647 List<KeyValuePair<string, object>> Result =
new List<KeyValuePair<string, object>>();
650 Result.Add(
new KeyValuePair<string, object>(Handler.
SourceVariable, Source));
653 Result.Add(
new KeyValuePair<string, object>(Handler.
PersonalVariable, Personal));
656 Result.Add(
new KeyValuePair<string, object>(Handler.
NoteVariable, Note));
658 return Result.ToArray();
673 if ((Handlers?.Length ?? 0) == 0)
683 private static KeyValuePair<string, object>[] GetVariablesToSet(
686 List<KeyValuePair<string, object>> Result =
new List<KeyValuePair<string, object>>();
706 return Result.ToArray();
719 if ((Handlers?.Length ?? 0) == 0)
725 await EventRaised(Handler,
null, GetVariablesToSet(PaymentHandler, Uri, Uri.
To.
BareJid));
740 if ((Handlers?.Length ?? 0) == 0)
744 Sender = SenderAddress.
BareJid;
749 await EventRaised(Handler,
null, GetVariablesToSet(PaymentHandler, Uri, Sender));
755 List<KeyValuePair<string, object>> Result =
new List<KeyValuePair<string, object>>();
758 Result.Add(
new KeyValuePair<string, object>(Handler.
RemoteVariable, RemoteAddress));
783 return Result.ToArray();
794 return Task.CompletedTask;
797 private static void Ledger_EntryAdded(
object Sender,
ObjectEventArgs e)
802 private static void Ledger_EntryUpdated(
object Sender,
ObjectEventArgs e)
807 private static void Ledger_EntryDeleted(
object Sender,
ObjectEventArgs e)
812 internal static async Task<(int, int, int, int)> DeleteExpiredMachines()
815 int NrEventHandlers = 0;
816 int NrCurrentStates = 0;
826 if (stateMachines.TryGetValue(Machine.
StateMachineId, out CacheRecord Record))
830 if (!
string.IsNullOrEmpty(Record.CurrentState?.State) &&
832 !(State.OnEvent is
null))
838 Machine,
null, Record.CurrentState, Record.Legal, Record.EDaler,
850 IEnumerable<EventHandlers.EventHandler> EventHandlers = await
Database.
FindDelete<EventHandlers.EventHandler>(
853 foreach (EventHandlers.EventHandler
EventHandler in EventHandlers)
874 return (NrMachines, NrEventHandlers, NrCurrentStates, NrSamples);
877 #region XMPP Interface
901 #region GetCurrentStateHandler
903 private static async Task GetCurrentStateHandler(
object Sender,
IqEventArgs e)
906 if (
string.IsNullOrEmpty(TokenId))
918 StringBuilder Xml =
new StringBuilder();
926 Xml.Append(
"<currentState xmlns='");
928 Xml.Append(
"' state='");
930 Xml.Append(
"' ended='");
932 Xml.Append(
"' running='");
934 Xml.Append(
"' expires='");
944 Xml.Append(
"</currentState>");
947 internal static void AppendVariable(StringBuilder Xml,
string Name,
object Value)
949 Xml.Append(
"<variable name='");
954 Xml.Append(
"<null/>");
955 else if (Value is
double dbl)
959 Xml.Append(
"</dbl>");
961 else if (Value is
float fl)
967 else if (Value is decimal dec)
971 Xml.Append(
"</dec>");
973 else if (Value is
int i32)
976 Xml.Append(i32.ToString());
977 Xml.Append(
"</i32>");
979 else if (Value is
long i64)
982 Xml.Append(i64.ToString());
983 Xml.Append(
"</i64>");
985 else if (Value is
short i16)
988 Xml.Append(i16.ToString());
989 Xml.Append(
"</i16>");
991 else if (Value is sbyte i8)
994 Xml.Append(i8.ToString());
997 else if (Value is uint ui32)
999 Xml.Append(
"<ui32>");
1000 Xml.Append(ui32.ToString());
1001 Xml.Append(
"</ui32>");
1003 else if (Value is ulong ui64)
1005 Xml.Append(
"<ui64>");
1006 Xml.Append(ui64.ToString());
1007 Xml.Append(
"</ui64>");
1009 else if (Value is ushort ui16)
1011 Xml.Append(
"<ui16>");
1012 Xml.Append(ui16.ToString());
1013 Xml.Append(
"</ui16>");
1015 else if (Value is
byte ui8)
1017 Xml.Append(
"<ui8>");
1018 Xml.Append(ui8.ToString());
1019 Xml.Append(
"</ui8>");
1021 else if (Value is
bool b)
1027 else if (Value is DateTime TP)
1031 Xml.Append(
"</dt>");
1033 else if (Value is DateTimeOffset TPO)
1035 Xml.Append(
"<dto>");
1037 Xml.Append(
"</dto>");
1039 else if (Value is TimeSpan TS)
1043 Xml.Append(
"</ts>");
1051 else if (Value is
string s)
1059 Xml.Append(
"<exp>");
1061 Xml.Append(
"</exp>");
1064 Xml.Append(
"</variable>");
1067 private static async Task<CacheRecord> GetCacheRecord(
string TokenId,
IqEventArgs e)
1102 private static async Task<CurrentState> GetCurrentState(
string TokenId,
IqEventArgs e)
1104 CacheRecord Record = await GetCacheRecord(TokenId, e);
1108 return Record.CurrentState;
1113 #region GetProfilingReport
1115 internal static async Task<string> GetProfilingReportAsync(
string TokenId,
ReportFormat Format)
1117 CacheRecord Record = await GetCacheRecord(TokenId,
null);
1119 return string.Empty;
1121 return await GetProfilingReport(Record.Profiler, Format);
1124 private static async Task GetProfilingReport(
object Sender,
IqEventArgs e)
1127 if (
string.IsNullOrEmpty(TokenId))
1133 CacheRecord Record = await GetCacheRecord(TokenId, e);
1146 StringBuilder Xml =
new StringBuilder();
1148 Xml.Append(
"<report xmlns='");
1152 Xml.Append(
"</report>");
1159 StringBuilder Markdown =
new StringBuilder();
1161 Markdown.AppendLine(
"Timing Diagram");
1162 Markdown.AppendLine(
"==================");
1163 Markdown.AppendLine();
1164 Markdown.AppendLine(
"```uml");
1166 Markdown.AppendLine(
"```");
1170 for (i = 1; i <= c; i++)
1174 Markdown.AppendLine();
1175 Markdown.Append(
"Note ");
1176 Markdown.AppendLine(i.ToString());
1177 Markdown.AppendLine(
"-----------------");
1178 Markdown.AppendLine();
1180 if (Note is
string s)
1182 if (s.StartsWith(
"@startjson") && s.EndsWith(
"@endjson"))
1184 Markdown.AppendLine(
"```uml");
1185 Markdown.AppendLine(s);
1186 Markdown.AppendLine(
"```");
1194 Markdown.AppendLine();
1195 Markdown.AppendLine(
"```");
1196 Markdown.AppendLine(ScriptError.Node?.SubExpression ?? ScriptError.StackTrace);
1197 Markdown.AppendLine(
"```");
1199 else if (Note is Exception ex)
1202 Markdown.AppendLine();
1203 Markdown.AppendLine(
"```");
1204 Markdown.AppendLine(ex.StackTrace);
1205 Markdown.AppendLine(
"```");
1209 Markdown.AppendLine(
"```uml");
1210 Markdown.AppendLine(
"@startjson");
1211 Markdown.AppendLine(
JSON.
Encode(Note,
true));
1212 Markdown.AppendLine(
"@endjson");
1213 Markdown.AppendLine(
"```");
1223 #region GetPresentReport
1227 CacheRecord Record = await GetStateMachine(
Token);
1229 return string.Empty;
1231 return await GetPresentReport(Record, Format);
1234 private static async Task GetPresentReport(
object Sender,
IqEventArgs e)
1237 if (
string.IsNullOrEmpty(TokenId))
1243 CacheRecord Record = await GetCacheRecord(TokenId, e);
1250 StringBuilder Xml =
new StringBuilder();
1252 Xml.Append(
"<report xmlns='");
1256 Xml.Append(
"</report>");
1261 private static Task<string> GetPresentReport(CacheRecord Record,
ReportFormat Format)
1263 string Markdown =
null;
1269 Markdown = Report.Markdown;
1274 if (
string.IsNullOrEmpty(Markdown))
1275 return Task.FromResult(
string.Empty);
1284 #region GetHistoryReport
1288 CacheRecord Record = await GetStateMachine(
Token);
1290 return string.Empty;
1292 return await GetHistoryReport(Record, Format);
1295 private static async Task GetHistoryReport(
object Sender,
IqEventArgs e)
1298 if (
string.IsNullOrEmpty(TokenId))
1304 CacheRecord Record = await GetCacheRecord(TokenId, e);
1311 StringBuilder Xml =
new StringBuilder();
1313 Xml.Append(
"<report xmlns='");
1317 Xml.Append(
"</report>");
1322 private static async Task<string> GetHistoryReport(CacheRecord Record,
ReportFormat Format)
1324 string Markdown =
null;
1330 Markdown = Report.Markdown;
1335 if (
string.IsNullOrEmpty(Markdown))
1336 return string.Empty;
1338 Dictionary<string, SortedDictionary<DateTime, StateMachineSample>> ByVariableAndTime =
new Dictionary<string, SortedDictionary<DateTime, StateMachineSample>>();
1339 SortedDictionary<DateTime, StateMachineSample> ByTime =
null;
1342 "Variable",
"Timestamp");
1343 string LastVariable =
null;
1345 DateTime Now = DateTime.UtcNow;
1349 if (ByTime is
null || Sample.
Variable != LastVariable)
1353 if (!ByVariableAndTime.TryGetValue(LastVariable, out ByTime))
1355 ByTime =
new SortedDictionary<DateTime, StateMachineSample>(timestampDescending);
1356 ByVariableAndTime[LastVariable] = ByTime;
1363 foreach (KeyValuePair<
string, SortedDictionary<DateTime, StateMachineSample>> P
in ByVariableAndTime)
1373 Expires = Record.Machine.Expires,
1374 ArchiveOptional = Record.Machine.ArchiveOptional,
1375 ArchiveRequired = Record.Machine.ArchiveRequired
1380 P.
Value.Values.CopyTo(History, 0);
1387 private class TimestampDescending : IComparer<DateTime>
1389 public int Compare(DateTime x, DateTime y)
1391 return y.CompareTo(x);
1395 private static readonly TimestampDescending timestampDescending =
new TimestampDescending();
1399 #region GetStateDiagram
1403 CacheRecord Record = await GetStateMachine(
Token);
1405 return string.Empty;
1407 return await GetStateDiagram(Record, Format);
1410 private static async Task GetStateDiagram(
object Sender,
IqEventArgs e)
1413 if (
string.IsNullOrEmpty(TokenId))
1419 CacheRecord Record = await GetCacheRecord(TokenId, e);
1426 StringBuilder Xml =
new StringBuilder();
1428 Xml.Append(
"<report xmlns='");
1432 Xml.Append(
"</report>");
1437 private static async Task<string> GetStateDiagram(CacheRecord Record,
ReportFormat Format)
1439 StringBuilder Markdown =
new StringBuilder();
1441 Dictionary<string, string> States =
new Dictionary<string, string>();
1442 LinkedList<State> StateNodes =
new LinkedList<State>();
1446 Markdown.AppendLine(
"```uml");
1447 Markdown.AppendLine(
"@startuml");
1448 Markdown.AppendLine();
1449 Markdown.AppendLine(
"skinparam state {");
1450 Markdown.AppendLine(
"\tFontSize 12");
1451 Markdown.AppendLine(
"\tFontStyle Italic");
1452 Markdown.AppendLine(
"\tAttributeFontSize 18");
1453 Markdown.AppendLine(
"\tBackgroundColor<<Action>> LightSalmon");
1454 Markdown.AppendLine(
"\tBackgroundColor<<Calc>> LightBlue");
1455 Markdown.AppendLine(
"\tBackgroundColor<<Current>> LightGreen");
1456 Markdown.AppendLine(
"\tFontStyle<<Current>> Bold, Italic");
1457 Markdown.AppendLine(
"\tAttributeFontStyle<<Current>> Bold");
1458 Markdown.AppendLine(
"\tBorderColor<<Current>> Black");
1459 Markdown.AppendLine(
"}");
1460 Markdown.AppendLine();
1461 Markdown.AppendLine(
"skinparam note {");
1462 Markdown.AppendLine(
"\tBackgroundColor<<Warning>> Salmon");
1463 Markdown.AppendLine(
"}");
1464 Markdown.AppendLine();
1466 Markdown.AppendLine(
"state \"Initialize\" as Init");
1467 Markdown.AppendLine(
"[*] --> Init");
1469 Markdown.Append(
"Init --> ");
1470 Markdown.AppendLine(GetStateLabel(States, Machine.
Root.
StartState));
1474 if (Node is Model.Variable
Variable)
1476 Markdown.Append(
"Init : ");
1480 !
string.IsNullOrEmpty(StateVariable.InitExpression))
1482 Markdown.Append(
":=");
1483 Markdown.Append(EncodeLabel(StateVariable.InitExpression));
1486 Markdown.AppendLine();
1490 StateNodes.AddLast(
State);
1492 Markdown.AppendLine();
1493 Markdown.Append(
"state \"State\" as ");
1494 Markdown.Append(GetStateLabel(States,
State.
Id));
1496 if (
State.
Id == Record.CurrentState.State)
1497 Markdown.Append(
" <<Current>>");
1499 Markdown.Append(
" : ");
1500 Markdown.AppendLine(EncodeLabel(
State.
Id));
1506 s = GetStateLabel(States,
State.
Id);
1510 Markdown.Append(
"note right of ");
1512 Markdown.AppendLine(
" <<Warning>> : No events defined.");
1517 GenerateEventStateDiagram(
Event, Markdown,
State, ref AIndex, s, States, Machine);
1519 Markdown.AppendLine();
1522 Markdown.AppendLine(
"@enduml");
1523 Markdown.AppendLine(
"```");
1528 private static void GenerateEventStateDiagram(
OnEvent Event, StringBuilder Markdown,
1529 State State, ref
int AIndex,
string s, Dictionary<string, string> States,
1540 s2 =
"A" + AIndex.ToString();
1542 Markdown.Append(
"state \"OnLeave Action\" as ");
1543 Markdown.Append(s2);
1544 Markdown.Append(
" <<Action>> : ");
1548 Markdown.Append(
" --> ");
1549 Markdown.Append(s2);
1551 if (!
string.IsNullOrEmpty(s3))
1553 Markdown.Append(
" : ");
1554 Markdown.Append(EncodeLabel(s3));
1558 Markdown.AppendLine();
1563 if (
Event.HasActionReference)
1566 s2 =
"A" + AIndex.ToString();
1568 Markdown.Append(
"state \"Event Action\" as ");
1569 Markdown.Append(s2);
1570 Markdown.Append(
" <<Action>> : ");
1571 Markdown.AppendLine(EncodeLabel(
Event.ActionReferenceDefinition));
1574 Markdown.Append(
" --> ");
1575 Markdown.Append(s2);
1577 if (!
string.IsNullOrEmpty(s3))
1579 Markdown.Append(
" : ");
1580 Markdown.Append(EncodeLabel(s3));
1584 Markdown.AppendLine();
1587 if (
Event.HasFailureState)
1590 else if (
Event.HasFailureState)
1592 if (
string.IsNullOrEmpty(s3))
1603 Actions = NewState.OnEnter;
1604 Termination = NewState.IsDone(Machine);
1609 Termination =
false;
1612 GenerateOnEnterBranch(
Event, Markdown,
State, ref AIndex, s, States,
1613 Actions, s3,
Event.NewStateDefinition, Termination);
1615 if (
Event.HasFailureState)
1619 Actions = FailureState.OnEnter;
1620 Termination = FailureState.IsDone(Machine);
1625 Termination =
false;
1628 GenerateOnEnterBranch(
Event, Markdown,
State, ref AIndex, s, States,
1629 Actions,
"Error",
Event.FailureStateDefinition, Termination);
1633 private static void GenerateOnEnterBranch(
OnEvent Event, StringBuilder Markdown,
1634 State State, ref
int AIndex,
string s, Dictionary<string, string> States,
1635 ActionReference[] Actions,
string s3,
string NewState,
bool Termination)
1639 if (!(Actions is
null) && !Termination)
1644 s2 =
"A" + AIndex.ToString();
1646 Markdown.Append(
"state \"OnEnter Action\" as ");
1647 Markdown.Append(s2);
1648 Markdown.Append(
" <<Action>> : ");
1649 Markdown.AppendLine(EncodeLabel(
Action.ActionReferenceDefinition));
1652 Markdown.Append(
" --> ");
1653 Markdown.Append(s2);
1655 if (!
string.IsNullOrEmpty(s3))
1657 Markdown.Append(
" : ");
1658 Markdown.Append(EncodeLabel(s3));
1662 Markdown.AppendLine();
1671 if (
string.IsNullOrEmpty(NewState))
1674 bool VarState = !States.ContainsKey(NewState);
1676 s2 = GetStateLabel(States, NewState);
1680 Markdown.Append(
"state \"Calc\" as ");
1681 Markdown.Append(s2);
1682 Markdown.Append(
" <<Calc>> : ");
1683 Markdown.AppendLine(EncodeLabel(
Event.NewStateDefinition));
1685 Markdown.Append(
"note right of ");
1686 Markdown.Append(s2);
1687 Markdown.AppendLine(
" <<Warning>> : Variable state, through script.");
1692 Markdown.Append(
" --> ");
1693 Markdown.Append(s2);
1695 if (!
string.IsNullOrEmpty(s3))
1697 Markdown.Append(
" : ");
1698 Markdown.Append(EncodeLabel(s3));
1701 Markdown.AppendLine();
1705 private static string GetStateLabel(Dictionary<string, string> States,
string StateId)
1707 if (!States.TryGetValue(StateId, out
string Id))
1709 int Index = States.Count + 1;
1710 States[StateId] = Id =
"S" + Index.ToString();
1716 private static string EncodeLabel(
string s)
1719 Replace(
"\\",
"\\\\").
1721 Replace(
"\a",
"\\a").
1722 Replace(
"\b",
"\\b").
1723 Replace(
"\f",
"\\f").
1724 Replace(
"\n",
"\\n").
1725 Replace(
"\r",
"\\r").
1726 Replace(
"\t",
"\\t").
1727 Replace(
"\v",
"\\v");
Helps with parsing of commong data types.
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
Contains a markdown document. This markdown document class supports original markdown,...
static string Encode(string s)
Encodes all special characters in a string so that it can be included in a markdown document without ...
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.
Class representing an event.
Event(DateTime Timestamp, EventType Type, string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
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.
static void Error(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an error event.
Implements an HTTP server.
static Variables CreateVariables()
Creates a new collection of variables, that contains access to the global set of variables.
bool IsComponentDomain(CaseInsensitiveString Domain, bool IncludeAlternativeDomains)
Checks if a domain is the component domain, or optionally, an alternative component domain.
Event arguments for IQ queries.
Task IqResult(string Xml, string From)
Returns a response to the current request.
Task IqErrorItemNotFound(XmppAddress From, string ErrorText, string Language)
Returns a item-not-found error.
XmlElement Query
Query element, if found, null otherwise.
XmppAddress To
To address attribute
Task IqErrorServiceUnavailable(XmppAddress From, string ErrorText, string Language)
Returns a service-unavailable error.
Task IqErrorBadRequest(XmppAddress From, string ErrorText, string Language)
Returns a bad-request error.
Contains information about one XMPP address.
bool IsBareJID
If the address is a Bare JID.
CaseInsensitiveString Domain
Domain
CaseInsensitiveString BareJid
Bare JID
CaseInsensitiveString Account
Account
Represents a case-insensitive string.
string Value
String-representation of the case-insensitive string. (Representation is case sensitive....
string LowerCase
Lower-case representation of the case-insensitive string.
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
override string ToString()
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static Task< IEnumerable< object > > FindDelete(string Collection, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
static async Task Delete(object Object)
Deletes an object in the database.
static Task< IEnumerable< object > > Find(string Collection, params string[] SortOrder)
Finds objects in a given collection.
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
This filter selects objects that have a named field equal to a given value.
This filter selects objects that have a named field lesser than a given value.
Event arguments for database object events.
Implements an in-memory cache.
Static class that dynamically manages types and interfaces available in the runtime environment.
static object Instantiate(Type Type, params object[] Arguments)
Returns an instance of the type Type . If one needs to be created, it is. If the constructor requires...
static Type[] GetTypesImplementingInterface(string InterfaceFullName)
Gets all types implementing a given interface.
Class that keeps track of events and timing.
bool TryGetNote(int Index, out object Note)
Tries to get a note from the profile.
Profiler()
Class that keeps track of events and timing.
string ExportPlantUml(TimeUnit TimeUnit)
Exports events to PlantUML.
int NoteCount
Number of notes added.
void Start()
Starts measuring time.
Represents a named semaphore, i.e. an object, identified by a name, that allows single concurrent wri...
Static class of application-wide semaphores that can be used to order access to editable objects.
static async Task< Semaphore > BeginWrite(string Key)
Waits until the semaphore identified by Key is ready for writing. Each call to BeginWrite must be fo...
Script runtime exception.
Class managing a script expression.
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Contains information about a variable.
object ValueObject
Object Value of variable.
string Name
Name of variable.
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
Corresponds to a privilege in the system.
Corresponds to a user in the system.
bool HasPrivilege(string Privilege)
If the user has a given privilege.
Maintains the collection of all users in the system.
static async Task< User > GetUser(string UserName, bool CreateIfNew)
Gets the User object corresponding to a User Name.
Manages eDaler on accounts connected to the broker.
Abstract base class for eDaler URIs
CaseInsensitiveString ContractCondition
Optional Contract defining conditions that must be met before payment can be realized....
decimal TotalAmount
Total amount: Amount+AmountExtra
byte[] EncryptedMessage
Encrypted message for recipient. If EncryptionPublicKey is null, the message is just UTF-8 encoded.
decimal? AmountExtra
Any extra amount
byte[] EncryptionPublicKey
Sender public key used to generate the shared secret to encrypt the message for the recipient....
Provisioning and registry service component.
Event raised when a token has been destroyed.
A text note logged on the token from an external source.
An xml note logged on the token from an external source.
A text note logged on the token.
An xml note logged on the token.
Abstract base class for token events.
Event raised when a token has been transferred.
Marketplace processor, brokering sales of items via tenders and offers defined in smart contracts.
string Definition
M2M definition of token, in XML, from the original creation contract.
string DefinitionNamespace
Namespace of M2M definition of token.
CaseInsensitiveString TrustProviderJid
JID of Trust Provider, asserting claims in the token.
CaseInsensitiveString CreationContract
ID of contract that details the creation of the token.
CaseInsensitiveString MachineId
State Machine ID, if any
CaseInsensitiveString TrustProvider
Trust Provider, asserting claims in the token.
CaseInsensitiveString TokenId
Token ID
Class representing the current state of a state machine.
bool IsRunning
If state-machine is running.
CurrentStateVariable[] VariableValues
Current variable values.
bool HasEnded
If state-machine has ended.
DateTime Expires
When state-machine expires
Variables GetVariables(StateMachine Machine)
Gets a new variable collection containing the current state variables.
string State
ID of current state in state-machine. Empty State = State-machine has ended.
CurrentState()
Class representing the current state of a state machine.
Class representing a persisted state-machine variable value.
Abstract base class for cached event handlers.
static async Task< CachedEventHandler[]> GetEventHandlers(string EventType)
Gets registered event handlers of a given event type.
async Task RemoveFromCache()
Removes the event handler from the cache.
Abstract base class for persisted state-machine event handlers.
string State
ID of state in state-machine to which the event handler belongs.
string StateMachineId
ID of State-Machine.
int EventIndex
Zero-based index of event handler in state.
Event handler for owner events.
Abstract base class for payment event handlerss.
string RemoteVariable
Optional repote partty variable.
string AmountExtraVariable
Optional amount extra variable.
string ReferenceVariable
Optional reference variable.
string AmountVariable
Optional amount variable.
string ConditionVariable
Optional condition variable.
string AmountTotalVariable
Optional amount total variable.
string CurrencyVariable
Optional currency variable.
Event handler for timepoint events.
Event handler for token note events.
string PersonalVariable
Optional personal variable.
string NoteVariable
Optional note variable.
string SourceVariable
Optional source variable.
string Privilege
Privilege required from external party.
Event handler for token transfer events.
string ValueVariable
Optional value variable.
string SellerVariable
Optional seller variable.
string BuyerVariable
Optional buyer variable.
string ContractVariable
Optional contract variable.
string AmountVariable
Optional amount variable.
string CurrencyVariable
Optional currency variable.
Represents an action definition.
Abstract base class for nodes referencing an action.
string ActionReferenceDefinition
Action Reference
Contains information required for evaluating script in a state-machine.
StateMachine Machine
Reference to state-machine definition.
Event raised when an external text note has been logged on the token corresponding to the state-machi...
Event raised when an external XML note has been logged on the token corresponding to the state-machin...
Event raised when a payment has been received.
Event raised when a payment has been sent.
Event raised when a text note has been logged on the token corresponding to the state-machine.
Event raised when the associated token is transferred to a new owner.
Event raised when an XML note has been logged on the token corresponding to the state-machine.
Abstract base class for timed State-Machine event nodes.
async Task ReregisterOnStart(TimepointEventHandler Handler)
Re-registers the event on module start.
Contains a report over the history of the state-machine.
Contains a report over the present state of the state-machine.
IStateMachineNode[] ChildNodes
Child nodes, if available. Null if no children.
Root of the State-Machine definition
string StartState
Start State of state-machine.
Action executed when entering a state.
Action executed when entering a state.
Represents an action definition.
OnLeave[] OnLeave
Events raised when leaving the state.
OnEvent[] OnEvent
Events that can be raised when in the state.
Class representing a state machine.
StateMachineRoot Root
Root of State-Machine model.
bool TryGetState(string Id, out State State)
Tries to get a state.
Duration? ArchiveRequired
Duration after which token expires, the token is required to be archived.
void IndexElements()
Indexes all elements in the state-machine.
async Task<(CurrentState, EvaluationArguments)> CreateCurrentState(Token Token, LegalComponent Legal, EDalerComponent EDaler, Profiler Profiler)
Starts processing of the state-machine.
static async Task GoToState(string StateId, EvaluationArguments Arguments)
Goes to a new state.
CaseInsensitiveString CreatorTokenId
ID of token that created the state-machine.
async Task Start(EvaluationArguments Arguments)
Starts the processing of the state-machine.
string ObjectId
Object ID of state machine.
CaseInsensitiveString StateMachineId
ID of State Machine.
void CheckReferences(Token Token)
Indexes all elements in the state-machine.
static async Task EvaluationComplete(EvaluationArguments Arguments)
Method called when current evaluation has been completed, and new states need to be persisted.
DateTime Expires
When state-machine expires
static async Task CheckConditionalEvents(EvaluationArguments Arguments)
Checks conditional events.
static async Task UnregisterEventHandlers(OnEvent[] Events, EvaluationArguments Arguments)
Unregisters event handlers for the current state.
static StateMachine Parse(XmlDocument Xml, Token Token)
Parses the XML representation of a State Machine.
static StateMachine Parse(Token Token)
Parses the XML representation of a State Machine.
const string StateMachineDefinition
Local name of state-machine definition
const string StateMachineNamespace
https://paiwise.tagroot.io/Schema/StateMachines.xsd
static StateMachine Parse(string Xml, Token Token)
Parses the XML representation of a State Machine.
static StateMachine Parse(XmlElement Xml, Token Token)
Parses the XML representation of a State Machine.
Class representing a sample of a state machine variable over time.
DateTime Timestamp
Timestamp of sample
string StateMachineId
ID of State-Machine.
object Value
Sampled value
string Variable
ID of State-Machine.
Basic interface for a user.
Interface for State-Machine nodes
string LocalName
Local name
IStateMachineNode[] ChildNodes
Child nodes, if available. Null if no children.
TimeUnit
Options for presenting time in reports.
ProfilerThreadType
Type of profiler thread.
ReportFormat
Desired report format
Represents a duration value, as defined by the xsd:duration data type: http://www....