Browse Source

Revise blob and container classes.

pull/4161/head
Halil İbrahim Kalkan 6 years ago
parent
commit
73bf93dbdb
  1. 30
      modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/Blob.cs
  2. 13
      modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/Container.cs

30
modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/Blob.cs

@ -7,38 +7,38 @@ namespace Volo.Abp.BlobStoring.Database
{ {
public class Blob : AggregateRoot<Guid>, IMultiTenant public class Blob : AggregateRoot<Guid>, IMultiTenant
{ {
public Guid ContainerId { get; set; } public virtual Guid ContainerId { get; protected set; }
public Guid? TenantId { get; } public virtual Guid? TenantId { get; protected set; }
public string Name { get; set; } public virtual string Name { get; protected set; }
public byte[] Content { get; private set; } public virtual byte[] Content { get; protected set; }
public Blob(Guid id, Guid containerId, [NotNull]string name, byte[] content, Guid? tenantId) : base(id)
{
Check.NotNullOrWhiteSpace(name, nameof(name), BlobConsts.MaxNameLength);
CheckContentLength(content);
Content = content; public Blob(Guid id, Guid containerId, [NotNull] string name, [NotNull] byte[] content, Guid? tenantId = null)
: base(id)
{
Name = Check.NotNullOrWhiteSpace(name, nameof(name), BlobConsts.MaxNameLength);
ContainerId = containerId; ContainerId = containerId;
Name = name; Content = CheckContentLength(content);
TenantId = tenantId; TenantId = tenantId;
} }
public virtual void SetContent(byte[] content) public virtual void SetContent(byte[] content)
{ {
CheckContentLength(content); Content = CheckContentLength(content);
Content = content;
} }
protected virtual void CheckContentLength(byte[] content) protected virtual byte[] CheckContentLength(byte[] content)
{ {
Check.NotNull(content, nameof(content));
if (content.Length >= BlobConsts.MaxContentLength) if (content.Length >= BlobConsts.MaxContentLength)
{ {
throw new AbpException($"Blob content size cannot be more than {BlobConsts.MaxContentLength} Bytes."); throw new AbpException($"Blob content size cannot be more than {BlobConsts.MaxContentLength} Bytes.");
} }
return content;
} }
} }
} }

13
modules/blob-storing-database/src/Volo.Abp.BlobStoring.Database.Domain/Volo/Abp/BlobStoring/Database/Container.cs

@ -5,18 +5,17 @@ using Volo.Abp.MultiTenancy;
namespace Volo.Abp.BlobStoring.Database namespace Volo.Abp.BlobStoring.Database
{ {
public class Container : AggregateRoot<Guid>, IMultiTenant public class Container : AggregateRoot<Guid>, IMultiTenant //TODO: Rename to BlobContainer
{ {
public Guid? TenantId { get; } public virtual Guid? TenantId { get; protected set; }
public string Name { get; set; } public virtual string Name { get; protected set; }
public Container(Guid id, [NotNull]string name, Guid? tenantId = null) : base(id) public Container(Guid id, [NotNull] string name, Guid? tenantId = null)
: base(id)
{ {
Check.NotNullOrWhiteSpace(name, nameof(name), ContainerConsts.MaxNameLength); Name = Check.NotNullOrWhiteSpace(name, nameof(name), ContainerConsts.MaxNameLength);
TenantId = tenantId; TenantId = tenantId;
Name = name;
} }
} }
} }
Loading…
Cancel
Save