Example #1
0
        public async Task SaveAsync(DomainEvent e, TModel model, bool notify = false)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            OnSave(model, e, CollectionWrapperOperationType.Update);
            var orignalVersion = model.Version;

            model.Version++;
            model.LastModified = e.CommitStamp;
            model.AddEvent(e.MessageId);
            HandlePollableReadModel(e, model);
            var result = await _storage.SaveWithVersionAsync(model, orignalVersion).ConfigureAwait(false);

            if (!result.Ok)
            {
                throw new CollectionWrapperException(FormatCollectionWrapperExceptionMessage("Concurency exception", e));
            }

            if (ShouldSendNotification(e, notify))
            {
                Object notificationPayload = TransformForNotification(e, model);
                await _notifyToSubscribers.Send(ReadModelUpdatedMessage.Updated <TModel, TKey>(model.Id, notificationPayload)).ConfigureAwait(false);
            }
        }
        public void Save(DomainEvent e, TModel model, bool notify = false)
        {
            OnSave(model, e);
            var orignalVersion = model.Version;

            model.Version++;
            model.AddEvent(e.MessageId);
            model.LastModified = e.CommitStamp;

            var result = _storage.SaveWithVersion(model, orignalVersion);

            if (!result.Ok)
            {
                throw new Exception("Concurency exception");
            }

            if (!IsReplay && (notify || NotifySubscribers))
            {
                _notifyToSubscribers.Send(ReadModelUpdatedMessage.Updated <TModel, TKey>(PrepareForNotification(model)));
            }
        }