2using System.Threading.Tasks;
13 private readonly
INode nodeReference;
16 private readonly
string commandId;
17 private readonly
string queryId;
18 private readonly
object state;
19 private bool isStarted =
false;
20 private bool isAborted =
false;
21 private bool isDone =
false;
22 private int seqNr = 0;
23 private int nrSectionsBegun = 0;
24 private int nrSectionsEnded = 0;
25 private int nrTablesStarted = 0;
26 private int nrTablesCompleted = 0;
27 private int nrObjectsReported = 0;
28 private int nrMessagesReported = 0;
29 private int nrRecordsReported = 0;
30 private bool hasTitle =
false;
45 this.commandId = CommandId;
46 this.queryId = QueryId;
65 public object State => this.state;
144 int Result = this.nrSectionsBegun;
145 Result += this.nrSectionsEnded;
147 Result += this.nrTablesCompleted;
148 Result += this.nrObjectsReported;
149 Result += this.nrMessagesReported;
150 Result += this.nrRecordsReported;
181 this.isAborted =
true;
190 this.isAborted =
true;
191 return this.Raise(this.
OnAborted, e,
false);
194 return Task.CompletedTask;
197 private async Task Raise(EventHandlerAsync<QueryEventArgs> Callback, QueryEventArgs e,
bool CheckTerminated)
199 if (CheckTerminated && (this.isAborted || this.isDone))
202 await Callback.Raise(
this, e);
208 public event EventHandlerAsync<QueryEventArgs>
OnAborted =
null;
216 return Task.CompletedTask;
218 this.isStarted =
true;
226 this.isStarted =
true;
227 return this.Raise(this.
OnStarted, e,
false);
230 return Task.CompletedTask;
236 public event EventHandlerAsync<QueryEventArgs>
OnStarted =
null;
255 return this.Raise(this.
OnDone, e,
false);
258 return Task.CompletedTask;
264 public event EventHandlerAsync<QueryEventArgs>
OnDone =
null;
274 this.nrTablesStarted++;
280 this.nrTablesStarted++;
284 private async Task Raise(EventHandlerAsync<QueryNewTableEventArgs> Callback, QueryNewTableEventArgs e)
286 if (!this.isAborted && !this.isDone)
287 await Callback.Raise(
this, e);
293 public event EventHandlerAsync<QueryNewTableEventArgs>
OnNewTable =
null;
302 this.nrRecordsReported += Records.Length;
308 this.nrRecordsReported += e.
Records.Length;
312 private async Task Raise(EventHandlerAsync<QueryNewRecordsEventArgs> Callback, QueryNewRecordsEventArgs e)
314 if (!this.isAborted && !this.isDone)
315 await Callback.Raise(
this, e);
321 public event EventHandlerAsync<QueryNewRecordsEventArgs>
OnNewRecords =
null;
329 this.nrTablesCompleted++;
335 this.nrTablesCompleted++;
339 private async Task Raise(EventHandlerAsync<QueryTableEventArgs> Callback, QueryTableEventArgs e)
341 if (!this.isAborted && !this.isDone)
342 await Callback.Raise(
this, e);
348 public event EventHandlerAsync<QueryTableEventArgs>
OnTableDone =
null;
356 this.nrObjectsReported++;
362 this.nrObjectsReported++;
366 private async Task Raise(EventHandlerAsync<QueryObjectEventArgs> Callback, QueryObjectEventArgs e)
368 if (!this.isAborted && !this.isDone)
369 await Callback.Raise(
this, e);
375 public event EventHandlerAsync<QueryObjectEventArgs>
OnNewObject =
null;
405 this.nrMessagesReported++;
411 this.nrMessagesReported++;
415 private async Task Raise(EventHandlerAsync<QueryMessageEventArgs> Callback, QueryMessageEventArgs e)
417 if (!this.isAborted && !this.isDone)
418 await Callback.Raise(
this, e);
424 public event EventHandlerAsync<QueryMessageEventArgs>
OnMessage =
null;
432 this.hasTitle =
true;
438 this.hasTitle =
true;
439 return this.Raise(this.
OnTitle, e);
442 private async Task Raise(EventHandlerAsync<QueryTitleEventArgs> Callback, QueryTitleEventArgs e)
444 if (!this.isAborted && !this.isDone)
445 await Callback.Raise(
this, e);
451 public event EventHandlerAsync<QueryTitleEventArgs>
OnTitle =
null;
464 return this.Raise(this.
OnStatus, e);
467 private async Task Raise(EventHandlerAsync<QueryStatusEventArgs> h, QueryStatusEventArgs e)
469 if (!this.isAborted && !this.isDone)
470 await h.Raise(
this, e);
476 public event EventHandlerAsync<QueryStatusEventArgs>
OnStatus =
null;
485 this.nrSectionsBegun++;
491 this.nrSectionsBegun++;
506 this.nrSectionsEnded++;
512 this.nrSectionsEnded++;
521 #region ICommunicationLayer
Static class managing the application event log. Applications and services log events on this static ...
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Contains information about a language.
Defines a column in a table.
Base class for all query-related events.
Class handling the reception of data from a query.
Task TableDone(string TableId)
Reports a table as being complete.
int NrTablesStarted
Number of tables started.
EventHandlerAsync< QueryTableEventArgs > OnTableDone
Event raised when a table is completed.
Task EndSection()
Ends a section. Each call to BeginSection(string) must be followed by a call to EndSection().
int NrSectionsBegun
Number of sectios begun.
bool IsDone
If the query is done.
void Error(string Error)
Called to inform the viewer of an error state.
EventHandlerAsync< QueryMessageEventArgs > OnMessage
Event raised when a new message has been received.
int NrTablesCompleted
Number of tables compeleted.
Task NewObject(object Object)
Reports a new object.
int NrRecordsReported
Number of records reported.
void Error(DateTime Timestamp, string Error)
Called to inform the viewer of an error state.
void Warning(DateTime Timestamp, string Warning)
Called to inform the viewer of a warning state.
Query(string CommandId, string QueryId, object State, Language Language, INode NodeReference, RequestOrigin Origin)
Class handling the reception of data from a query.
int NrObjectsReported
Number of objects reported.
EventHandlerAsync< QueryEventArgs > OnDone
Event raised when query has been completed.
void Exception(DateTime Timestamp, Exception Exception)
Called to inform the viewer of an exception state.
EventHandlerAsync< QueryTitleEventArgs > OnBeginSection
Event raised when a new section is created.
EventHandlerAsync< QueryEventArgs > OnEndSection
Event raised when a section is closed.
void Information(string Comment)
Called to inform the viewer of something.
INode NodeReference
Node reference.
bool HasReported
If anything has been reported.
virtual async Task Abort()
Aborts the query.
void Exception(DateTime Timestamp, string Exception)
Called to inform the viewer of an exception state.
bool IsStarted
If the query has been started.
bool HasTitle
If a title has been set
EventHandlerAsync< QueryTitleEventArgs > OnTitle
Event raised when the report title has been set.
int NrTotalItemsReported
Number of items (total) reported.
Language Language
Language of query.
string CommandID
Command ID
void Warning(string Warning)
Called to inform the viewer of a warning state.
EventHandlerAsync< QueryEventArgs > OnStarted
Event raised when the query has been aborted.
EventHandlerAsync< QueryObjectEventArgs > OnNewObject
Event raised when new records are reported for a table.
Task Start()
Starts query execution.
Task NewRecords(string TableId, params Record[] Records)
Reports a new set of records in a table.
int NrSectionsEnded
Number of sectios ended.
RequestOrigin Origin
Origin of request to execute the query.
bool IsAborted
If the query is aborted.
int SequenceNumber
Curernt sequence number counter.
object State
State object.
Task BeginSection(string Header)
Begins a new section. Sections can be nested. Each call to BeginSection(string) must be followed by a...
EventHandlerAsync< QueryStatusEventArgs > OnStatus
Event raised when the current status changes.
Task NewTable(string TableId, string TableName, params Column[] Columns)
Defines a new table in the query output.
Task LogMessage(QueryEventType Type, QueryEventLevel Level, string Body)
Logs a query message.
void Exception(string Exception)
Called to inform the viewer of an exception state.
Task LogMessage(Exception Exception)
Logs an Exception as a query message.
void Information(DateTime Timestamp, string Comment)
Called to inform the viewer of something.
EventHandlerAsync< QueryNewTableEventArgs > OnNewTable
Event raised when a new table has been created.
bool DecoupledEvents
If events raised from the communication layer are decoupled, i.e. executed in parallel with the sourc...
int NrMessagesReported
Number of messages reported.
async Task Done()
Query execution completed.
int NextSequenceNumber()
Gets the next sequence number.
EventHandlerAsync< QueryNewRecordsEventArgs > OnNewRecords
Event raised when new records are reported for a table.
void Exception(Exception Exception)
Called to inform the viewer of an exception state.
EventHandlerAsync< QueryEventArgs > OnAborted
Event raised when the query has been aborted.
Task SetStatus(string Status)
Sets the current status of the query execution.
Task SetTitle(string Title)
Sets the title of the report.
Task LogMessage(QueryEventLevel Level, Exception Exception)
Logs an Exception as a query message.
Base class for all query-related table events.
Base class for all query-related table events.
Base class for all query-related table events.
Event arguments for query title events.
Base class for all query-related table events.
Event arguments for query title events.
Defines a record in a table.
Tokens available in request.
Interface for classes that can be observed.
Interface for nodes that are published through the concentrator interface.
QueryEventLevel
Event level.
QueryEventType
Query event type.