DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Event.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Collections.Generic;
19 
20 namespace Deveel.Data.Diagnostics {
21  public abstract class Event : IEvent {
22  private IDictionary<string, object> metadata;
24 
25  protected Event()
26  : this(DateTimeOffset.UtcNow) {
27  }
28 
29  protected Event(DateTimeOffset timeStamp) {
30  TimeStamp = timeStamp;
31  }
32 
33  private IDictionary<string, object> GenerateEventData() {
34  var dictionary = new Dictionary<string, object>();
35  GetEventData(dictionary);
36  return dictionary;
37  }
38 
39  protected virtual void GetEventData(Dictionary<string, object> data) {
40  }
41 
42  public IEventSource EventSource {
43  get {
44  if (source == null)
45  return null;
46 
47  return OnSourceGet(source);
48  }
49  set { source = OnSourceSet(value); }
50  }
51 
52  public DateTimeOffset TimeStamp { get; private set; }
53 
54  protected virtual IEventSource OnSourceGet(IEventSource eventSource) {
55  return eventSource;
56  }
57 
58  protected virtual IEventSource OnSourceSet(IEventSource eventSource) {
59  return eventSource;
60  }
61 
62  IDictionary<string, object> IEvent.EventData {
63  get {
64  if (metadata == null)
65  metadata = GenerateEventData();
66 
67  return metadata;
68  }
69  }
70  }
71 }
virtual void GetEventData(Dictionary< string, object > data)
Definition: Event.cs:39
virtual IEventSource OnSourceSet(IEventSource eventSource)
Definition: Event.cs:58
This is an event occurred during the lifetime of a database.
Definition: IEvent.cs:24
IDictionary< string, object > metadata
Definition: Event.cs:22
Event(DateTimeOffset timeStamp)
Definition: Event.cs:29
IDictionary< string, object > EventData
Gets additional event data that come with the event.
Definition: IEvent.cs:43
IDictionary< string, object > GenerateEventData()
Definition: Event.cs:33
virtual IEventSource OnSourceGet(IEventSource eventSource)
Definition: Event.cs:54
Represents the origin of system events, providing a mechanism to fill the metadata before dispatching...
Definition: IEventSource.cs:40