Created
February 15, 2018 02:11
-
-
Save dcomartin/0ca59e07b4ef45908bd825495a69e9e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task RaiseEvent(BankAccountEvent evnt) | |
{ | |
base.RaiseEvent(evnt); | |
await ConfirmEvents(); | |
await _conn.AppendToStreamAsync(_stream, Version - 2, ToEventData(Guid.NewGuid(), evnt, new Dictionary<string, object>())); | |
} | |
private static EventData ToEventData(Guid eventId, object evnt, IDictionary<string, object> headers) | |
{ | |
var data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(evnt)); | |
var eventHeaders = new Dictionary<string, object>(headers) | |
{ | |
{ | |
"EventClrType", evnt.GetType().AssemblyQualifiedName | |
} | |
}; | |
var metadata = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(eventHeaders)); | |
var typeName = evnt.GetType().Name; | |
return new EventData(eventId, typeName, true, data, metadata); | |
} | |
private static object DeserializeEvent(RecordedEvent evntData) | |
{ | |
var eventClrTypeName = JObject.Parse(Encoding.UTF8.GetString(evntData.Metadata)).Property("EventClrType").Value; | |
return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(evntData.Data), Type.GetType((string)eventClrTypeName)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment