mirror of https://github.com/abpframework/abp.git
16 changed files with 221 additions and 49 deletions
@ -0,0 +1,7 @@ |
|||||
|
namespace Volo.Abp.BlobStoring.Database |
||||
|
{ |
||||
|
public static class ContainerConsts |
||||
|
{ |
||||
|
public const int MaxNameLength = 64; // TODO: find best length
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
||||
|
{ |
||||
|
public class EfCoreBlobRepository : EfCoreRepository<IBlobStoringDatabaseDbContext, Blob, Guid>, IBlobRepository |
||||
|
{ |
||||
|
public EfCoreBlobRepository(IDbContextProvider<IBlobStoringDatabaseDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<Blob> FindAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await DbSet.FirstOrDefaultAsync( |
||||
|
x => x.ContainerId == containerId && |
||||
|
x.Name == name && |
||||
|
x.TenantId == tenantId, |
||||
|
GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<bool> ExistsAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await DbSet.AnyAsync( |
||||
|
x => x.ContainerId == containerId && |
||||
|
x.Name == name && |
||||
|
x.TenantId == tenantId, |
||||
|
GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<bool> DeleteAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var blob = await FindAsync(containerId, name, tenantId, cancellationToken); |
||||
|
|
||||
|
if (blob == null) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
await base.DeleteAsync(blob.Id, cancellationToken: GetCancellationToken(cancellationToken)); |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore |
||||
|
{ |
||||
|
public class EfCoreContainerRepository : EfCoreRepository<IBlobStoringDatabaseDbContext, Container, Guid>, IContainerRepository |
||||
|
{ |
||||
|
public EfCoreContainerRepository(IDbContextProvider<IBlobStoringDatabaseDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<Container> GetContainerAsync(string name, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await DbSet.FirstAsync(x => x.Name == name, GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<Container> FindContainerAsync(string name, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await DbSet.FirstOrDefaultAsync(x => x.Name == name, GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
using MongoDB.Driver.Linq; |
||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.BlobStoring.Database.MongoDB |
||||
|
{ |
||||
|
public class MongoBlobRepository : MongoDbRepository<IBlobStoringDatabaseMongoDbContext, Blob, Guid>, IBlobRepository |
||||
|
{ |
||||
|
public MongoBlobRepository(IMongoDbContextProvider<IBlobStoringDatabaseMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<Blob> FindAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await GetMongoQueryable().FirstOrDefaultAsync( |
||||
|
x => x.ContainerId == containerId && |
||||
|
x.Name == name && |
||||
|
x.TenantId == tenantId, |
||||
|
GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<bool> ExistsAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await GetMongoQueryable().AnyAsync( |
||||
|
x => x.ContainerId == containerId && |
||||
|
x.Name == name && |
||||
|
x.TenantId == tenantId, |
||||
|
GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<bool> DeleteAsync(Guid containerId, string name, Guid? tenantId = null, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var blob = await FindAsync(containerId, name, tenantId, cancellationToken); |
||||
|
|
||||
|
if (blob == null) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
await base.DeleteAsync(blob, cancellationToken: GetCancellationToken(cancellationToken)); |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.BlobStoring.Database.MongoDB |
||||
|
{ |
||||
|
public class MongoContainerRepository : MongoDbRepository<IBlobStoringDatabaseMongoDbContext, Container, Guid>, IContainerRepository |
||||
|
{ |
||||
|
public MongoContainerRepository(IMongoDbContextProvider<IBlobStoringDatabaseMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<Container> GetContainerAsync(string name, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await GetMongoQueryable().Where(x => x.Name == name).FirstAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<Container> FindContainerAsync(string name, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await GetMongoQueryable().Where(x => x.Name == name).FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue