2using System.Collections.Generic;
3using System.Threading.Tasks;
16 private readonly DateTime created = DateTime.Now;
17 private readonly DateTime expires;
18 private readonly
string[] privileges;
19 private readonly
string userVariable;
20 private readonly
string resource;
21 private string[] tabIds =
null;
22 private DateTime tabIdTimestamp = DateTime.MinValue;
33 public WebEventSink(
string SinkId,
string PageResource, TimeSpan MaxLife,
string UserVariable, params
string[] Privileges)
36 this.expires = DateTime.Now.Add(MaxLife);
37 this.resource = PageResource;
39 this.userVariable = UserVariable;
40 this.privileges = Privileges;
51 DateTime Now = DateTime.Now;
53 if ((Now - this.tabIdTimestamp).TotalSeconds > 2 || this.tabIds is
null || this.tabIds.Length == 0)
56 this.tabIdTimestamp = Now;
59 Dictionary<string, object>[] Tags;
66 Tags =
new Dictionary<string, object>[c];
68 for (i = 0; i < c; i++)
70 Tags[i] =
new Dictionary<string, object>()
78 string Data =
JSON.
Encode(
new KeyValuePair<string, object>[]
81 new KeyValuePair<string, object>(
"time",
Event.
Timestamp.TimeOfDay.ToString()),
82 new KeyValuePair<string, object>(
"type",
Event.
Type.ToString()),
83 new KeyValuePair<string, object>(
"level",
Event.
Level.ToString()),
85 new KeyValuePair<string, object>(
"object",
Event.
Object),
86 new KeyValuePair<string, object>(
"actor",
Event.
Actor),
87 new KeyValuePair<string, object>(
"module",
Event.
Module),
89 new KeyValuePair<string, object>(
"message",
Event.
Message),
91 new KeyValuePair<string, object>(
"tags", Tags)
94 int Tabs = await
ClientEvents.
PushEvent(this.tabIds,
"NewEvent", Data,
true, this.userVariable, this.privileges);
96 if (Now >= this.expires || (Tabs <= 0 && (Now - this.created).TotalSeconds >= 5))
98 await
ClientEvents.
PushEvent(this.tabIds,
"SinkClosed",
string.Empty,
false, this.userVariable, this.privileges);
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
Helps with common XML-related tasks.
static string Encode(string s)
Encodes a string for use in XML.
Class representing an event.
string Message
Free-text event message.
EventType Type
Type of event.
string Object
Object related to the event.
EventLevel Level
Event Level.
string Actor
Actor responsible for the action causing the event.
string Module
Module where the event is reported.
DateTime Timestamp
Timestamp of event.
KeyValuePair< string, object >[] Tags
Variable set of tags providing event-specific information.
string EventId
Computer-readable Event ID identifying type of even.
string Facility
Facility can be either a facility in the network sense or in the system sense.
string StackTrace
Stack Trace of event.
Base class for event sinks.
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 bool Unregister(IEventSink EventSink)
Unregisters an event sink from the event log.
virtual void Dispose()
IDisposable.Dispose()
The ClientEvents class allows applications to push information asynchronously to web clients connecte...
static string[] GetTabIDsForLocation(string Location)
Gets the Tab IDs of all tabs that display a particular resource.
static Task< int > PushEvent(string[] TabIDs, string Type, object Data)
Puses an event to a set of Tabs, given their Tab IDs.
Sending events to the corresponding web page(s).
override async Task Queue(Event Event)
Queues an event to be output.
WebEventSink(string SinkId, string PageResource, TimeSpan MaxLife, string UserVariable, params string[] Privileges)
Sending sniffer events to the corresponding web page(s).