forked from PeterWaher/IoTGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersistedEvent.cs
More file actions
230 lines (207 loc) · 4.68 KB
/
PersistedEvent.cs
File metadata and controls
230 lines (207 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
using System;
using System.Collections.Generic;
using Waher.Persistence.Attributes;
namespace Waher.Events.Persistence
{
/// <summary>
/// Class representing a persisted event.
/// </summary>
[CollectionName("EventLog")]
[TypeName(TypeNameSerialization.None)]
[ArchivingTime("ArchiveDays")]
[Index("Timestamp")]
[Index("Object", "Timestamp")]
[Index("Actor", "Timestamp")]
[Index("EventId", "Timestamp")]
[Index("Facility", "Timestamp")]
[Index("Type", "Timestamp")]
public class PersistedEvent
{
private Guid objectId = Guid.Empty;
private DateTime timestamp = DateTime.MinValue;
private EventType type = EventType.Informational;
private EventLevel level = EventLevel.Minor;
private string message = string.Empty;
private string obj = string.Empty;
private string actor = string.Empty;
private string eventId = string.Empty;
private string module = string.Empty;
private string facility = string.Empty;
private string stackTrace = string.Empty;
private PersistedTag[] tags = null;
/// <summary>
/// Class representing a persisted event.
/// </summary>
public PersistedEvent()
{
}
/// <summary>
/// Class representing a persisted event.
/// </summary>
/// <param name="Event">Event to store.</param>
public PersistedEvent(Event Event)
{
this.timestamp = Event.Timestamp;
this.type = Event.Type;
this.message = Event.Message;
this.obj = Event.Object;
this.actor = Event.Actor;
this.eventId = Event.EventId;
this.level = Event.Level;
this.facility = Event.Facility;
this.module = Event.Module;
this.stackTrace = Event.StackTrace;
if (Event.Tags is null)
this.tags = null;
else
{
int i, c = Event.Tags.Length;
this.tags = new PersistedTag[c];
for (i = 0; i < c; i++)
{
this.tags[i] = new PersistedTag()
{
Name = Event.Tags[i].Key,
Value = Event.Tags[i].Value
};
}
}
}
/// <summary>
/// Object ID
/// </summary>
[ObjectId]
public Guid ObjectId
{
get { return this.objectId; }
set { this.objectId = value; }
}
/// <summary>
/// Timestamp of event.
/// </summary>
public DateTime Timestamp
{
get { return this.timestamp; }
set { this.timestamp = value; }
}
/// <summary>
/// Type of event.
/// </summary>
public EventType Type
{
get { return this.type; }
set { this.type = value; }
}
/// <summary>
/// Event Level.
/// </summary>
[DefaultValue(EventLevel.Minor)]
public EventLevel Level
{
get { return this.level; }
set { this.level = value; }
}
/// <summary>
/// Free-text event message.
/// </summary>
public string Message
{
get { return this.message; }
set { this.message = value; }
}
/// <summary>
/// First row of <see cref="Message"/>.
/// </summary>
[IgnoreMember]
public string MessageFirstRow
{
get
{
string s = this.message.Trim();
int i = s.IndexOf('\n');
int j = s.IndexOf('\r');
if (i < 0)
i = j;
else if (j >= 0 && j < i)
i = j;
if (i < 0)
return s;
else
return s.Substring(0, i).TrimEnd();
}
}
/// <summary>
/// Object related to the event.
/// </summary>
public string Object
{
get { return this.obj; }
set { this.obj = value; }
}
/// <summary>
/// Actor responsible for the action causing the event.
/// </summary>
public string Actor
{
get { return this.actor; }
set { this.actor = value; }
}
/// <summary>
/// Computer-readable Event ID identifying type of even.
/// </summary>
public string EventId
{
get { return this.eventId; }
set { this.eventId = value; }
}
/// <summary>
/// Facility can be either a facility in the network sense or in the system sense.
/// </summary>
public string Facility
{
get { return this.facility; }
set { this.facility = value; }
}
/// <summary>
/// Module where the event is reported.
/// </summary>
[DefaultValueStringEmpty]
public string Module
{
get { return this.module; }
set { this.module = value; }
}
/// <summary>
/// Stack Trace of event.
/// </summary>
[DefaultValueStringEmpty]
public string StackTrace
{
get { return this.stackTrace; }
set { this.stackTrace = value; }
}
/// <summary>
/// Variable set of tags providing event-specific information.
/// </summary>
[DefaultValueNull]
public PersistedTag[] Tags
{
get { return this.tags; }
set { this.tags = value; }
}
/// <summary>
/// <see cref="Object.ToString()"/>
/// </summary>
public override string ToString()
{
return this.message;
}
/// <summary>
/// Number of days to archive event.
/// </summary>
public int ArchiveDays
{
get => PersistedEventLog.ArchiveDays;
}
}
}