public PaginatedContentSource(Func <ContentEntry, object> getViewModel, IContentProviderService service, ContentSearchOptions options, ContentPage initialPage) { if (initialPage is null) { throw new ArgumentNullException(nameof(initialPage)); } this.getViewModel = getViewModel; this.service = service ?? throw new ArgumentNullException(nameof(service)); this.options = options ?? throw new ArgumentNullException(nameof(options)); this.items.AddRange(initialPage.Entries.Select(e => getViewModel(e))); this.pageSize = initialPage.Entries.Count; }
public async Task EnsurePresentAsync(FileSample sample, IProgress <double> progress = null, CancellationToken cancellationToken = default) { if (sample is null) { throw new ArgumentNullException(nameof(sample)); } if (await this.storage.GetIsPresentAsync(sample.Id, sample.ContentHash)) { progress?.Report(1); return; } if (!this.settings.DownloadInBackground) { Task <bool> downloadQuestionTask; if (this.downloadInBackground != null) { downloadQuestionTask = this.downloadInBackground; } else { lock (this.settings) { if (this.downloadInBackground == null) { // TODO: Localize var prompt = new PromptMessage("Download missing files", "Some of the files for these elements are missing. Would you like to download them now?", "Download"); Messenger.Default.Send(prompt); this.downloadInBackground = prompt.Result; downloadQuestionTask = this.downloadInBackground; } else { downloadQuestionTask = this.downloadInBackground; } } } if (!await downloadQuestionTask) { progress?.Report(1); return; } } IContentProviderService[] providers = await this.services.GetServicesAsync <IContentProviderService> ().ConfigureAwait(false); IContentProviderService handler = providers.FirstOrDefault(c => c.CanAcquire(sample)); ManagedDownload download = null; if (handler != null) { string id = handler.GetEntryIdFromUrl(sample.SourceUrl); if (id != null) { ContentEntry entry = await handler.GetEntryAsync(id, cancellationToken); download = QueueDownload(sample.Id, sample.Name, handler.DownloadEntryAsync(id), entry.Size, sample.ContentHash, progress, cancellationToken); } } if (download == null) { if (!Uri.TryCreate(sample.SourceUrl, UriKind.Absolute, out Uri uri)) { progress?.Report(1); throw new ArgumentException(); } if (uri.IsFile) { if (await this.storage.GetIsPresentAsync(uri)) { progress?.Report(1); return; } else { progress?.Report(1); throw new FileNotFoundException(); } } download = QueueDownload(sample.Id, sample.Name, new Uri(sample.SourceUrl), sample.ContentHash, progress, cancellationToken); } await download.Task; }
internal ContentProviderModelValidator() { ContentProviderService = new DdsContentProviderService(); }