2using System.Collections.Generic;
3using System.Threading.Tasks;
18 : base(
"/SearchEvents")
22 public override bool HandlesSubPaths =>
false;
23 public override bool UserSessions =>
true;
34 if (!(Obj is Dictionary<string, object> Form))
37 if (!Form.TryGetValue(
"offset", out Obj) || !(Obj is
int Offset) ||
38 !Form.TryGetValue(
"maxCount", out Obj) || !(Obj is
int MaxCount) ||
39 !Form.TryGetValue(
"from", out Obj) || !(Obj is
string FromStr) || !
XML.
TryParse(FromStr, out DateTime From) ||
40 !Form.TryGetValue(
"to", out Obj) || !(Obj is
string ToStr) || !
XML.
TryParse(ToStr, out DateTime To) ||
41 !Form.TryGetValue(
"object", out Obj) || !(Obj is
string Object) ||
42 !Form.TryGetValue(
"actor", out Obj) || !(Obj is
string Actor) ||
43 !Form.TryGetValue(
"eventId", out Obj) || !(Obj is
string EventId) ||
44 !Form.TryGetValue(
"module", out Obj) || !(Obj is
string Module) ||
45 !Form.TryGetValue(
"facility", out Obj) || !(Obj is
string Facility) ||
46 !Form.TryGetValue(
"debug", out Obj) || !(Obj is
bool Debug) ||
47 !Form.TryGetValue(
"informational", out Obj) || !(Obj is
bool Informational) ||
48 !Form.TryGetValue(
"notice", out Obj) || !(Obj is
bool Notice) ||
49 !Form.TryGetValue(
"warning", out Obj) || !(Obj is
bool Warning) ||
50 !Form.TryGetValue(
"error", out Obj) || !(Obj is
bool Error) ||
51 !Form.TryGetValue(
"critical", out Obj) || !(Obj is
bool Critical) ||
52 !Form.TryGetValue(
"alert", out Obj) || !(Obj is
bool Alert) ||
53 !Form.TryGetValue(
"emergency", out Obj) || !(Obj is
bool Emergency) ||
54 !Form.TryGetValue(
"minor", out Obj) || !(Obj is
bool Minor) ||
55 !Form.TryGetValue(
"medium", out Obj) || !(Obj is
bool Medium) ||
56 !Form.TryGetValue(
"major", out Obj) || !(Obj is
bool Major))
70 List<KeyValuePair<string, object>> Tags =
new List<KeyValuePair<string, object>>()
72 new KeyValuePair<string, object>(
"From", From.ToString()),
73 new KeyValuePair<string, object>(
"To", To.ToString()),
76 if (!
string.IsNullOrEmpty(Object))
77 Tags.Add(
new KeyValuePair<string, object>(
"Object", Object));
79 if (!
string.IsNullOrEmpty(Actor))
80 Tags.Add(
new KeyValuePair<string, object>(
"Actor", Actor));
82 if (!
string.IsNullOrEmpty(EventId))
83 Tags.Add(
new KeyValuePair<string, object>(
"EventId", EventId));
85 if (!
string.IsNullOrEmpty(Module))
86 Tags.Add(
new KeyValuePair<string, object>(
"Module", Module));
88 if (!
string.IsNullOrEmpty(Facility))
89 Tags.Add(
new KeyValuePair<string, object>(
"Facility", Facility));
91 if (!(Debug && Informational && Notice && Warning && Error && Critical && Alert && Emergency))
94 Tags.Add(
new KeyValuePair<string, object>(
"Debug", Debug));
97 Tags.Add(
new KeyValuePair<string, object>(
"Informational", Informational));
100 Tags.Add(
new KeyValuePair<string, object>(
"Notice", Notice));
103 Tags.Add(
new KeyValuePair<string, object>(
"Warning", Warning));
106 Tags.Add(
new KeyValuePair<string, object>(
"Error", Error));
109 Tags.Add(
new KeyValuePair<string, object>(
"Critical", Critical));
112 Tags.Add(
new KeyValuePair<string, object>(
"Alert", Alert));
115 Tags.Add(
new KeyValuePair<string, object>(
"Emergency", Emergency));
118 if (!(Minor && Medium && Major))
121 Tags.Add(
new KeyValuePair<string, object>(
"Minor", Minor));
124 Tags.Add(
new KeyValuePair<string, object>(
"Medium", Medium));
127 Tags.Add(
new KeyValuePair<string, object>(
"Major", Major));
136 List<Filter> Filters =
new List<Filter>()
142 AddFilter(Filters,
"Object", Object);
143 AddFilter(Filters,
"Actor", Actor);
144 AddFilter(Filters,
"EventId", EventId);
145 AddFilter(Filters,
"Module", Module);
146 AddFilter(Filters,
"Facility", Facility);
148 if (!(Debug && Informational && Notice && Warning && Error && Critical && Alert && Emergency))
150 List<Filter> Ors =
new List<Filter>();
152 AddFilter(Ors,
"Type", Debug,
EventType.Debug);
153 AddFilter(Ors,
"Type", Informational,
EventType.Informational);
154 AddFilter(Ors,
"Type", Notice,
EventType.Notice);
155 AddFilter(Ors,
"Type", Warning,
EventType.Warning);
156 AddFilter(Ors,
"Type", Error,
EventType.Error);
157 AddFilter(Ors,
"Type", Critical,
EventType.Critical);
158 AddFilter(Ors,
"Type", Alert,
EventType.Alert);
159 AddFilter(Ors,
"Type", Emergency,
EventType.Emergency);
161 Filters.Add(
new FilterOr(Ors.ToArray()));
164 if (!(Minor && Medium && Major))
166 List<Filter> Ors =
new List<Filter>();
168 AddFilter(Ors,
"Level", Minor,
EventLevel.Minor);
169 AddFilter(Ors,
"Level", Medium,
EventLevel.Medium);
170 AddFilter(Ors,
"Level", Major,
EventLevel.Major);
172 Filters.Add(
new FilterOr(Ors.ToArray()));
176 List<Dictionary<string, object>> Events =
new List<Dictionary<string, object>>();
182 Events.Add(
new Dictionary<string, object>()
184 {
"timestamp", Event.Timestamp },
185 {
"type", Event.Type },
186 {
"level", Event.Level },
187 {
"message", Event.Message },
188 {
"object", Event.Object },
189 {
"actor", Event.Actor },
190 {
"eventId", Event.EventId },
191 {
"module", Event.Module },
192 {
"facility", Event.Facility },
193 {
"stackTrace", Event.StackTrace },
204 Dictionary<string, object> Result =
new Dictionary<string, object>()
207 {
"events", Events.ToArray() }
210 await Response.Return(Result);
213 public static void AddFilter(List<Filter> Filters,
string ParameterName,
string Value)
215 if (!
string.IsNullOrEmpty(Value))
217 if (Value.IndexOf(
'*') >= 0)
224 public static void AddFilter(List<Filter> Filters,
string ParameterName,
bool Value, Enum EnumValue)
230 private static Dictionary<string, object>[] TagsToJson(
PersistedTag[] Tags)
235 int i, c = Tags.Length;
236 Dictionary<string, object>[] Result =
new Dictionary<string, object>[c];
238 for (i = 0; i < c; i++)
240 Result[i] =
new Dictionary<string, object>()
242 {
"name", Tags[i].
Name },
243 {
"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.
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< object > DecodeDataAsync()
Decodes data sent in request.
Represets a response of an HTTP client request.
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.
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.