示例#1
0
        public IEnumerable <WriteModel <DbCachedEntry> > GetModel(WriteModelOptions options)
        {
            var filter = Builders <DbCachedEntry> .Filter.Eq(e => e.CacheKey, Entry.CacheKey);

            var updateDefinition = Builders <DbCachedEntry> .Update
                                   .Set(e => e.CacheKey, Entry.CacheKey)
                                   .Set(e => e.Expiry, Entry.Expiry)
                                   .Set(e => e.Value, Entry.Value);

            var model = new UpdateOneModel <DbCachedEntry>(filter, updateDefinition)
            {
                IsUpsert = true
            };

            yield return(model);
        }
示例#2
0
        public IEnumerable <WriteModel <DbCachedEntry> > GetModel(WriteModelOptions options)
        {
            var filter = Builders <DbCachedEntry> .Filter.Lt(e => e.Expiry, DateTime.UtcNow);

            yield return(new DeleteManyModel <DbCachedEntry>(filter));
        }
 private static void InternalSaveChanges <TEntity>(IMongoDbConnection connection, IEnumerable <IWriteCommand> commands, WriteModelOptions options) where TEntity : class
 {
     EntityIndexWriter.ApplyIndexing <TEntity>(connection);
     EntityCommandWriter.Write <TEntity>(connection, commands, options);
 }
        private static async Task InternalSaveChangesAsync <TEntity>(IMongoDbConnection connection, IEnumerable <IWriteCommand> commands, WriteModelOptions options, CancellationToken cancellationToken) where TEntity : class
        {
            await EntityIndexWriter.ApplyIndexingAsync <TEntity>(connection);

            await EntityCommandWriter.WriteAsync <TEntity>(connection, commands, options, cancellationToken);
        }
示例#5
0
        public IEnumerable <WriteModel <DbCachedEntry> > GetModel(WriteModelOptions options)
        {
            var filter = Builders <DbCachedEntry> .Filter.Empty;

            yield return(new DeleteManyModel <DbCachedEntry>(filter));
        }
示例#6
0
        public static async Task WriteAsync <TEntity>(IMongoDbConnection connection, IEnumerable <IWriteCommand> commands, WriteModelOptions options, CancellationToken cancellationToken = default) where TEntity : class
        {
            var writeModels = commands.OfType <IWriteCommand <TEntity> >().SelectMany(c => c.GetModel(options)).ToArray();

            if (writeModels.Any())
            {
                var entityDefinition = EntityMapping.GetOrCreateDefinition(typeof(TEntity));
                var collection       = connection.GetDatabase().GetCollection <TEntity>(entityDefinition.CollectionName);
                using (var diagnostics = DiagnosticRunner.Start(connection, writeModels))
                {
                    try
                    {
                        await collection.BulkWriteAsync(writeModels, cancellationToken : cancellationToken);
                    }
                    catch (Exception exception)
                    {
                        diagnostics.Error(exception);
                        throw;
                    }
                }
            }
        }