67 lines
2.3 KiB
C#
67 lines
2.3 KiB
C#
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 string? ChatType { get; private set; }
|
|
public Guid? TargetId { 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; }
|
|
public Guid? ResultFileId { get; private set; }
|
|
public string? FailureReason { get; private set; }
|
|
|
|
private UploadTask() { }
|
|
|
|
public UploadTask(Guid uploaderId, Guid conversationId, string? chatType, Guid? targetId, FileName fileName, long fileSize, ContentType contentType, StorageLocation? storageLocation, CheckSum checkSum)
|
|
{
|
|
UploaderId = uploaderId;
|
|
ConversationId = conversationId;
|
|
ChatType = chatType?.ToUpperInvariant();
|
|
TargetId = targetId;
|
|
FileName = fileName;
|
|
FileSize = fileSize;
|
|
ContentType = contentType;
|
|
StorageLocation = storageLocation ?? new StorageLocation();
|
|
CheckSum = checkSum;
|
|
}
|
|
|
|
public void StartUpload()
|
|
{
|
|
State = UploadTaskState.Uploading;
|
|
}
|
|
|
|
public void StartMerging(StorageLocation location)
|
|
{
|
|
StorageLocation = location;
|
|
State = UploadTaskState.Merging;
|
|
FailureReason = null;
|
|
NotifyModified();
|
|
}
|
|
|
|
public void CompleteUpload(Guid fileId)
|
|
{
|
|
ResultFileId = fileId;
|
|
State = UploadTaskState.Completed;
|
|
FailureReason = null;
|
|
NotifyModified();
|
|
AddDomainEvent(new UploadTaskCompletedDomainEvent(this));
|
|
}
|
|
|
|
public void Fail(string reason)
|
|
{
|
|
State = UploadTaskState.Failed;
|
|
FailureReason = reason.Length > 500 ? reason[..500] : reason;
|
|
NotifyModified();
|
|
}
|
|
}
|
|
}
|