public async Task <int> GetPublishedVersionAsync(string processorName, string aggregateRootTypeName, string aggregateRootId) { try { var builder = Builders <PublishedVersion> .Filter; var filter = builder.Eq(e => e.ProcessorName, processorName) & builder.Eq(e => e.AggregateRootId, aggregateRootId); var result = await _publishedVersionCollection.GetCollection(aggregateRootId).Find(filter).ToListAsync(); return(result.Select(r => r.Version).SingleOrDefault()); } catch (MongoQueryException ex) { var errorMessage = string.Format("Get aggregate published version has mongo exception, aggregateRootType: {0}, aggregateRootId: {1}", aggregateRootTypeName, aggregateRootId); _logger.Error(errorMessage, ex); throw; } catch (Exception ex) { var errorMessage = string.Format("Get aggregate published version has unknown exception, aggregateRootType: {0}, aggregateRootId: {1}", aggregateRootTypeName, aggregateRootId); _logger.Error(errorMessage, ex); throw; } }
public async Task <AsyncTaskResult <int> > GetPublishedVersionAsync(string processorName, string aggregateRootTypeName, string aggregateRootId) { try { var builder = Builders <PublishedVersion> .Filter; var filter = builder.Eq(e => e.ProcessorName, processorName) & builder.Eq(e => e.AggregateRootId, aggregateRootId); var result = await _publishedVersionCollection.GetCollection(aggregateRootId).Find(filter).ToListAsync(); var version = result.Select(r => r.Version).SingleOrDefault(); return(new AsyncTaskResult <int>(AsyncTaskStatus.Success, version)); } catch (MongoQueryException ex) { _logger.Error("Get aggregate published version has query exception.", ex); return(new AsyncTaskResult <int>(AsyncTaskStatus.IOException, ex.Message)); } catch (Exception ex) { _logger.Error("Get aggregate published version has unknown exception.", ex); return(new AsyncTaskResult <int>(AsyncTaskStatus.Failed, ex.Message)); } }