Beispiel #1
0
        /// <summary>
        /// Updates an existing saga entity in the persistence store.
        /// </summary>
        /// <param name="saga">The saga entity to updated.</param>
        public void Update(IContainSagaData saga)
        {
            var collection = this.mongoDatabase.GetCollection(saga.GetType().Name);

            var query  = saga.MongoUpdateQuery();
            var update = saga.MongoUpdate();
            var result = collection.Update(query, update, UpdateFlags.None);

            if (!result.UpdatedExisting)
            {
                throw new InvalidOperationException(string.Format("Unable to update saga with id {0}", saga.Id));
            }
        }
        public async Task Update(IContainSagaData sagaData, SynchronizedStorageSession session, ContextBag context)
        {
            var newETag = sagaData.AssumedNotNull().ComputeETag();

            var versionedDocument = (IHaveDocumentVersion)sagaData;

            if (versionedDocument.ETag == newETag)
            {
                return;
            }

            var query  = sagaData.MongoUpdateQuery(versionedDocument.DocumentVersion);
            var update = sagaData.MongoUpdate(newETag);

            var collection = this.mongoDatabase.GetCollection <BsonDocument>(sagaData.GetType().Name);
            var result     = await collection.UpdateOneAsync(query, update).ConfigureAwait(false);

            if (result.ModifiedCount != 1)
            {
                throw new InvalidOperationException(string.Format("Unable to update saga with id {0}", sagaData.Id));
            }
        }