Make IFileStreamProvider more generic

- Move SetError up to IFileUploadTicket.
- Move from Transfer to IO namespace.
This commit is contained in:
Dominion
2023-06-09 13:23:37 -04:00
parent a8ae1e9e32
commit 3a6dfa8936
4 changed files with 13 additions and 25 deletions
@@ -3,9 +3,6 @@ using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Host.Transfer;
namespace Tgstation.Server.Host.IO
{
/// <summary>
@@ -98,11 +95,5 @@ namespace Tgstation.Server.Host.IO
return await localTask;
}
}
/// <inheritdoc />
public void SetError(ErrorCode errorCode, string additionalData)
{
// no-op
}
}
}
@@ -3,9 +3,7 @@ using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
namespace Tgstation.Server.Host.Transfer
namespace Tgstation.Server.Host.IO
{
/// <summary>
/// Interface for asynchronously consuming <see cref="Stream"/>s of files.
@@ -16,15 +14,8 @@ namespace Tgstation.Server.Host.Transfer
/// Gets the <see cref="Stream"/> for the file to consume. May be called multiple times, though cancelling any may cause all calls to be cancelled. All calls yield the same <see cref="Stream"/> reference.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the uploaded <see cref="Stream"/> of the file on success, <see langword="null"/> if the file could not be provider.</returns>
/// <remarks>The resulting <see cref="Stream"/> is owned by the <see cref="IFileStreamProvider"/> and is short lived. It should be buffered if it needs use outside the lifetime of the <see cref="IFileStreamProvider"/>.</remarks>
/// <returns>A <see cref="Task{TResult}"/> resulting in the uploaded <see cref="Stream"/> of the file on success, <see langword="null"/> if it could not be provided.</returns>
/// <remarks>The resulting <see cref="Stream"/> is owned by the <see cref="IFileStreamProvider"/> and is short lived unless otherwise specified. It should be buffered if it needs use outside the lifetime of the <see cref="IFileStreamProvider"/>.</remarks>
Task<Stream> GetResult(CancellationToken cancellationToken);
/// <summary>
/// Sets an <paramref name="errorCode"/> that indicates why the consuming operation could not complete. May only be called once on a <see cref="IFileStreamProvider"/>.
/// </summary>
/// <param name="errorCode">The <see cref="ErrorCode"/> to set.</param>
/// <param name="additionalData">Any additional information that can be provided about the error.</param>
void SetError(ErrorCode errorCode, string additionalData);
}
}
@@ -1,4 +1,6 @@
using Tgstation.Server.Api.Models.Response;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Response;
using Tgstation.Server.Host.IO;
namespace Tgstation.Server.Host.Transfer
{
@@ -11,5 +13,12 @@ namespace Tgstation.Server.Host.Transfer
/// The <see cref="FileTicketResponse"/>.
/// </summary>
FileTicketResponse Ticket { get; }
/// <summary>
/// Sets an <paramref name="errorCode"/> that indicates why the consuming operation could not complete. May only be called once on a <see cref="IFileStreamProvider"/>.
/// </summary>
/// <param name="errorCode">The <see cref="ErrorCode"/> to set.</param>
/// <param name="additionalData">Any additional information that can be provided about the error.</param>
void SetError(ErrorCode errorCode, string additionalData);
}
}
@@ -99,9 +99,6 @@ namespace Tgstation.Server.Host.IO.Tests
await Assert.ThrowsExceptionAsync<TaskCanceledException>(() => task2);
await Assert.ThrowsExceptionAsync<TaskCanceledException>(() => task3);
// code coverage
downloader.SetError(ErrorCode.BadHeaders, null);
mockFileDownloader.VerifyAll();
}
}