Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
EventsRoot.cs
1using System;
4using System.Threading.Tasks;
5using Waher.Events;
8using Waher.Reports;
10
12{
17 {
18 private readonly List<ISniffer> sniffers = new List<ISniffer>();
19 private ISniffer[] sniffersStatic = Array.Empty<ISniffer>();
20 private bool hasSniffers = false;
21
25 public EventsRoot()
26 : base("Events", null)
27 {
28 }
29
34 public override Task<string> GetTypeNameAsync(Language Language)
35 {
36 return Language.GetStringAsync(typeof(XmppServerModule), 43, "Events");
37 }
38
42 public static async Task RegisterReports()
43 {
44 EventsRoot Root = new EventsRoot();
45 new EventStatisticsNode(Root);
46 new SearchEventLogNode(Root);
47
49 }
50
51 #region ICommunicationLayer
52
57 public bool DecoupledEvents => false;
58
63 public void Add(ISniffer Sniffer)
64 {
65 lock (this.sniffers)
66 {
67 if (!this.sniffers.Contains(Sniffer))
68 {
69 Log.Register(new EventSinkToSniffer(Sniffer));
70 this.sniffers.Add(Sniffer);
71 this.sniffersStatic = this.sniffers.ToArray();
72 this.hasSniffers = true;
73 }
74 }
75 }
76
81 public void AddRange(IEnumerable<ISniffer> Sniffers)
82 {
83 foreach (ISniffer Sniffer in Sniffers)
84 this.Add(Sniffer);
85 }
86
92 public bool Remove(ISniffer Sniffer)
93 {
94 lock (this.sniffers)
95 {
96 if (!this.sniffers.Remove(Sniffer))
97 return false;
98
99 this.sniffersStatic = this.sniffers.ToArray();
100 this.hasSniffers = this.sniffers.Count > 0;
101 }
102
103 foreach (IEventSink Sink in Log.Sinks)
104 {
106 EventSinkToSniffer.Sniffer == Sniffer)
107 {
108 Log.Unregister(Sink);
109 return true;
110 }
111 }
112
113 return false;
114 }
115
119 public ISniffer[] Sniffers => this.sniffersStatic;
120
124 public bool HasSniffers => this.hasSniffers;
125
130 public IEnumerator<ISniffer> GetEnumerator()
131 {
132 return (IEnumerator<ISniffer>)this.sniffersStatic.GetEnumerator();
133 }
134
139 IEnumerator IEnumerable.GetEnumerator()
140 {
141 lock (this.sniffers)
142 {
143 return this.sniffersStatic.GetEnumerator();
144 }
145 }
146
151 public void ReceiveBinary(int Count)
152 {
153 if (this.hasSniffers)
154 {
155 foreach (ISniffer Sniffer in this.sniffersStatic)
156 Sniffer.ReceiveBinary(Count);
157 }
158 }
159
166 public void ReceiveBinary(bool ConstantBuffer, byte[] Data)
167 {
168 if (this.hasSniffers)
169 {
170 foreach (ISniffer Sniffer in this.sniffersStatic)
171 Sniffer.ReceiveBinary(ConstantBuffer, Data);
172 }
173 }
174
183 public void ReceiveBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
184 {
185 if (this.hasSniffers)
186 {
187 foreach (ISniffer Sniffer in this.sniffersStatic)
188 Sniffer.ReceiveBinary(ConstantBuffer, Data, Offset, Count);
189 }
190 }
191
196 public void TransmitBinary(int Count)
197 {
198 if (this.hasSniffers)
199 {
200 foreach (ISniffer Sniffer in this.sniffersStatic)
201 Sniffer.TransmitBinary(Count);
202 }
203 }
204
211 public void TransmitBinary(bool ConstantBuffer, byte[] Data)
212 {
213 if (this.hasSniffers)
214 {
215 foreach (ISniffer Sniffer in this.sniffersStatic)
216 Sniffer.TransmitBinary(ConstantBuffer, Data);
217 }
218 }
219
228 public void TransmitBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
229 {
230 if (this.hasSniffers)
231 {
232 foreach (ISniffer Sniffer in this.sniffersStatic)
233 Sniffer.TransmitBinary(ConstantBuffer, Data, Offset, Count);
234 }
235 }
236
241 public void ReceiveText(string Text)
242 {
243 if (this.hasSniffers)
244 {
245 foreach (ISniffer Sniffer in this.sniffersStatic)
246 Sniffer.ReceiveText(Text);
247 }
248 }
249
254 public void TransmitText(string Text)
255 {
256 if (this.hasSniffers)
257 {
258 foreach (ISniffer Sniffer in this.sniffersStatic)
259 Sniffer.TransmitText(Text);
260 }
261 }
262
267 public void Information(string Comment)
268 {
269 if (this.hasSniffers)
270 {
271 foreach (ISniffer Sniffer in this.sniffersStatic)
272 Sniffer.Information(Comment);
273 }
274 }
275
280 public void Warning(string Warning)
281 {
282 if (this.hasSniffers)
283 {
284 foreach (ISniffer Sniffer in this.sniffersStatic)
285 Sniffer.Warning(Warning);
286 }
287 }
288
293 public void Error(string Error)
294 {
295 if (this.hasSniffers)
296 {
297 foreach (ISniffer Sniffer in this.sniffersStatic)
298 Sniffer.Error(Error);
299 }
300 }
301
306 public void Exception(Exception Exception)
307 {
308 if (this.hasSniffers)
309 {
310 foreach (ISniffer Sniffer in this.sniffersStatic)
311 Sniffer.Exception(Exception);
312 }
313 }
314
319 public void Exception(string Exception)
320 {
321 if (this.hasSniffers)
322 {
323 foreach (ISniffer Sniffer in this.sniffersStatic)
324 Sniffer.Exception(Exception);
325 }
326 }
327
333 public void ReceiveBinary(DateTime Timestamp, int Count)
334 {
335 if (this.hasSniffers)
336 {
337 foreach (ISniffer Sniffer in this.sniffersStatic)
338 Sniffer.ReceiveBinary(Timestamp, Count);
339 }
340 }
341
349 public void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
350 {
351 if (this.hasSniffers)
352 {
353 foreach (ISniffer Sniffer in this.sniffersStatic)
354 Sniffer.ReceiveBinary(Timestamp, ConstantBuffer, Data);
355 }
356 }
357
367 public void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
368 {
369 if (this.hasSniffers)
370 {
371 foreach (ISniffer Sniffer in this.sniffersStatic)
372 Sniffer.ReceiveBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
373 }
374 }
375
381 public void TransmitBinary(DateTime Timestamp, int Count)
382 {
383 if (this.hasSniffers)
384 {
385 foreach (ISniffer Sniffer in this.sniffersStatic)
386 Sniffer.TransmitBinary(Timestamp, Count);
387 }
388 }
389
397 public void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
398 {
399 if (this.hasSniffers)
400 {
401 foreach (ISniffer Sniffer in this.sniffersStatic)
402 Sniffer.TransmitBinary(Timestamp, ConstantBuffer, Data);
403 }
404 }
405
415 public void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
416 {
417 if (this.hasSniffers)
418 {
419 foreach (ISniffer Sniffer in this.sniffersStatic)
420 Sniffer.TransmitBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
421 }
422 }
423
429 public void ReceiveText(DateTime Timestamp, string Text)
430 {
431 if (this.hasSniffers)
432 {
433 foreach (ISniffer Sniffer in this.sniffersStatic)
434 Sniffer.ReceiveText(Timestamp, Text);
435 }
436 }
437
443 public void TransmitText(DateTime Timestamp, string Text)
444 {
445 if (this.hasSniffers)
446 {
447 foreach (ISniffer Sniffer in this.sniffersStatic)
448 Sniffer.TransmitText(Timestamp, Text);
449 }
450 }
451
457 public void Information(DateTime Timestamp, string Comment)
458 {
459 if (this.hasSniffers)
460 {
461 foreach (ISniffer Sniffer in this.sniffersStatic)
462 Sniffer.Information(Timestamp, Comment);
463 }
464 }
465
471 public void Warning(DateTime Timestamp, string Warning)
472 {
473 if (this.hasSniffers)
474 {
475 foreach (ISniffer Sniffer in this.sniffersStatic)
476 Sniffer.Warning(Timestamp, Warning);
477 }
478 }
479
485 public void Error(DateTime Timestamp, string Error)
486 {
487 if (this.hasSniffers)
488 {
489 foreach (ISniffer Sniffer in this.sniffersStatic)
490 Sniffer.Error(Timestamp, Error);
491 }
492 }
493
499 public void Exception(DateTime Timestamp, string Exception)
500 {
501 if (this.hasSniffers)
502 {
503 foreach (ISniffer Sniffer in this.sniffersStatic)
504 Sniffer.Exception(Timestamp, Exception);
505 }
506 }
507
513 public void Exception(DateTime Timestamp, Exception Exception)
514 {
515 if (this.hasSniffers)
516 {
517 foreach (ISniffer Sniffer in this.sniffersStatic)
518 Sniffer.Exception(Timestamp, Exception);
519 }
520 }
521
522 #endregion
523 }
524}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:14
static IEventSink[] Sinks
Registered sinks.
Definition: Log.cs:132
static void Register(IEventSink EventSink)
Registers an event sink with the event log. Call Unregister(IEventSink) to unregister it,...
Definition: Log.cs:30
static bool Unregister(IEventSink EventSink)
Unregisters an event sink from the event log.
Definition: Log.cs:47
Defines the Reports data source. This data source contains a tree structure of reports published by d...
static async Task< bool > RegisterRootNode(ReportNode ReportRoot)
Registers a new report root node.
Contains information about a language.
Definition: Language.cs:17
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Definition: Language.cs:209
Event sink that forwards logged events to a sniffer.
bool Remove(ISniffer Sniffer)
Removes a sniffer, if registered.
Definition: EventsRoot.cs:92
void Exception(DateTime Timestamp, Exception Exception)
Called to inform the viewer of an exception state.
Definition: EventsRoot.cs:513
void Error(DateTime Timestamp, string Error)
Called to inform the viewer of an error state.
Definition: EventsRoot.cs:485
void ReceiveBinary(DateTime Timestamp, int Count)
Called when binary data has been received.
Definition: EventsRoot.cs:333
void TransmitText(string Text)
Called when text has been transmitted.
Definition: EventsRoot.cs:254
void Information(DateTime Timestamp, string Comment)
Called to inform the viewer of something.
Definition: EventsRoot.cs:457
EventsRoot()
Root node of Events report folder.
Definition: EventsRoot.cs:25
void TransmitText(DateTime Timestamp, string Text)
Called when text has been transmitted.
Definition: EventsRoot.cs:443
void ReceiveText(DateTime Timestamp, string Text)
Called when text has been received.
Definition: EventsRoot.cs:429
void Warning(string Warning)
Called to inform the viewer of a warning state.
Definition: EventsRoot.cs:280
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
Definition: EventsRoot.cs:397
void ReceiveBinary(int Count)
Called when binary data has been received.
Definition: EventsRoot.cs:151
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
Definition: EventsRoot.cs:415
void Add(ISniffer Sniffer)
Adds a sniffer to the node.
Definition: EventsRoot.cs:63
bool DecoupledEvents
If events raised from the communication layer are decoupled, i.e. executed in parallel with the sourc...
Definition: EventsRoot.cs:57
void Information(string Comment)
Called to inform the viewer of something.
Definition: EventsRoot.cs:267
void AddRange(IEnumerable< ISniffer > Sniffers)
Adds a range of sniffers to the node.
Definition: EventsRoot.cs:81
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been received.
Definition: EventsRoot.cs:349
void ReceiveBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
Definition: EventsRoot.cs:183
void ReceiveBinary(bool ConstantBuffer, byte[] Data)
Called when binary data has been received.
Definition: EventsRoot.cs:166
void TransmitBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
Definition: EventsRoot.cs:228
void TransmitBinary(int Count)
Called when binary data has been transmitted.
Definition: EventsRoot.cs:196
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
Definition: EventsRoot.cs:367
void ReceiveText(string Text)
Called when text has been received.
Definition: EventsRoot.cs:241
void Warning(DateTime Timestamp, string Warning)
Called to inform the viewer of a warning state.
Definition: EventsRoot.cs:471
void Exception(Exception Exception)
Called to inform the viewer of an exception state.
Definition: EventsRoot.cs:306
IEnumerator< ISniffer > GetEnumerator()
Returns an enumerator that iterates through the collection.
Definition: EventsRoot.cs:130
void TransmitBinary(DateTime Timestamp, int Count)
Called when binary data has been transmitted.
Definition: EventsRoot.cs:381
static async Task RegisterReports()
Registers protocol reports.
Definition: EventsRoot.cs:42
void Error(string Error)
Called to inform the viewer of an error state.
Definition: EventsRoot.cs:293
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
Definition: EventsRoot.cs:34
void TransmitBinary(bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
Definition: EventsRoot.cs:211
bool HasSniffers
If there are sniffers registered on the object.
Definition: EventsRoot.cs:124
void Exception(string Exception)
Called to inform the viewer of an exception state.
Definition: EventsRoot.cs:319
void Exception(DateTime Timestamp, string Exception)
Called to inform the viewer of an exception state.
Definition: EventsRoot.cs:499
Abstract base class for server report folders, requiring admin privileges to be seen and executed.
Service Module hosting the XMPP broker and its components.
Interface for all event sinks.
Definition: IEventSink.cs:9
Interface for observable classes implementing communication protocols.
Interface for sniffers. Sniffers can be added to ICommunicationLayer classes to eavesdrop on communic...
Definition: ISniffer.cs:10
void TransmitText(string Text)
Called when text has been transmitted.
void ReceiveText(string Text)
Called when text has been received.
void Information(string Comment)
Called to inform the viewer of something.
void Error(string Error)
Called to inform the viewer of an error state.
void Exception(string Exception)
Called to inform the viewer of an exception state.
void ReceiveBinary(int Count)
Called when binary data has been received.
void TransmitBinary(int Count)
Called when binary data has been transmitted.
void Warning(string Warning)
Called to inform the viewer of a warning state.