/// <summary>Saves the event to the data store.</summary> /// <param name="uncommittedEvent">The event to save.</param> /// <param name="transaction">The transaction.</param> private void SaveEvent(UncommittedEvent uncommittedEvent, SqlTransaction transaction) { Contract.Requires <ArgumentNullException>(uncommittedEvent != null, "The argument uncommittedEvent could not be null."); Contract.Requires <ArgumentNullException>(transaction != null, "The argument transaction could not be null."); string eventName; var document = _formatter.Serialize(uncommittedEvent.Payload, out eventName); var storedEvent = new StoredEvent <JObject>(uncommittedEvent.EventIdentifier, uncommittedEvent.EventTimeStamp, eventName, uncommittedEvent.EventVersion, uncommittedEvent.EventSourceId, uncommittedEvent.EventSequence, document); var raw = _translator.TranslateToRaw(storedEvent); using (var command = new SqlCommand(Queries.InsertNewEventQuery, transaction.Connection)) { command.Transaction = transaction; command.Parameters.AddWithValue("EventId", raw.EventIdentifier); command.Parameters.AddWithValue("TimeStamp", raw.EventTimeStamp); command.Parameters.AddWithValue("EventSourceId", raw.EventSourceId); command.Parameters.AddWithValue("Name", raw.EventName); command.Parameters.AddWithValue("Version", raw.EventVersion.ToString()); command.Parameters.AddWithValue("Sequence", raw.EventSequence); command.Parameters.AddWithValue("Data", raw.Data); command.ExecuteNonQuery(); } }
protected override string Serialize(T @event) { string eventName; var serializedEvent = _formatter.Serialize(@event, out eventName); EventName = eventName; return(Translate(serializedEvent)); }
/// <summary>Saves the event to the data store.</summary> /// <param name="evnt">The event to save.</param> /// <param name="transaction">The transaction.</param> private void SaveEvent(UncommittedEvent evnt, NpgsqlTransaction transaction) { string eventName; var document = _formatter.Serialize(evnt.Payload, out eventName); var storedEvent = new StoredEvent <JObject>(evnt.EventIdentifier, evnt.EventTimeStamp, eventName, evnt.EventVersion, evnt.EventSourceId, evnt.EventSequence, document); var raw = _translator.TranslateToRaw(storedEvent); using (var command = new NpgsqlCommand(Queries.InsertNewEventQuery, transaction.Connection)) { command.Transaction = transaction; command.Parameters.AddWithValue("EventId", raw.EventIdentifier); command.Parameters.AddWithValue("TimeStamp", raw.EventTimeStamp); command.Parameters.AddWithValue("EventSourceId", raw.EventSourceId); command.Parameters.AddWithValue("Name", raw.EventName); command.Parameters.AddWithValue("Version", raw.EventVersion.ToString()); command.Parameters.AddWithValue("Sequence", raw.EventSequence); command.Parameters.AddWithValue("Data", raw.Data); command.ExecuteNonQuery(); } }