添加项目文件。
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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; } = FileState.Uploaded;
|
||||
public StorageLocation StorageLocation { get; private set; } = new StorageLocation();
|
||||
public CheckSum CheckSum { get; private set; }
|
||||
|
||||
private UploadFile() { }
|
||||
|
||||
public UploadFile(Guid ownerId, FileName fileName, long fileSize, ContentType contentType, StorageLocation? storageLocation, CheckSum checkSum)
|
||||
{
|
||||
OwnerId = ownerId;
|
||||
FileName = fileName;
|
||||
FileSize = fileSize;
|
||||
ContentType = contentType;
|
||||
StorageLocation = storageLocation ?? new StorageLocation();
|
||||
CheckSum = checkSum;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using FileService.Domain.Events;
|
||||
using FileService.Domain.ValueObjects;
|
||||
using IM.DomainCommons;
|
||||
|
||||
namespace FileService.Domain.Entities
|
||||
{
|
||||
public class UploadTask:AggregateRootEntity
|
||||
{
|
||||
public Guid UploaderId { get; private set; }
|
||||
public Guid ConversationId { get; private set; }
|
||||
public FileName FileName { get; private set; }
|
||||
public long FileSize { get; private set; }
|
||||
public ContentType ContentType { get; private set; }
|
||||
public StorageLocation StorageLocation { get; private set; }
|
||||
public UploadTaskState State { get; private set; }
|
||||
public CheckSum CheckSum { get; private set; }
|
||||
|
||||
private UploadTask() { }
|
||||
|
||||
public UploadTask(Guid uploaderId, Guid conversationId, FileName fileName, long fileSize, ContentType contentType, StorageLocation? storageLocation, CheckSum checkSum)
|
||||
{
|
||||
UploaderId = uploaderId;
|
||||
ConversationId = conversationId;
|
||||
FileName = fileName;
|
||||
FileSize = fileSize;
|
||||
ContentType = contentType;
|
||||
StorageLocation = storageLocation ?? new StorageLocation();
|
||||
CheckSum = checkSum;
|
||||
}
|
||||
|
||||
public void StartUpload()
|
||||
{
|
||||
State = UploadTaskState.Uploading;
|
||||
}
|
||||
|
||||
public void CompleteUpload(StorageLocation location)
|
||||
{
|
||||
State = UploadTaskState.Completed;
|
||||
AddDomainEvent(new UploadTaskCompletedDomainEvent(this));
|
||||
}
|
||||
|
||||
public void Fail()
|
||||
{
|
||||
State = UploadTaskState.Failed;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using FileService.Domain.Entities;
|
||||
using MediatR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Domain.Events
|
||||
{
|
||||
public class UploadTaskCompletedDomainEvent(UploadTask task):INotification;
|
||||
}
|
||||
@@ -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,16 @@
|
||||
using FileService.Domain.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Domain.IReposities
|
||||
{
|
||||
public interface IUploadFileReposity
|
||||
{
|
||||
void Create(UploadFile file);
|
||||
Task<UploadFile?> FindByIdAsync(Guid id);
|
||||
Task<UploadFile?> FindByCheckSumAsync(Guid uploaderId,string value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using FileService.Domain.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Domain.IReposities
|
||||
{
|
||||
public interface IUploadTaskReposity
|
||||
{
|
||||
void Create(UploadTask task);
|
||||
Task<UploadTask?> FindByIdAsync(Guid id);
|
||||
Task<UploadTask?> FindByCheckSumAsync(string value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FileService.Domain
|
||||
{
|
||||
public enum UploadTaskState
|
||||
{
|
||||
Created = 0,
|
||||
Failed = 1,
|
||||
Uploading = 2,
|
||||
Uploaded = 4,
|
||||
Merging = 5,
|
||||
Completed = 6,
|
||||
}
|
||||
}
|
||||
@@ -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,29 @@
|
||||
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; } = "Local";
|
||||
public string Bucket { get; private set; } = string.Empty;
|
||||
public string ObjectKey { get; private set; } = string.Empty;
|
||||
public string? Region { get; private set; } = string.Empty;
|
||||
|
||||
public StorageLocation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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