DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
LogEntry.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;
19 using System.Collections.Generic;
20 
21 namespace Deveel.Data.Diagnostics {
22  public sealed class LogEntry : IEnumerable<KeyValuePair<string, object>> {
23  private readonly Dictionary<string, object> data;
24 
25  internal LogEntry(IDictionary<string, object> metadata) {
26  data = new Dictionary<string, object>(metadata);
27  }
28 
29  public IEnumerable<string> Keys {
30  get { return data.Keys; }
31  }
32 
33  public object GetValue(string key) {
34  object value;
35  if (!data.TryGetValue(key, out value))
36  return null;
37 
38  return value;
39  }
40 
41  public IEnumerator<KeyValuePair<string, object>> GetEnumerator() {
42  return data.GetEnumerator();
43  }
44 
45  IEnumerator IEnumerable.GetEnumerator() {
46  return GetEnumerator();
47  }
48 
49  public static LogEntry FromEvent(IEvent @event) {
50  var data = new Dictionary<string, object>();
51  if (@event.EventSource != null) {
52  var source = @event.EventSource;
53  while (source != null) {
54  var sourceData = source.Metadata;
55  foreach (var pair in sourceData) {
56  data[pair.Key] = pair.Value;
57  }
58 
59  source = source.ParentSource;
60  }
61  }
62 
63  foreach (var pair in @event.EventData) {
64  data[pair.Key] = pair.Value;
65  }
66 
67  return new LogEntry(data);
68  }
69  }
70 }
LogEntry(IDictionary< string, object > metadata)
Definition: LogEntry.cs:25
This is an event occurred during the lifetime of a database.
Definition: IEvent.cs:24
static LogEntry FromEvent(IEvent @event)
Definition: LogEntry.cs:49
IEnumerator< KeyValuePair< string, object > > GetEnumerator()
Definition: LogEntry.cs:41
IEventSource EventSource
Gets the event source.
Definition: IEvent.cs:31
readonly Dictionary< string, object > data
Definition: LogEntry.cs:23
object GetValue(string key)
Definition: LogEntry.cs:33