3using System.Threading.Tasks;
19 : base(
"/SearchEvents")
23 public override bool HandlesSubPaths =>
false;
24 public override bool UserSessions =>
true;
38 if (Content.
HasError || !(Content.
Decoded is Dictionary<string, object> Form))
44 if (!Form.TryGetValue(
"offset", out
object Obj) || !(Obj is
int Offset) ||
45 !Form.TryGetValue(
"maxCount", out Obj) || !(Obj is
int MaxCount) ||
46 !Form.TryGetValue(
"from", out Obj) || !(Obj is
string FromStr) || !
XML.
TryParse(FromStr, out DateTime From) ||
47 !Form.TryGetValue(
"to", out Obj) || !(Obj is
string ToStr) || !
XML.
TryParse(ToStr, out DateTime To) ||
48 !Form.TryGetValue(
"object", out Obj) || !(Obj is
string Object) ||
49 !Form.TryGetValue(
"actor", out Obj) || !(Obj is
string Actor) ||
50 !Form.TryGetValue(
"eventId", out Obj) || !(Obj is
string EventId) ||
51 !Form.TryGetValue(
"module", out Obj) || !(Obj is
string Module) ||
52 !Form.TryGetValue(
"facility", out Obj) || !(Obj is
string Facility) ||
53 !Form.TryGetValue(
"debug", out Obj) || !(Obj is
bool Debug) ||
54 !Form.TryGetValue(
"informational", out Obj) || !(Obj is
bool Informational) ||
55 !Form.TryGetValue(
"notice", out Obj) || !(Obj is
bool Notice) ||
56 !Form.TryGetValue(
"warning", out Obj) || !(Obj is
bool Warning) ||
57 !Form.TryGetValue(
"error", out Obj) || !(Obj is
bool Error) ||
58 !Form.TryGetValue(
"critical", out Obj) || !(Obj is
bool Critical) ||
59 !Form.TryGetValue(
"alert", out Obj) || !(Obj is
bool Alert) ||
60 !Form.TryGetValue(
"emergency", out Obj) || !(Obj is
bool Emergency) ||
61 !Form.TryGetValue(
"minor", out Obj) || !(Obj is
bool Minor) ||
62 !Form.TryGetValue(
"medium", out Obj) || !(Obj is
bool Medium) ||
63 !Form.TryGetValue(
"major", out Obj) || !(Obj is
bool Major))
80 new KeyValuePair<string, object>(
"From", From.ToString()),
81 new KeyValuePair<string, object>(
"To", To.ToString()),
84 if (!
string.IsNullOrEmpty(Object))
85 Tags.
Add(
new KeyValuePair<string, object>(
"Object", Object));
87 if (!
string.IsNullOrEmpty(Actor))
88 Tags.
Add(
new KeyValuePair<string, object>(
"Actor", Actor));
90 if (!
string.IsNullOrEmpty(EventId))
91 Tags.
Add(
new KeyValuePair<string, object>(
"EventId", EventId));
93 if (!
string.IsNullOrEmpty(Module))
94 Tags.
Add(
new KeyValuePair<string, object>(
"Module", Module));
96 if (!
string.IsNullOrEmpty(Facility))
97 Tags.
Add(
new KeyValuePair<string, object>(
"Facility", Facility));
99 if (!(Debug && Informational && Notice && Warning && Error && Critical && Alert && Emergency))
102 Tags.
Add(
new KeyValuePair<string, object>(
"Debug", Debug));
105 Tags.
Add(
new KeyValuePair<string, object>(
"Informational", Informational));
108 Tags.
Add(
new KeyValuePair<string, object>(
"Notice", Notice));
111 Tags.
Add(
new KeyValuePair<string, object>(
"Warning", Warning));
114 Tags.
Add(
new KeyValuePair<string, object>(
"Error", Error));
117 Tags.
Add(
new KeyValuePair<string, object>(
"Critical", Critical));
120 Tags.
Add(
new KeyValuePair<string, object>(
"Alert", Alert));
123 Tags.
Add(
new KeyValuePair<string, object>(
"Emergency", Emergency));
126 if (!(Minor && Medium && Major))
129 Tags.
Add(
new KeyValuePair<string, object>(
"Minor", Minor));
132 Tags.
Add(
new KeyValuePair<string, object>(
"Medium", Medium));
135 Tags.
Add(
new KeyValuePair<string, object>(
"Major", Major));
150 AddFilter(Filters,
"Object", Object);
151 AddFilter(Filters,
"Actor", Actor);
152 AddFilter(Filters,
"EventId", EventId);
153 AddFilter(Filters,
"Module", Module);
154 AddFilter(Filters,
"Facility", Facility);
156 if (!(Debug && Informational && Notice && Warning && Error && Critical && Alert && Emergency))
158 List<Filter> Ors =
new List<Filter>();
160 AddFilter(Ors,
"Type", Debug,
EventType.Debug);
161 AddFilter(Ors,
"Type", Informational,
EventType.Informational);
162 AddFilter(Ors,
"Type", Notice,
EventType.Notice);
163 AddFilter(Ors,
"Type", Warning,
EventType.Warning);
164 AddFilter(Ors,
"Type", Error,
EventType.Error);
165 AddFilter(Ors,
"Type", Critical,
EventType.Critical);
166 AddFilter(Ors,
"Type", Alert,
EventType.Alert);
167 AddFilter(Ors,
"Type", Emergency,
EventType.Emergency);
172 if (!(Minor && Medium && Major))
174 List<Filter> Ors =
new List<Filter>();
176 AddFilter(Ors,
"Level", Minor,
EventLevel.Minor);
177 AddFilter(Ors,
"Level", Medium,
EventLevel.Medium);
178 AddFilter(Ors,
"Level", Major,
EventLevel.Major);
192 Events.Add(
new Dictionary<string, object>()
194 {
"timestamp", Event.Timestamp },
195 {
"type", Event.Type },
196 {
"level", Event.Level },
197 {
"message", Event.Message },
198 {
"object", Event.Object },
199 {
"actor", Event.Actor },
200 {
"eventId", Event.EventId },
201 {
"module", Event.Module },
202 {
"facility", Event.Facility },
203 {
"stackTrace", Event.StackTrace },
214 Dictionary<string, object> Result =
new Dictionary<string, object>()
217 {
"events", Events.ToArray() }
220 await Response.Return(Result);
223 public static void AddFilter(
ChunkedList<Filter> Filters,
string ParameterName,
string Value)
225 if (!
string.IsNullOrEmpty(Value))
227 if (Value.IndexOf(
'*') >= 0)
234 public static void AddFilter(List<Filter> Filters,
string ParameterName,
bool Value, Enum EnumValue)
240 private static Dictionary<string, object>[] TagsToJson(
PersistedTag[] Tags)
245 int i, c = Tags.Length;
246 Dictionary<string, object>[] Result =
new Dictionary<string, object>[c];
248 for (i = 0; i < c; i++)
250 Result[i] =
new Dictionary<string, object>()
252 {
"name", Tags[i].
Name },
253 {
"value", Tags[i].
Value }
Helps with parsing of commong data types.
static string RegexStringEncode(string s)
Encodes a string for inclusion in a regular expression.
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Helps with common XML-related tasks.
static bool TryParse(string s, out DateTime Value)
Tries to decode a string encoded DateTime.
Class representing an event.
KeyValuePair< string, object >[] Tags
Variable set of tags providing event-specific information.
Static class managing the application event log. Applications and services log events on this static ...
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
Class representing a persisted event.
Class representing a persisted tag.
Static class managing the runtime environment of the IoT Gateway.
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
string RemoteEndPoint
Remote end-point.
bool HasData
If the request has data.
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Represets a response of an HTTP client request.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static Task< IEnumerable< object > > Find(string Collection, params string[] SortOrder)
Finds objects in a given collection.
This filter selects objects that conform to all child-filters provided.
This filter selects objects that have a named field equal to a given value.
This filter selects objects that have a named field greater or equal to a given value.
This filter selects objects that have a named field lesser or equal to a given value.
This filter selects objects that have a named field matching a given regular expression.
This filter selects objects that conform to any of the child-filters provided.
A chunked list is a linked list of chunks of objects of type T .
void Add(T Item)
Adds an item to the collection.
T[] ToArray()
Returns an array containing all elements of the collection.
bool AllowsPOST
If the POST method is allowed.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
POST Interface for HTTP resources.