2using System.Threading.Tasks;
13 private readonly
INode nodeReference;
15 private readonly
string commandId;
16 private readonly
string queryId;
17 private readonly
object state;
18 private bool isStarted =
false;
19 private bool isAborted =
false;
20 private bool isDone =
false;
21 private int seqNr = 0;
22 private int nrSectionsBegun = 0;
23 private int nrSectionsEnded = 0;
24 private int nrTablesStarted = 0;
25 private int nrTablesCompleted = 0;
26 private int nrObjectsReported = 0;
27 private int nrMessagesReported = 0;
28 private int nrRecordsReported = 0;
29 private bool hasTitle =
false;
42 this.commandId = CommandId;
43 this.queryId = QueryId;
61 public object State => this.state;
135 int Result = this.nrSectionsBegun;
136 Result += this.nrSectionsEnded;
138 Result += this.nrTablesCompleted;
139 Result += this.nrObjectsReported;
140 Result += this.nrMessagesReported;
141 Result += this.nrRecordsReported;
172 this.isAborted =
true;
181 this.isAborted =
true;
182 return this.Raise(this.
OnAborted, e,
false);
185 return Task.CompletedTask;
188 private async Task Raise(EventHandlerAsync<QueryEventArgs> Callback, QueryEventArgs e,
bool CheckTerminated)
190 if (CheckTerminated && (this.isAborted || this.isDone))
193 await Callback.Raise(
this, e);
199 public event EventHandlerAsync<QueryEventArgs>
OnAborted =
null;
207 return Task.CompletedTask;
209 this.isStarted =
true;
217 this.isStarted =
true;
218 return this.Raise(this.
OnStarted, e,
false);
221 return Task.CompletedTask;
227 public event EventHandlerAsync<QueryEventArgs>
OnStarted =
null;
246 return this.Raise(this.
OnDone, e,
false);
249 return Task.CompletedTask;
255 public event EventHandlerAsync<QueryEventArgs>
OnDone =
null;
265 this.nrTablesStarted++;
271 this.nrTablesStarted++;
275 private async Task Raise(EventHandlerAsync<QueryNewTableEventArgs> Callback, QueryNewTableEventArgs e)
277 if (!this.isAborted && !this.isDone)
278 await Callback.Raise(
this, e);
284 public event EventHandlerAsync<QueryNewTableEventArgs>
OnNewTable =
null;
293 this.nrRecordsReported += Records.Length;
299 this.nrRecordsReported += e.
Records.Length;
303 private async Task Raise(EventHandlerAsync<QueryNewRecordsEventArgs> Callback, QueryNewRecordsEventArgs e)
305 if (!this.isAborted && !this.isDone)
306 await Callback.Raise(
this, e);
312 public event EventHandlerAsync<QueryNewRecordsEventArgs>
OnNewRecords =
null;
320 this.nrTablesCompleted++;
326 this.nrTablesCompleted++;
330 private async Task Raise(EventHandlerAsync<QueryTableEventArgs> Callback, QueryTableEventArgs e)
332 if (!this.isAborted && !this.isDone)
333 await Callback.Raise(
this, e);
339 public event EventHandlerAsync<QueryTableEventArgs>
OnTableDone =
null;
347 this.nrObjectsReported++;
353 this.nrObjectsReported++;
357 private async Task Raise(EventHandlerAsync<QueryObjectEventArgs> Callback, QueryObjectEventArgs e)
359 if (!this.isAborted && !this.isDone)
360 await Callback.Raise(
this, e);
366 public event EventHandlerAsync<QueryObjectEventArgs>
OnNewObject =
null;
396 this.nrMessagesReported++;
402 this.nrMessagesReported++;
406 private async Task Raise(EventHandlerAsync<QueryMessageEventArgs> Callback, QueryMessageEventArgs e)
408 if (!this.isAborted && !this.isDone)
409 await Callback.Raise(
this, e);
415 public event EventHandlerAsync<QueryMessageEventArgs>
OnMessage =
null;
423 this.hasTitle =
true;
429 this.hasTitle =
true;
430 return this.Raise(this.
OnTitle, e);
433 private async Task Raise(EventHandlerAsync<QueryTitleEventArgs> Callback, QueryTitleEventArgs e)
435 if (!this.isAborted && !this.isDone)
436 await Callback.Raise(
this, e);
442 public event EventHandlerAsync<QueryTitleEventArgs>
OnTitle =
null;
455 return this.Raise(this.
OnStatus, e);
458 private async Task Raise(EventHandlerAsync<QueryStatusEventArgs> h, QueryStatusEventArgs e)
460 if (!this.isAborted && !this.isDone)
461 await h.Raise(
this, e);
467 public event EventHandlerAsync<QueryStatusEventArgs>
OnStatus =
null;
476 this.nrSectionsBegun++;
482 this.nrSectionsBegun++;
497 this.nrSectionsEnded++;
503 this.nrSectionsEnded++;
512 #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 Information(DateTime Timestamp, string Comment)
Called to inform the viewer of something.
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.
Task 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.
int NrObjectsReported
Number of objects reported.
EventHandlerAsync< QueryEventArgs > OnDone
Event raised when query has been completed.
Task Exception(DateTime Timestamp, string 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.
INode NodeReference
Node reference.
bool HasReported
If anything has been reported.
virtual async Task Abort()
Aborts the query.
bool IsStarted
If the query has been started.
Query(string CommandId, string QueryId, object State, Language Language, INode NodeReference)
Class handling the reception of data from a query.
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
Task Exception(string Exception)
Called to inform the viewer of an exception state.
Task Exception(Exception Exception)
Called to inform the viewer of an exception 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.
bool IsAborted
If the query is aborted.
int SequenceNumber
Curernt sequence number counter.
Task Warning(DateTime Timestamp, string Warning)
Called to inform the viewer of a warning state.
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...
Task Exception(DateTime Timestamp, Exception Exception)
Called to inform the viewer of an exception state.
EventHandlerAsync< QueryStatusEventArgs > OnStatus
Event raised when the current status changes.
Task Warning(string Warning)
Called to inform the viewer of a warning state.
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.
Task LogMessage(Exception Exception)
Logs an Exception as a query message.
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...
Task Error(DateTime Timestamp, string Error)
Called to inform the viewer of an error state.
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.
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.
Task Information(string Comment)
Called to inform the viewer of something.
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.
Interface for classes that can be observed.
Interface for nodes that are published through the concentrator interface.
QueryEventLevel
Event level.
QueryEventType
Query event type.