本文整理汇总了C#中ISagaData.ToBsonDocument方法的典型用法代码示例。如果您正苦于以下问题:C# ISagaData.ToBsonDocument方法的具体用法?C# ISagaData.ToBsonDocument怎么用?C# ISagaData.ToBsonDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISagaData
的用法示例。
在下文中一共展示了ISagaData.ToBsonDocument方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public async Task Save(ISagaData sagaData, Dictionary<string, string> sagaAuditMetadata)
{
var document = new BsonDocument
{
{"_id", new {Id = sagaData.Id, Revision = sagaData.Revision}.ToBsonDocument()},
{"Metadata", sagaAuditMetadata.ToBsonDocument()},
{"Data", sagaData.ToBsonDocument()}
};
await _snapshots.InsertOneAsync(document);
}
示例2: Insert
public async Task Insert(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties)
{
if (sagaData.Id == Guid.Empty)
{
throw new InvalidOperationException(string.Format("Attempted to insert saga data {0} without an ID", sagaData.GetType()));
}
var collection = GetCollection(sagaData.GetType());
await collection.InsertOneAsync(sagaData.ToBsonDocument()).ConfigureAwait(false);
}
示例3: Insert
public async Task Insert(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties)
{
if (sagaData.Id == Guid.Empty)
{
throw new InvalidOperationException($"Attempted to insert saga data {sagaData.GetType()} without an ID");
}
if (sagaData.Revision != 0)
{
throw new InvalidOperationException($"Attempted to insert saga data with ID {sagaData.Id} and revision {sagaData.Revision}, but revision must be 0 on first insert!");
}
var collection = GetCollection(sagaData.GetType());
await collection.InsertOneAsync(sagaData.ToBsonDocument()).ConfigureAwait(false);
}
示例4: Update
public async Task Update(ISagaData sagaData, IEnumerable<ISagaCorrelationProperty> correlationProperties)
{
var collection = GetCollection(sagaData.GetType());
var criteria = Builders<BsonDocument>.Filter.And(Builders<BsonDocument>.Filter.Eq("_id", sagaData.Id),
Builders<BsonDocument>.Filter.Eq("Revision", sagaData.Revision));
sagaData.Revision++;
var result = await collection.ReplaceOneAsync(criteria, sagaData.ToBsonDocument(sagaData.GetType())).ConfigureAwait(false);
if (!result.IsModifiedCountAvailable || result.ModifiedCount != 1)
{
throw new ConcurrencyException("Saga data {0} with ID {1} in collection {2} could not be updated!",
sagaData.GetType(), sagaData.Id, collection.CollectionNamespace);
}
}