/// <inheritdoc /> public async Task <IReadOnlyCollection <IEvent> > SaveAsync(IAggregateRoot entity) { if (!entity.Events.Any()) { throw new InvalidOperationException("No events for serialization."); } var batchOperation = new TableBatchOperation(); entity.Events.ToList().ForEach(e => batchOperation.Insert(new EventStoreEvent(e))); await tableProxy.ExecuteBatchAsync(batchOperation); return(entity.Events); }
/// <inheritdoc/> public Task PersistMessagesAsync(string id, IReadOnlyCollection <AbstractMessage> messages) { if (messages.Count >= MaxBatchSize) { throw new NotSupportedException($"Storage unable to persist '{messages.Count}' messages. Supported message count is up to '{MaxBatchSize}'."); } var batchOperation = new TableBatchOperation(); foreach (var msg in messages) { var properties = AzureTableSerializer.Serialize(msg, true); properties.Add(IsPublishedColumnName, new EntityProperty(false)); batchOperation.Insert(new DynamicTableEntity(id, msg.Id, "*", properties)); } return(tableProxy.ExecuteBatchAsync(batchOperation)); }