Simplify download method

This commit is contained in:
Dean Herbert 2019-06-19 01:41:19 +09:00
parent f2e0ced052
commit 341dc74834
3 changed files with 16 additions and 31 deletions

View File

@ -78,7 +78,8 @@ public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, R
updateQueue = new BeatmapUpdateQueue(api);
}
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, object[] options) => new DownloadBeatmapSetRequest(set, (options?.FirstOrDefault() as bool?) ?? false);
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize) =>
new DownloadBeatmapSetRequest(set, minimiseDownloadSize);
protected override Task Populate(BeatmapSetInfo beatmapSet, ArchiveReader archive, CancellationToken cancellationToken = default)
{

View File

@ -42,30 +42,23 @@ protected DownloadableArchiveModelManager(Storage storage, IDatabaseContextFacto
/// <summary>
/// Creates the download request for this <see cref="TModel"/>.
/// The <paramref name="options"/> parameters will be provided when the download was initiated with extra options meant
/// to be used in the creation of the request.
/// </summary>
/// <param name="model">The <see cref="TModel"/> to be downloaded.</param>
/// <param name="options">Extra parameters for request creation, null if none were passed.</param>
/// <param name="minimiseDownloadSize">Whether this download should be optimised for slow connections. Generally means extras are not included in the download bundle..</param>
/// <returns>The request object.</returns>
protected abstract ArchiveDownloadRequest<TModel> CreateDownloadRequest(TModel model, object[] options);
protected abstract ArchiveDownloadRequest<TModel> CreateDownloadRequest(TModel model, bool minimiseDownloadSize);
public bool Download(TModel model)
/// <summary>
/// Begin a download for the requested <see cref="TModel"/>.
/// </summary>
/// <param name="model">The <see cref="TModel"/> to be downloaded.</param>
/// <param name="minimiseDownloadSize">Whether this download should be optimised for slow connections. Generally means extras are not included in the download bundle..</param>
/// <returns>Whether the download was started.</returns>
public bool Download(TModel model, bool minimiseDownloadSize = false)
{
if (!canDownload(model)) return false;
var request = CreateDownloadRequest(model, null);
performDownloadWithRequest(request);
return true;
}
public bool Download(TModel model, params object[] extra)
{
if (!canDownload(model)) return false;
var request = CreateDownloadRequest(model, extra);
var request = CreateDownloadRequest(model, minimiseDownloadSize);
performDownloadWithRequest(request);

View File

@ -31,21 +31,12 @@ public interface IModelDownloader<TModel> : IModelManager<TModel>
bool IsAvailableLocally(TModel model);
/// <summary>
/// Downloads a <see cref="TModel"/>.
/// This may post notifications tracking progress.
/// Begin a download for the requested <see cref="TModel"/>.
/// </summary>
/// <param name="model">The <see cref="TModel"/> to be downloaded.</param>
/// <returns>Whether downloading can happen.</returns>
bool Download(TModel model);
/// <summary>
/// Downloads a <see cref="TModel"/> with optional parameters for the download request.
/// This may post notifications tracking progress.
/// </summary>
/// <param name="model">The <see cref="TModel"/> to be downloaded.</param>
/// <param name="extra">Optional parameters to be used for creating the download request.</param>
/// <returns>Whether downloading can happen.</returns>
bool Download(TModel model, params object[] extra);
/// <param name="minimiseDownloadSize">Whether this download should be optimised for slow connections. Generally means extras are not included in the download bundle..</param>
/// <returns>Whether the download was started.</returns>
bool Download(TModel model, bool minimiseDownloadSize);
/// <summary>
/// Gets an existing <see cref="TModel"/> download request if it exists.