/// <summary> /// Serializes the object graph to the specified <paramref name="stream"/>. /// </summary> /// <param name="stream">The <see cref="Stream"/> on which to serialize the object <paramref name="graph"/>.</param> /// <param name="graph">The object to serialize.</param> /// <param name="type">The <see cref="Type"/> of object being serialized.</param> public void Serialize(Stream stream, Object graph, Type type) { Verify.NotNull(graph, nameof(graph)); Verify.NotNull(stream, nameof(stream)); using (var gzipStream = new GZipStream(stream, CompressionMode.Compress)) serializer.Serialize(gzipStream, graph, type); }
/// <summary> /// Serializes an object graph to binary data. /// </summary> /// <param name="serializer">The <see cref="ISerializeObjects"/> implementation being extended.</param> /// <param name="graph">The object graph to serialize.</param> public static Byte[] Serialize <T>(this ISerializeObjects serializer, T graph) { using (var stream = new MemoryStream()) { serializer.Serialize(stream, graph); return(stream.ToArray()); } }
/// <summary> /// Adds a new <see cref="Snapshot"/> to the snapshot store. /// </summary> /// <param name="snapshot">The snapshot to save to the snapshot store.</param> public void Save(Snapshot snapshot) { Verify.NotDisposed(this, disposed); if (useAsyncWrite) { buffer.Add(snapshot.StreamId, snapshot.Version, serializer.Serialize(snapshot.State)); } else { if (replaceExisting) { UpdateSnapshot(snapshot); } else { InsertSnapshot(snapshot); } } }
/// <summary> /// Adds a new commit to the event store. /// </summary> /// <param name="commit">The commit to append to the event store.</param> public void Save(Commit commit) { Verify.NotDisposed(this, disposed); Verify.NotNull(commit, nameof(commit)); var data = serializer.Serialize(new CommitData(commit.Headers, commit.Events)); using (var command = dialect.CreateCommand(dialect.InsertCommit)) { Log.Trace("Inserting stream {0} commit for version {1}", commit.StreamId, commit.Version); command.Parameters.Add(dialect.CreateTimestampParameter(commit.Timestamp)); command.Parameters.Add(dialect.CreateCorrelationIdParameter(commit.CorrelationId)); command.Parameters.Add(dialect.CreateStreamIdParameter(commit.StreamId)); command.Parameters.Add(dialect.CreateVersionParameter(commit.Version)); command.Parameters.Add(dialect.CreateDataParameter(data)); commit.Id = Convert.ToInt64(dialect.ExecuteScalar(command)); } }
/// <summary> /// Insert a new saga instance. /// </summary> /// <param name="saga">The saga instance to insert.</param> private void InsertSaga(Saga saga) { var state = serializer.Serialize(saga); var typeId = GetSagaTypeId(saga.GetType()); using (var command = dialect.CreateCommand(dialect.InsertSaga)) { Log.Trace("Starting new saga {0}", saga); command.Parameters.Add(dialect.CreateTypeIdParameter(typeId)); command.Parameters.Add(dialect.CreateIdParameter(saga.CorrelationId)); command.Parameters.Add(dialect.CreateTimeoutParameter(saga.Timeout)); command.Parameters.Add(dialect.CreateStateParameter(state)); if (dialect.ExecuteNonQuery(command) == 0) { throw new ConcurrencyException(Exceptions.SagaConcurrencyConflict.FormatWith(saga.GetType(), saga.CorrelationId)); } } saga.Version++; }
/// <summary> /// Serializes the object graph to the specified <paramref name="stream"/>. /// </summary> /// <param name="serializer">The <see cref="ISerializeObjects"/> implementation being extended.</param> /// <param name="stream">The <see cref="Stream"/> on which to serialize the object <paramref name="graph"/>.</param> /// <param name="graph">The object to serialize.</param> public static void Serialize <T>(this ISerializeObjects serializer, Stream stream, T graph) { Verify.NotNull(serializer, nameof(serializer)); serializer.Serialize(stream, graph, typeof(T)); }