DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
EventExtensions.cs
Go to the documentation of this file.
1 using System;
2 using System.Globalization;
3 
4 namespace Deveel.Data.Diagnostics {
5  public static class EventExtensions {
6  public static T GetData<T>(this IEvent @event, string key) {
7  if (@event == null || @event.EventData == null)
8  return default(T);
9 
10  object value;
11  if (!@event.EventData.TryGetValue(key, out value))
12  return default(T);
13 
14  if (value is T)
15  return (T) value;
16 
17  if (value is IConvertible)
18  return (T) Convert.ChangeType(value, typeof (T), CultureInfo.InvariantCulture);
19 
20  throw new InvalidCastException();
21  }
22 
23  public static string UserName(this IEvent @event) {
24  return @event.GetData<string>(KnownEventMetadata.UserName);
25  }
26 
27  public static string DatabaseName(this IEvent @event) {
28  return @event.GetData<string>(KnownEventMetadata.DatabaseName);
29  }
30 
31  public static int CommitId(this IEvent @event) {
32  return @event.GetData<int>(KnownEventMetadata.CommitId);
33  }
34 
35  public static DateTimeOffset SessionStartTime(this IEvent @event) {
36  return @event.GetData<DateTimeOffset>(KnownEventMetadata.SessionStartTime);
37  }
38  }
39 }
static string DatabaseName(this IEvent @event)
This is an event occurred during the lifetime of a database.
Definition: IEvent.cs:24
static int CommitId(this IEvent @event)
static string UserName(this IEvent @event)
static DateTimeOffset SessionStartTime(this IEvent @event)