Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
LogEvent.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
6using Waher.Events;
8
10{
14 public class LogEvent : ActionNode
15 {
16 private Message message;
17 private Object @object;
18 private Actor actor;
19 private EventId eventId;
20 private Module module;
21 private Facility facility;
22 private Tag[] tags;
23
27 public LogEvent()
28 : base()
29 {
30 }
31
35 public Message Message => this.message;
36
40 public Object Object => this.@object;
41
45 public Actor Actor => this.actor;
46
50 public EventId EventId => this.eventId;
51
55 public Module Module => this.module;
56
60 public Facility Facility => this.facility;
61
65 public Tag[] Tags => this.tags;
66
70 [DefaultValue(EventType.Informational)]
71 public EventType Type { get; set; }
72
76 [DefaultValue(EventLevel.Minor)]
77 public EventLevel Level { get; set; }
78
82 public override string LocalName => nameof(LogEvent);
83
88 public override IStateMachineNode Create()
89 {
90 return new LogEvent();
91 }
92
97 public override async Task Parse(XmlElement Xml)
98 {
99 this.Type = XML.Attribute(Xml, "type", EventType.Informational);
100 this.Level = XML.Attribute(Xml, "level", EventLevel.Minor);
101
102 await base.Parse(Xml);
103
105 new Type[]
106 {
107 typeof(Message),
108 typeof(Object),
109 typeof(Actor),
110 typeof(EventId),
111 typeof(Module),
112 typeof(Facility)
113 },
114 new bool[]
115 {
116 true,
117 false,
118 false,
119 false,
120 false,
121 false
122 });
123 }
124
128 protected override void OnChildNodesUpdated()
129 {
130 base.OnChildNodesUpdated();
131
132 this.message = this.GetValueElement<Message>();
133 this.@object = this.GetValueElement<Object>();
134 this.actor = this.GetValueElement<Actor>();
135 this.eventId = this.GetValueElement<EventId>();
136 this.module = this.GetValueElement<Module>();
137 this.facility = this.GetValueElement<Facility>();
138 this.tags = this.GetChildElements<Tag>();
139 }
140
145 public override async Task Execute(EvaluationArguments Arguments)
146 {
147 string Message = (await this.message.Evaluate(Arguments))?.ToString();
148 string Object = this.@object is null ? string.Empty : (await this.@object.Evaluate(Arguments))?.ToString();
149 string Actor = this.actor is null ? string.Empty : (await this.actor.Evaluate(Arguments))?.ToString();
150 string EventId = this.eventId is null ? string.Empty : (await this.eventId.Evaluate(Arguments))?.ToString();
151 string Module = this.module is null ? string.Empty : (await this.module.Evaluate(Arguments))?.ToString();
152 string Facility = this.facility is null ? string.Empty : (await this.facility.Evaluate(Arguments))?.ToString();
153 List<KeyValuePair<string, object>> Tags = new List<KeyValuePair<string, object>>();
154
155 foreach (Tag Tag in this.tags)
156 {
157 Tags.Add(new KeyValuePair<string, object>(
158 (await Tag.Key.Evaluate(Arguments))?.ToString(),
159 await Tag.Value.Evaluate(Arguments)));
160 }
161
162 Log.Event(new Event(DateTime.Now, this.Type, Message, Object, Actor, EventId,
163 this.Level, Facility, Module, string.Empty, Tags.ToArray()));
164 }
165 }
166}
Helps with common XML-related tasks.
Definition: XML.cs:19
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Definition: XML.cs:914
Class representing an event.
Definition: Event.cs:10
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static async void Event(Event Event)
Logs an event. It will be distributed to registered event sinks.
Definition: Log.cs:128
Abstract base class for State-Machine action nodes.
Definition: ActionNode.cs:9
override IStateMachineNode Create()
Creates a new node of the corresponding type.
Definition: LogEvent.cs:88
override void OnChildNodesUpdated()
Method called whenever ChildNodes is updated.
Definition: LogEvent.cs:128
override async Task Execute(EvaluationArguments Arguments)
Evaluates the action node
Definition: LogEvent.cs:145
override async Task Parse(XmlElement Xml)
Parses the State-machine node.
Definition: LogEvent.cs:97
Contains information required for evaluating script in a state-machine.
void ConvertValueAttributesToElements(XmlElement Xml, Type[] ValueTypes, bool[] Required)
Converts value attributes to parsed elements. The XML definition has to be parsed before,...
Task< object > Evaluate(EvaluationArguments Arguments)
Evaluates the value node.
Definition: Value.cs:146
EventLevel
Event level.
Definition: EventLevel.cs:7
EventType
Type of event.
Definition: EventType.cs:7