添加项目文件。
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using FileService.Domain.ValueObjects;
|
||||
using IM.DomainCommons;
|
||||
|
||||
namespace FileService.Domain.Entities
|
||||
{
|
||||
public class UploadFile:AggregateRootEntity
|
||||
{
|
||||
public Guid OwnerId { get; private set; }
|
||||
public FileName FileName { get; private set; }
|
||||
public long FileSize { get;private set; }
|
||||
public ContentType ContentType { get;private set; }
|
||||
public FileState State { get; private set; }
|
||||
public StorageLocation? StorageLocation { get; private set; }
|
||||
public CheckSum CheckSum { get; private set; }
|
||||
|
||||
private UploadFile() { }
|
||||
public UploadFile(Guid ownerId, string fileName, string contentType)
|
||||
{
|
||||
OwnerId = ownerId;
|
||||
FileName = fileName;
|
||||
ContentType = contentType;
|
||||
State = FileState.Created;
|
||||
}
|
||||
|
||||
public void StartUpload()
|
||||
{
|
||||
State = FileState.Uploading;
|
||||
}
|
||||
|
||||
public void CompleteUpload(StorageLocation storage, CheckSum checkSum)
|
||||
{
|
||||
StorageLocation = storage;
|
||||
CheckSum = checkSum;
|
||||
State = FileState.Uploaded;
|
||||
}
|
||||
|
||||
public void Fail()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DomainCommons\IM.DomainCommons.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Domain
|
||||
{
|
||||
public enum FileState
|
||||
{
|
||||
Created = 0,
|
||||
Uploading = 1,
|
||||
Uploaded = 2,
|
||||
Failed = 3,
|
||||
Deleted = 4
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Domain.ValueObjects
|
||||
{
|
||||
public class CheckSum
|
||||
{
|
||||
public string Algorithm { get; }
|
||||
public string Value { get; }
|
||||
|
||||
public CheckSum(string algorithm, string value)
|
||||
{
|
||||
Algorithm = algorithm;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
public static implicit operator CheckSum((string algorithm, string value) value)
|
||||
{
|
||||
return new CheckSum(value.algorithm, value.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Domain.ValueObjects
|
||||
{
|
||||
public class ContentType
|
||||
{
|
||||
public string Value { get; }
|
||||
public ContentType(string contentType)
|
||||
{
|
||||
Value = contentType;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
public static implicit operator ContentType(string contentType)
|
||||
{
|
||||
return new ContentType(contentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Domain.ValueObjects
|
||||
{
|
||||
public class FileName
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
public FileName(string value)
|
||||
{
|
||||
if(value.Length > 20)
|
||||
{
|
||||
throw new ArgumentException("文件名超出长度");
|
||||
}
|
||||
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
public static implicit operator FileName(string value)
|
||||
{
|
||||
return new FileName(value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Domain.ValueObjects
|
||||
{
|
||||
public class StorageLocation
|
||||
{
|
||||
public string StorageProvider { get; private set; }
|
||||
public string Bucket { get; private set; }
|
||||
public string ObjectKey { get; private set; }
|
||||
public string? Region { get; private set; }
|
||||
|
||||
public StorageLocation(string storageProvider, string bucket, string objectKey, string? region = null)
|
||||
{
|
||||
this.StorageProvider = storageProvider;
|
||||
this.Bucket = bucket;
|
||||
this.ObjectKey = objectKey;
|
||||
this.Region = region;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user