public void DispatchCommand(object command, Action <EnvelopeBuilder> builder = null) { var envelopeBuilder = new EnvelopeBuilder(Guid.NewGuid().ToString()); envelopeBuilder.AddItem(command); if (builder != null) { builder(envelopeBuilder); } var envelope = envelopeBuilder.Build(); var data = _serializer.SaveEnvelopeData(envelope); if (!_tapeStream.TryAppend(data)) { throw new InvalidOperationException("Failed to record domain log"); } _aggregateFactory.Dispatch(envelope); }
private void SaveEventsInternal(IEnumerable<DomainEvent> events, ITapeStream stream, int version) { var array = events.ToArray(); foreach (var @event in array) { @event.Version = ++version; byte[] bytes; using (var buffer = new MemoryStream()) { var descriptor = new EventDescriptor(@event); serializer.Serialize(descriptor, buffer); bytes = buffer.ToArray(); } stream.TryAppend(bytes, TapeAppendCondition.None); } sender.SendBatch(array); }
public void Can_continue_after_recreation() { foreach (var b in _batch) { _stream.TryAppend(b); } var version = _stream.GetCurrentVersion(); _stream = null; FreeResources(); _stream = InitializeAndGetTapeStorage(); _stream.TryAppend(_batch[0]); var readings = _stream.ReadRecords(version, 1).ToArray(); Assert.AreEqual(1, readings.Length, "Number of records mismatch"); Assert.Greater(readings[0].Version, version, "Version mismatch"); CollectionAssert.AreEqual(_batch[0], readings[0].Data, "Data mismatch"); }