public async Task <long> PersistEventAsync(string actorName, long index, object @event) { switch (@event) { case IMessage message: var data = message.ToByteArray(); var metadata = Array.Empty <byte>(); if (data.Length > 512 * 1024) { using (var compressedStream = new MemoryStream()) { using (var originalStream = new MemoryStream(data)) using (var gZipStream = new GZipStream(compressedStream, CompressionMode.Compress)) { originalStream.CopyTo(gZipStream); } data = compressedStream.ToArray(); metadata = Encoding.UTF8.GetBytes( new JObject { ["encoding"] = "gzip" }.ToString(Formatting.None)); } } var eventData = new EventData(Guid.NewGuid(), @event.GetType().Name, false, data, metadata); var result = await connection.AppendToStream(actorName, index - 1, eventData); return(result.NextExpectedVersion); default: throw new Exception($"Expected event of type 'IMessage', but found {@event.GetType().FullName}."); } }
public async void ThrowWhenNoServerAvailable() { var stream = $"test-{Guid.NewGuid()}"; var eventData = new EventData(Guid.NewGuid(), "Event1", false, Array.Empty <byte>(), Array.Empty <byte>()); var writeResult = await connection.AppendToStream(stream, ExpectedVersion.NoStream, eventData); writeResult.NextExpectedVersion.Should().Be(0); }
public async Task <long> PersistEventAsync(string actorName, long index, object @event) { switch (@event) { case IMessage message: var result = await connection.AppendToStream(actorName, index - 1, message.ToEventData()); return(result.NextExpectedVersion); default: throw new Exception($"Expected event of type 'IMessage', but found {@event.GetType().FullName}."); } }