* 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>
		
			
				
	
	
		
			93 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			93 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
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;
 | 
						|
    }
 | 
						|
} |