2using System.Collections.Generic;
4using System.Threading.Tasks;
66 : base(
"/ClientEvents")
98 if (
string.IsNullOrEmpty(Request.
SubPath))
101 string Id = Request.
SubPath.Substring(1);
106 lock (requestsByContentID)
108 if (requestsByContentID.TryGetValue(Id, out ContentQueue Queue))
110 if (Queue.Content is
null)
112 Queue.Response = Response;
117 Content = Queue.Content;
118 ContentType = Queue.ContentType;
123 Queue.Content =
null;
124 Queue.ContentType =
null;
127 requestsByContentID.Remove(Id);
131 requestsByContentID[Id] =
new ContentQueue(Id)
142 Response.
SetHeader(
"X-More", More ?
"1" :
"0");
143 Response.ContentType = ContentType;
144 await Response.
Write(Content, 0, Content.Length);
162 if (!(Obj is
string Location))
165 string TabID = Request.
Header[
"X-TabID"];
166 if (
string.IsNullOrEmpty(TabID))
169 TabQueue Queue = Register(Request, Response,
null, Location, TabID);
170 StringBuilder Json =
null;
176 if (!await Queue.SyncObj.TryBeginWrite(10000))
181 if (!(Queue.Queue.First is
null))
183 foreach (
string Event in Queue.Queue)
186 Json =
new StringBuilder(
"[");
194 Queue.Response =
null;
197 Queue.Response = Response;
201 await Queue.SyncObj.EndWrite();
206 timeoutByTabID.Remove(TabID);
209 await Response.
Write(Json.ToString());
214 timeoutByTabID[TabID] = Queue;
219 Uri Uri =
new Uri(Location);
220 string Resource = Uri.LocalPath;
221 (string, string, string)[] Query =
null;
225 if (!
string.IsNullOrEmpty(Uri.Query))
228 if (s.StartsWith(
"?"))
231 string[] Parts = s.Split(
'&');
232 Query =
new (string, string, string)[Parts.Length];
235 foreach (
string Part in Parts)
237 i = Part.IndexOf(
'=');
239 Query[j++] = (Part,
string.Empty,
string.Empty);
242 string s2 = Part.Substring(i + 1);
243 Query[j++] = (Part.Substring(0, i), s2, System.Net.WebUtility.UrlDecode(s2));
248 if (eventsByTabID.TryGetValue(TabID, out TabQueue Queue) &&
249 !
string.IsNullOrEmpty(Queue.SessionID) &&
250 !(Queue.SyncObj is
null))
252 Queue.WebSocket = Socket;
260 TabQueue Queue2 =
new TabQueue(TabID,
HttpSessionID, Session)
267 if (!(Queue is
null))
269 while (!(Queue.Queue.First is
null))
271 Queue2.Queue.AddLast(Queue.Queue.First.Value);
272 Queue.Queue.RemoveFirst();
277 eventsByTabID[TabID] = Queue;
280 lock (locationByTabID)
282 if (!locationByTabID.TryGetValue(TabID, out s) || s != Resource)
283 locationByTabID[TabID] = Resource;
286 lock (tabIdsByLocation)
288 if (!tabIdsByLocation.TryGetValue(Resource, out Dictionary<
string, (
string,
string,
string)[]> TabIds))
290 TabIds =
new Dictionary<string, (string, string, string)[]>();
291 tabIdsByLocation[Resource] = TabIds;
294 TabIds[TabID] = Query;
300 if (!(Session is
null) &&
302 !((UserObject = UserId(UserVariable.ValueObject)) is
null))
306 if (!usersByTabID.TryGetValue(TabID, out
object Obj2) || !Obj2.Equals(UserObject))
307 usersByTabID[TabID] = UserObject;
310 UserType = UserObject.GetType();
314 if (!tabIdsByUser.TryGetValue(UserType, out Dictionary<
object, Dictionary<
string, (
string,
string,
string)[]>> UserObjects))
316 UserObjects =
new Dictionary<object, Dictionary<string, (string, string, string)[]>>();
317 tabIdsByUser[UserType] = UserObjects;
320 if (!UserObjects.TryGetValue(UserObject, out Dictionary<
string, (
string,
string,
string)[]> TabIds))
322 TabIds =
new Dictionary<string, (string, string, string)[]>();
323 UserObjects[UserObject] = TabIds;
326 TabIds[TabID] = Query;
333 if (!usersByTabID.TryGetValue(TabID, out UserObject))
337 if (!(UserObject is
null))
339 UserType = UserObject.GetType();
343 if (tabIdsByUser.TryGetValue(UserType, out Dictionary<
object, Dictionary<
string, (
string,
string,
string)[]>> UserObjects))
345 if (UserObjects.Remove(UserObject) && UserObjects.Count == 0)
346 tabIdsByUser.Remove(UserType);
355 private static object UserId(
object User)
357 if (User is
IUser User2)
358 return User2.UserName;
361 if (GenObj.TryGetFieldValue(
"UserName", out
object UserName))
364 return GenObj.ObjectId;
366 else if (User is Dictionary<string, IElement> ScriptObj)
368 if (ScriptObj.TryGetValue(
"UserName", out
IElement UserName))
369 return UserName.AssociatedObjectValue;
373 else if (User is Dictionary<string, object> JsonObj)
375 if (JsonObj.TryGetValue(
"UserName", out
object UserName))
384 internal static async Task RegisterWebSocket(
WebSocket Socket,
string Location,
string TabID)
387 LinkedList<string> ToSend =
null;
389 if (!await Queue.SyncObj.TryBeginWrite(10000))
394 if (!(Queue.Queue.First is
null))
396 ToSend =
new LinkedList<string>();
398 foreach (
string s2
in Queue.Queue)
406 await Queue.SyncObj.EndWrite();
409 if (!(ToSend is
null))
411 foreach (
string s2
in ToSend)
412 await Socket.
Send(s2, 4096);
416 internal static void Ping(
string TabID)
418 if (eventsByTabID.TryGetValue(TabID, out TabQueue TabQueue) && !
string.IsNullOrEmpty(TabQueue.SessionID))
419 Gateway.HttpServer?.GetSession(TabQueue.SessionID,
false);
422 internal static async Task UnregisterWebSocket(
WebSocket Socket,
string Location,
string TabID)
424 if (eventsByTabID.TryGetValue(TabID, out TabQueue Queue) && Queue.WebSocket == Socket)
426 if (!await Queue.SyncObj.TryBeginWrite(10000))
431 Queue.WebSocket =
null;
435 await Queue.SyncObj.EndWrite();
438 if (Queue.KeepAliveUntil > DateTime.Now)
442 Uri Uri =
new Uri(Location);
443 Remove(TabID, Uri.LocalPath);
454 if (!eventsByTabID.TryGetValue(TabID, out TabQueue Queue))
456 Queue =
new TabQueue(TabID,
string.Empty,
new Variables());
457 eventsByTabID[TabID] = Queue;
460 DateTime Now = DateTime.Now;
464 DateTime CurrentKeepAliveTime = Queue.KeepAliveUntil;
466 if (CurrentKeepAliveTime < KeepAliveUntil)
468 Queue.KeepAliveUntil = KeepAliveUntil;
470 if (CurrentKeepAliveTime == DateTime.MinValue)
478 if (State is
string TabID &&
479 eventsByTabID.TryGetValue(TabID, out TabQueue Queue))
481 DateTime Now = DateTime.Now;
483 if (Queue.KeepAliveUntil < Now)
484 Queue.KeepAliveUntil = DateTime.MinValue;
493 private static readonly Dictionary<string, string> locationByTabID =
new Dictionary<string, string>();
494 private static readonly Dictionary<string, object> usersByTabID =
new Dictionary<string, object>();
495 private static readonly Dictionary<string, Dictionary<string, (string, string, string)[]>> tabIdsByLocation =
496 new Dictionary<
string, Dictionary<
string, (
string,
string,
string)[]>>(StringComparer.OrdinalIgnoreCase);
497 private static readonly Dictionary<Type, Dictionary<object, Dictionary<string, (string, string, string)[]>>> tabIdsByUser =
498 new Dictionary<Type, Dictionary<
object, Dictionary<
string, (
string,
string,
string)[]>>>();
503 Result.Removed += TimeoutCacheItem_Removed;
513 if (!(Response is
null))
517 e.Value.Response =
null;
519 await Response.
Write(
"[{\"type\":\"NOP\"}]");
537 Result.Removed += QueueCacheItem_Removed;
543 TabQueue Queue = e.
Value;
544 string TabID = Queue.TabID;
549 return Task.CompletedTask;
552 private static void Remove(
string TabID,
string Resource)
557 lock (locationByTabID)
559 if (locationByTabID.TryGetValue(TabID, out Location) && (Resource is
null || Location == Resource))
560 locationByTabID.Remove(TabID);
565 if (!(Location is
null))
567 lock (tabIdsByLocation)
569 if (tabIdsByLocation.TryGetValue(Location, out Dictionary<
string, (
string,
string,
string)[]> TabIDs))
571 if (TabIDs.Remove(TabID) && TabIDs.Count == 0)
572 tabIdsByLocation.Remove(Location);
579 if (usersByTabID.TryGetValue(TabID, out User))
580 usersByTabID.Remove(TabID);
587 Type UserType = User.GetType();
591 if (tabIdsByUser.TryGetValue(UserType, out Dictionary<
object, Dictionary<
string, (
string,
string,
string)[]>> UserObjects) &&
592 UserObjects.TryGetValue(User, out Dictionary<
string, (
string,
string,
string)[]> TabIDs))
594 if (TabIDs.Remove(TabID) && TabIDs.Count == 0 &&
595 UserObjects.Remove(User) && UserObjects.Count == 0)
597 tabIdsByUser.Remove(UserType);
607 Result.Removed += ContentCacheItem_Removed;
619 if (!(Response is
null))
622 await Response.
Write(
"Request took too long to complete.");
657 lock (requestsByContentID)
659 if (requestsByContentID.TryGetValue(Id, out ContentQueue Queue))
661 if (Queue.Response is
null)
663 Queue.ContentType = ContentType;
664 Queue.Content = Result;
669 Response = Queue.Response;
672 Queue.Response =
null;
674 requestsByContentID.Remove(Id);
678 Queue =
new ContentQueue(Id)
680 ContentType = ContentType,
685 requestsByContentID[Id] = Queue;
690 Response.
SetHeader(
"X-More", More ?
"1" :
"0");
691 Response.ContentType = ContentType;
692 await Response.
Write(Result, 0, Result.Length);
709 lock (tabIdsByLocation)
711 Result =
new string[tabIdsByLocation.Count];
712 tabIdsByLocation.Keys.CopyTo(Result, 0);
724 List<object> Result =
new List<object>();
728 foreach (KeyValuePair<Type, Dictionary<
object, Dictionary<
string, (
string,
string,
string)[]>>> P in tabIdsByUser)
729 Result.AddRange(P.Value.Keys);
732 return Result.ToArray();
752 public static string[]
GetTabIDsForLocation(
string Location,
string QueryParameter1,
string QueryParameterValue1)
754 return GetTabIDsForLocation(Location,
new KeyValuePair<string, string>(QueryParameter1, QueryParameterValue1));
766 public static string[]
GetTabIDsForLocation(
string Location,
string QueryParameter1,
string QueryParameterValue1,
767 string QueryParameter2,
string QueryParameterValue2)
770 new KeyValuePair<string, string>(QueryParameter1, QueryParameterValue1),
771 new KeyValuePair<string, string>(QueryParameter2, QueryParameterValue2));
780 public static string[]
GetTabIDsForLocation(
string Location, params KeyValuePair<string, string>[] QueryFilter)
794 string QueryParameter1,
string QueryParameterValue1)
796 return GetTabIDsForLocation(Location, IgnoreCase,
new KeyValuePair<string, string>(QueryParameter1, QueryParameterValue1));
810 string QueryParameter1,
string QueryParameterValue1,
811 string QueryParameter2,
string QueryParameterValue2)
814 new KeyValuePair<string, string>(QueryParameter1, QueryParameterValue1),
815 new KeyValuePair<string, string>(QueryParameter2, QueryParameterValue2));
825 public static string[]
GetTabIDsForLocation(
string Location,
bool IgnoreCase, params KeyValuePair<string, string>[] QueryFilter)
827 lock (tabIdsByLocation)
829 if (tabIdsByLocation.TryGetValue(Location, out Dictionary<
string, (
string,
string,
string)[]> TabIDs))
830 return ProcessQueryFilterLocked(TabIDs, QueryFilter, IgnoreCase);
833 if (eventsByTabID.TryGetValue(Location, out TabQueue Queue))
835 return ProcessQueryFilterLocked(
new Dictionary<
string, (
string,
string,
string)[]>()
837 { Location, Queue.Query }
838 }, QueryFilter, IgnoreCase);
841 return new string[0];
851 return GetTabIDsForUser(User,
null,
false,
new KeyValuePair<string, string>[0]);
860 public static string[]
GetTabIDsForUser(
object User, params KeyValuePair<string, string>[] QueryFilter)
874 string QueryParameter1,
string QueryParameterValue1)
876 return GetTabIDsForUser(User, IgnoreCase,
new KeyValuePair<string, string>(QueryParameter1, QueryParameterValue1));
890 string QueryParameter1,
string QueryParameterValue1,
891 string QueryParameter2,
string QueryParameterValue2)
894 new KeyValuePair<string, string>(QueryParameter1, QueryParameterValue1),
895 new KeyValuePair<string, string>(QueryParameter2, QueryParameterValue2));
905 public static string[]
GetTabIDsForUser(
object User,
bool IgnoreCase, params KeyValuePair<string, string>[] QueryFilter)
918 return GetTabIDsForUser(User, Location,
new KeyValuePair<string, string>[0]);
930 string QueryParameter1,
string QueryParameterValue1)
933 new KeyValuePair<string, string>(QueryParameter1, QueryParameterValue1));
947 string QueryParameter1,
string QueryParameterValue1,
948 string QueryParameter2,
string QueryParameterValue2)
951 new KeyValuePair<string, string>(QueryParameter1, QueryParameterValue1),
952 new KeyValuePair<string, string>(QueryParameter2, QueryParameterValue2));
962 public static string[]
GetTabIDsForUser(
object User,
string Location, params KeyValuePair<string, string>[] QueryFilter)
977 string QueryParameter1,
string QueryParameterValue1)
980 new KeyValuePair<string, string>(QueryParameter1, QueryParameterValue1));
995 string QueryParameter1,
string QueryParameterValue1,
996 string QueryParameter2,
string QueryParameterValue2)
999 new KeyValuePair<string, string>(QueryParameter1, QueryParameterValue1),
1000 new KeyValuePair<string, string>(QueryParameter2, QueryParameterValue2));
1011 public static string[]
GetTabIDsForUser(
object User,
string Location,
bool IgnoreCase, params KeyValuePair<string, string>[] QueryFilter)
1013 User = UserId(User);
1014 Type T = User.GetType();
1019 if (tabIdsByUser.TryGetValue(T, out Dictionary<
object, Dictionary<
string, (
string,
string,
string)[]>> UserObjects) &&
1020 UserObjects.TryGetValue(User, out Dictionary<
string, (
string,
string,
string)[]> TabIDs))
1022 Result = ProcessQueryFilterLocked(TabIDs, QueryFilter, IgnoreCase);
1025 return new string[0];
1028 if (
string.IsNullOrEmpty(Location))
1031 List<string> Result2 =
new List<string>();
1033 lock (tabIdsByLocation)
1035 if (tabIdsByLocation.TryGetValue(Location, out Dictionary<
string, (
string,
string,
string)[]> TabIDs))
1037 foreach (
string TabID
in Result)
1039 if (TabIDs.ContainsKey(TabID))
1045 return Result2.ToArray();
1048 private static string[] ProcessQueryFilterLocked(Dictionary<
string, (
string,
string,
string)[]> TabIDs,
1049 KeyValuePair<string, string>[] QueryFilter,
bool IgnoreCase)
1053 if (QueryFilter is
null || QueryFilter.Length == 0)
1055 Result =
new string[TabIDs.Count];
1056 TabIDs.Keys.CopyTo(Result, 0);
1060 List<string> Match =
new List<string>();
1064 foreach (KeyValuePair<
string, (
string,
string,
string)[]> P in TabIDs)
1068 foreach (KeyValuePair<string, string> Q
in QueryFilter)
1070 if (Q.Value is
null)
1074 if (!(P.Value is
null))
1076 foreach ((
string,
string,
string) Q2 in P.Value)
1078 if (Q2.Item1 == Q.Key)
1096 if (!(P.Value is
null))
1098 foreach ((
string,
string,
string) Q2 in P.Value)
1100 if (Q2.Item1 == Q.Key &&
1101 (
string.Compare(Q2.Item2, Q.Value, IgnoreCase) == 0 ||
1102 string.Compare(Q2.Item3, Q.Value, IgnoreCase) == 0))
1122 Result = Match.ToArray();
1135 switch (Locations.Length)
1138 return new string[0];
1144 Dictionary<string, bool> Result =
new Dictionary<string, bool>();
1145 Dictionary<string, (string, string, string)[]> TabIDs;
1147 lock (tabIdsByLocation)
1149 foreach (
string Location
in Locations)
1151 if (tabIdsByLocation.TryGetValue(Location, out TabIDs))
1153 foreach (
string TabID
in TabIDs.Keys)
1154 Result[TabID] =
true;
1159 string[] Result2 =
new string[Result.Count];
1160 Result.Keys.CopyTo(Result2, 0);
1174 lock (locationByTabID)
1176 Result =
new string[locationByTabID.Count];
1177 locationByTabID.Keys.CopyTo(Result, 0);
1189 Dictionary<string, bool> Result =
new Dictionary<string, bool>();
1193 foreach (Dictionary<
object, Dictionary<
string, (
string,
string,
string)[]>> P in tabIdsByUser.Values)
1195 foreach (Dictionary<
string, (
string,
string,
string)[]> P2 in P.Values)
1197 foreach (
string TabID
in P2.Keys)
1198 Result[TabID] =
true;
1203 string[] Result2 =
new string[Result.Count];
1204 Result.Keys.CopyTo(Result2, 0);
1215 if (eventsByTabID.TryGetValue(TabID, out TabQueue Queue))
1232 this.TabID = Queue.
TabID;
1233 this.SessionID = Queue.SessionID;
1234 this.Session = Queue.Session;
1235 this.Uri = Queue.Uri;
1237 this.Query =
new Dictionary<string, string>();
1239 if (!(Queue.Query is
null))
1241 foreach ((
string,
string,
string) Rec in Queue.Query)
1242 this.
Query[Rec.Item1] = Rec.Item3;
1269 public Dictionary<string, string>
Query {
get; }
1272 internal class TabQueue : IDisposable
1274 public string TabID;
1275 public string SessionID;
1278 public LinkedList<string> Queue =
new LinkedList<string>();
1281 public Uri Uri =
null;
1282 public DateTime KeepAliveUntil = DateTime.MinValue;
1283 public (string, string, string)[] Query =
null;
1285 public TabQueue(
string ID,
string SessionID,
Variables Session)
1289 this.SessionID = SessionID;
1290 this.Session = Session;
1293 public void Dispose()
1296 this.SyncObj =
null;
1298 this.Queue?.Clear();
1302 private class ContentQueue
1304 public string ContentID;
1307 public byte[] Content =
null;
1308 public bool More =
false;
1310 public ContentQueue(
string ID)
1312 this.ContentID = ID;
1323 public static Task<int>
PushEvent(
string[] TabIDs,
string Type,
object Data)
1325 if (Data is
string s)
1326 return PushEvent(TabIDs, Type, s,
false,
null,
null);
1330 return PushEvent(TabIDs, Type, s,
true,
null,
null);
1341 public static Task<int>
PushEvent(
string[] TabIDs,
string Type,
string Data)
1343 return PushEvent(TabIDs, Type, Data,
false,
null,
null);
1354 public static Task<int>
PushEvent(
string[] TabIDs,
string Type,
string Data,
bool DataIsJson)
1356 return PushEvent(TabIDs, Type, Data, DataIsJson,
null,
null);
1371 public static async Task<int>
PushEvent(
string[] TabIDs,
string Type,
string Data,
bool DataIsJson,
string UserVariable, params
string[] Privileges)
1377 StringBuilder Json =
new StringBuilder();
1379 Json.Append(
"{\"type\":\"");
1381 Json.Append(
"\",\"data\":");
1394 string s = Json.ToString();
1397 TabIDs = eventsByTabID.GetKeys();
1399 foreach (
string TabID
in TabIDs)
1401 if (!(TabID is
null) && eventsByTabID.TryGetValue(TabID, out TabQueue Queue))
1403 if (!
string.IsNullOrEmpty(UserVariable))
1405 if (!Queue.Session.TryGetVariable(UserVariable, out
Variable v) ||
1406 !(v.ValueObject is
IUser User))
1411 if (!(Privileges is
null))
1413 bool HasPrivileges =
true;
1415 foreach (
string Privilege
in Privileges)
1417 if (!User.HasPrivilege(Privilege))
1419 HasPrivileges =
false;
1429 if (await Queue.SyncObj.TryBeginWrite(10000))
1433 if (!(Queue.WebSocket is
null))
1434 await Queue.WebSocket.Send(Json.ToString(), 4096);
1435 else if (!(Queue.Response is
null))
1439 await Queue.Response.Write(
"[" + Json.ToString() +
"]");
1440 await Queue.Response.SendResponse();
1441 await Queue.Response.DisposeAsync();
1442 Queue.Response =
null;
1450 Queue.Queue.AddLast(s);
1454 await Queue.SyncObj.EndWrite();
1458 timeoutByTabID.Remove(TabID);
1463 catch (Exception ex)
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
const string DefaultContentType
application/json
Plain text encoder/decoder.
const string DefaultContentType
text/plain
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.
The ClientEvents class allows applications to push information asynchronously to web clients connecte...
static async Task ReportAsynchronousResult(string Id, string ContentType, byte[] Result, bool More)
Reports asynchronously evaluated result back to a client.
static string[] GetTabIDsForUser(object User, params KeyValuePair< string, string >[] QueryFilter)
Gets the Tab IDs of all tabs that a specific user views.
static async Task< int > PushEvent(string[] TabIDs, string Type, string Data, bool DataIsJson, string UserVariable, params string[] Privileges)
Puses an event to a set of Tabs, given their Tab IDs.
static string[] GetTabIDsForUser(object User, string Location)
Gets the Tab IDs of all tabs that a specific user views.
static void KeepTabAlive(string TabID, DateTime KeepAliveUntil)
Keeps a Tab alive, even though it might be temporarily offline or disconnected.
static string[] GetTabIDsForUser(object User, string Location, string QueryParameter1, string QueryParameterValue1)
Gets the Tab IDs of all tabs that a specific user views.
override bool UserSessions
If the resource uses user sessions.
static string[] GetOpenLocations()
Returns a list of resources that are currently open.
static object[] GetActiveUsers()
Returns a list of active users
bool AllowsGET
If the GET method is allowed.
static string[] GetTabIDsForLocation(string Location, string QueryParameter1, string QueryParameterValue1)
Gets the Tab IDs of all tabs that display a particular resource.
static TabInformation GetTabIDInformation(string TabID)
Gets information about a Tab, given its ID.
static string[] GetTabIDsForUser(object User, bool IgnoreCase, string QueryParameter1, string QueryParameterValue1, string QueryParameter2, string QueryParameterValue2)
Gets the Tab IDs of all tabs that a specific user views.
override bool HandlesSubPaths
If the resource handles sub-paths.
static string[] GetTabIDsForLocation(string Location)
Gets the Tab IDs of all tabs that display a particular resource.
const int TabIdCacheTimeoutSeconds
Number of seconds before a Tab ID is purged, unless references or kept alive.
static Task< int > PushEvent(string[] TabIDs, string Type, object Data)
Puses an event to a set of Tabs, given their Tab IDs.
static string[] GetTabIDsForLocation(string Location, params KeyValuePair< string, string >[] QueryFilter)
Gets the Tab IDs of all tabs that display a particular resource.
static string[] GetTabIDsForUser(object User, string Location, bool IgnoreCase, string QueryParameter1, string QueryParameterValue1, string QueryParameter2, string QueryParameterValue2)
Gets the Tab IDs of all tabs that a specific user views.
static string[] GetTabIDsForUser(object User, string Location, bool IgnoreCase, string QueryParameter1, string QueryParameterValue1)
Gets the Tab IDs of all tabs that a specific user views.
async Task GET(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
static Task< int > PushEvent(string[] TabIDs, string Type, string Data, bool DataIsJson)
Puses an event to a set of Tabs, given their Tab IDs.
static string[] GetTabIDsForLocation(string Location, bool IgnoreCase, params KeyValuePair< string, string >[] QueryFilter)
Gets the Tab IDs of all tabs that display a particular resource.
const int TabIdCacheTimeoutSecondsHalf
Half of TabIdCacheTimeoutSeconds.
static string[] GetTabIDsForLocation(string Location, bool IgnoreCase, string QueryParameter1, string QueryParameterValue1, string QueryParameter2, string QueryParameterValue2)
Gets the Tab IDs of all tabs that display a particular resource.
static string[] GetTabIDsForLocations(params string[] Locations)
Gets the Tab IDs of all tabs that display a set of resources.
static string[] GetTabIDsForLocation(string Location, bool IgnoreCase, string QueryParameter1, string QueryParameterValue1)
Gets the Tab IDs of all tabs that display a particular resource.
static string[] GetTabIDsForUser(object User, bool IgnoreCase, string QueryParameter1, string QueryParameterValue1)
Gets the Tab IDs of all tabs that a specific user views.
ClientEvents()
Resource managing asynchronous events to web clients.
static string[] GetTabIDsForUser(object User)
Gets the Tab IDs of all tabs that a specific user views.
static Task ReportAsynchronousResult(string Id, string ContentType, byte[] Result)
Reports asynchronously evaluated result back to a client.
bool AllowsPOST
If the POST method is allowed.
static string[] GetTabIDs()
Gets all open Tab IDs.
static string[] GetTabIDsForUser(object User, string Location, bool IgnoreCase, params KeyValuePair< string, string >[] QueryFilter)
Gets the Tab IDs of all tabs that a specific user views.
static string[] GetTabIDsForUser(object User, string Location, params KeyValuePair< string, string >[] QueryFilter)
Gets the Tab IDs of all tabs that a specific user views.
static Task< int > PushEvent(string[] TabIDs, string Type, string Data)
Puses an event to a set of Tabs, given their Tab IDs.
static string[] GetTabIDsForLocation(string Location, string QueryParameter1, string QueryParameterValue1, string QueryParameter2, string QueryParameterValue2)
Gets the Tab IDs of all tabs that display a particular resource.
static string[] GetTabIDsForUser(object User, string Location, string QueryParameter1, string QueryParameterValue1, string QueryParameter2, string QueryParameterValue2)
Gets the Tab IDs of all tabs that a specific user views.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
static string[] GetTabIDsForUser(object User, bool IgnoreCase, params KeyValuePair< string, string >[] QueryFilter)
Gets the Tab IDs of all tabs that a specific user views.
static string[] GetTabIDsForUsers()
Gets all open Tab IDs for logged in users.
Static class managing the runtime environment of the IoT Gateway.
static DateTime ScheduleEvent(ScheduledEventCallback Callback, DateTime When, object State)
Schedules a one-time event.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Base class for all asynchronous HTTP resources. An asynchronous resource responds outside of the meth...
Represents an HTTP request.
HttpRequestHeader Header
Request header.
bool HasData
If the request has data.
Variables Session
Contains session states, if the resource requires sessions, or null otherwise.
string SubPath
Sub-path. If a resource is found handling the request, this property contains the trailing sub-path o...
async Task< object > DecodeDataAsync()
Decodes data sent in request.
static string GetSessionId(HttpRequest Request, HttpResponse Response)
Gets the session ID used for a request.
static void SetTransparentCorsHeaders(HttpResource Resource, HttpRequest Request, HttpResponse Response)
Sets CORS headers for a resource, allowing it to be embedded in other sites.
const string HttpSessionID
The Cookie Key for HTTP Session Identifiers: "HttpSessionID"
Represets a response of an HTTP client request.
async Task DisposeAsync()
Closes the connection and disposes of all resources.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
void SetHeader(string FieldName, string Value)
Sets a custom header field value.
async Task Write(byte[] Data)
Returns binary data in the response.
The server encountered an unexpected condition which prevented it from fulfilling the request.
Class handling a web-socket.
HttpResponse HttpResponse
Original HTTP response used when connection was upgrades to a WebSocket connection.
async Task Send(string Payload, int MaxFrameLength)
Sends a text payload, possibly in multiple frames.
HttpRequest HttpRequest
Original HTTP request made to upgrade the connection to a WebSocket connection.
Generic object. Contains a sequence of properties.
Implements an in-memory cache.
Event arguments for cache item removal events.
ValueType Value
Value of item that was removed.
RemovedReason Reason
Reason for removing the item.
Represents an object that allows single concurrent writers but multiple concurrent readers....
virtual void Dispose()
IDisposable.Dispose
Contains information about a variable.
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
GET Interface for HTTP resources.
POST Interface for HTTP resources.
Basic interface for all types of elements.
Basic interface for a user.
RemovedReason
Reason for removing the item.
ContentType
DTLS Record content type.