[Draft] Update 0.8 (#46)
* move stuff out into file transfer manager * obnoxious unsupported version text, adjustments to filetransfermanager * add back file upload transfer progress * restructure code * cleanup some more stuff I guess * downloadids by playername * individual anim/sound bs * fix migration stuff, finalize impl of individual sound/anim pause * fixes with logging stuff * move download manager to transient * rework dl ui first iteration * some refactoring and cleanup * more code cleanup * refactoring * switch to hostbuilder * some more rework I guess * more refactoring * clean up mediator calls and disposal * fun code cleanup * push error message when log level is set to anything but information in non-debug builds * remove notificationservice * move message to after login * add download bars to gameworld * fixes download progress bar * set gpose ui min and max size * remove unnecessary usings * adjustments to reconnection logic * add options to set visible/offline groups visibility * add impl of uploading display, transfer list in settings ui * attempt to fix issues with server selection * add back download status to compact ui * make dl bar fixed size based * some fixes for upload/download handling * adjust text from Syncing back to Uploading --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com> Co-authored-by: Stanley Dimant <stanley.dimant@varian.com>
This commit is contained in:
20
MareSynchronos/WebAPI/Files/Models/DownloadFileTransfer.cs
Normal file
20
MareSynchronos/WebAPI/Files/Models/DownloadFileTransfer.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using MareSynchronos.API.Dto.Files;
|
||||
|
||||
namespace MareSynchronos.WebAPI.Files.Models;
|
||||
|
||||
public class DownloadFileTransfer : FileTransfer
|
||||
{
|
||||
private DownloadFileDto Dto => (DownloadFileDto)TransferDto;
|
||||
public DownloadFileTransfer(DownloadFileDto dto) : base(dto) { }
|
||||
public Uri DownloadUri => new(Dto.Url);
|
||||
public override long Total
|
||||
{
|
||||
set
|
||||
{
|
||||
// nothing to set
|
||||
}
|
||||
get => Dto.Size;
|
||||
}
|
||||
|
||||
public override bool CanBeTransferred => Dto.FileExists && !Dto.IsForbidden && Dto.Size > 0;
|
||||
}
|
||||
10
MareSynchronos/WebAPI/Files/Models/DownloadStatus.cs
Normal file
10
MareSynchronos/WebAPI/Files/Models/DownloadStatus.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace MareSynchronos.WebAPI.Files.Models;
|
||||
|
||||
public enum DownloadStatus
|
||||
{
|
||||
Initializing,
|
||||
WaitingForSlot,
|
||||
WaitingForQueue,
|
||||
Downloading,
|
||||
Decompressing
|
||||
}
|
||||
10
MareSynchronos/WebAPI/Files/Models/FileDownloadStatus.cs
Normal file
10
MareSynchronos/WebAPI/Files/Models/FileDownloadStatus.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace MareSynchronos.WebAPI.Files.Models;
|
||||
|
||||
public class FileDownloadStatus
|
||||
{
|
||||
public DownloadStatus DownloadStatus { get; set; }
|
||||
public int TotalFiles { get; set; }
|
||||
public int TransferredFiles { get; set; }
|
||||
public long TotalBytes { get; set; }
|
||||
public long TransferredBytes { get; set; }
|
||||
}
|
||||
27
MareSynchronos/WebAPI/Files/Models/FileTransfer.cs
Normal file
27
MareSynchronos/WebAPI/Files/Models/FileTransfer.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using MareSynchronos.API.Dto.Files;
|
||||
|
||||
namespace MareSynchronos.WebAPI.Files.Models;
|
||||
|
||||
public abstract class FileTransfer
|
||||
{
|
||||
protected readonly ITransferFileDto TransferDto;
|
||||
|
||||
protected FileTransfer(ITransferFileDto transferDto)
|
||||
{
|
||||
TransferDto = transferDto;
|
||||
}
|
||||
|
||||
public string ForbiddenBy => TransferDto.ForbiddenBy;
|
||||
public long Transferred { get; set; } = 0;
|
||||
public abstract long Total { get; set; }
|
||||
public string Hash => TransferDto.Hash;
|
||||
public bool IsInTransfer => Transferred != Total && Transferred > 0;
|
||||
public bool IsTransferred => Transferred == Total;
|
||||
public virtual bool CanBeTransferred => !TransferDto.IsForbidden && (TransferDto is not DownloadFileDto dto || dto.FileExists);
|
||||
public bool IsForbidden => TransferDto.IsForbidden;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Hash;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using System.Net;
|
||||
|
||||
namespace MareSynchronos.WebAPI.Files.Models;
|
||||
|
||||
public class ProgressableStreamContent : StreamContent
|
||||
{
|
||||
private const int _defaultBufferSize = 4096;
|
||||
private readonly int _bufferSize;
|
||||
private readonly IProgress<UploadProgress> _progress;
|
||||
private readonly Stream _streamToWrite;
|
||||
private bool _contentConsumed;
|
||||
|
||||
public ProgressableStreamContent(Stream streamToWrite, IProgress<UploadProgress> downloader)
|
||||
: this(streamToWrite, _defaultBufferSize, downloader)
|
||||
{
|
||||
}
|
||||
|
||||
public ProgressableStreamContent(Stream streamToWrite, int bufferSize, IProgress<UploadProgress> progress)
|
||||
: base(streamToWrite, bufferSize)
|
||||
{
|
||||
if (streamToWrite == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(streamToWrite));
|
||||
}
|
||||
|
||||
if (bufferSize <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(bufferSize));
|
||||
}
|
||||
|
||||
_streamToWrite = streamToWrite;
|
||||
_bufferSize = bufferSize;
|
||||
_progress = progress;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_streamToWrite.Dispose();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext? context)
|
||||
{
|
||||
PrepareContent();
|
||||
|
||||
var buffer = new byte[_bufferSize];
|
||||
var size = _streamToWrite.Length;
|
||||
var uploaded = 0;
|
||||
|
||||
using (_streamToWrite)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var length = _streamToWrite.Read(buffer, 0, buffer.Length);
|
||||
if (length <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
uploaded += length;
|
||||
_progress.Report(new UploadProgress(uploaded, size));
|
||||
await stream.WriteAsync(buffer.AsMemory(0, length)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool TryComputeLength(out long length)
|
||||
{
|
||||
length = _streamToWrite.Length;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void PrepareContent()
|
||||
{
|
||||
if (_contentConsumed)
|
||||
{
|
||||
if (_streamToWrite.CanSeek)
|
||||
{
|
||||
_streamToWrite.Position = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("The stream has already been read.");
|
||||
}
|
||||
}
|
||||
|
||||
_contentConsumed = true;
|
||||
}
|
||||
}
|
||||
10
MareSynchronos/WebAPI/Files/Models/UploadFileTransfer.cs
Normal file
10
MareSynchronos/WebAPI/Files/Models/UploadFileTransfer.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using MareSynchronos.API.Dto.Files;
|
||||
|
||||
namespace MareSynchronos.WebAPI.Files.Models;
|
||||
|
||||
public class UploadFileTransfer : FileTransfer
|
||||
{
|
||||
public UploadFileTransfer(UploadFileDto dto) : base(dto) { }
|
||||
public override long Total { get; set; }
|
||||
public string LocalFile { get; set; } = string.Empty;
|
||||
}
|
||||
3
MareSynchronos/WebAPI/Files/Models/UploadProgress.cs
Normal file
3
MareSynchronos/WebAPI/Files/Models/UploadProgress.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace MareSynchronos.WebAPI.Files.Models;
|
||||
|
||||
public record UploadProgress(long Uploaded, long Size);
|
||||
Reference in New Issue
Block a user