protected AnimatedIllustrationDownloadTask(DownloadHistoryEntry databaseEntry)
     : base(databaseEntry)
 {
     // derived classes won't need them
     _metadata     = null !;
     _illustration = null !;
 }
        public Task <ObservableDownloadTask> TryCreateIntrinsicAsync(IllustrationViewModel context, IRandomAccessStream stream, string rawPath)
        {
            var entry = new DownloadHistoryEntry(DownloadState.Completed, null, rawPath, false, context.Id,
                                                 context.Illustration.Title, context.Illustration.User?.Name, null, null);

            return(Task.FromResult <ObservableDownloadTask>(new IntrinsicIllustrationDownloadTask(entry, context, stream)));
        }
 public AnimatedIllustrationDownloadTask(
     DownloadHistoryEntry databaseEntry,
     IllustrationViewModel illustration,
     UgoiraMetadataResponse metadata) : base(databaseEntry)
 {
     _illustration = illustration;
     _metadata     = metadata;
 }
        public async Task <ObservableDownloadTask> CreateAsync(IllustrationViewModel context, string rawPath)
        {
            using var scope = App.AppViewModel.AppServicesScope;
            var manager = await scope.ServiceProvider.GetRequiredService <Task <DownloadHistoryPersistentManager> >();

            var path = IOHelper.NormalizePath(PathParser.Reduce(rawPath, context));

            if ((await manager.RawDataAsync()).Any(entry => entry.Destination == path))
            {
                // delete the original entry
                await manager.DeleteAsync(entry => entry.Destination == path);
            }
            ObservableDownloadTask task = context.Illustration.IsUgoira() switch
            {
                true => await Functions.Block(async() =>
                {
                    var ugoiraMetadata = await App.AppViewModel.MakoClient.GetUgoiraMetadataAsync(context.Id);
                    if (ugoiraMetadata.UgoiraMetadataInfo?.ZipUrls?.Medium is { } url)
                    {
                        var downloadHistoryEntry = new DownloadHistoryEntry(DownloadState.Created, null, path, true, context.Id, context.Illustration.Title, context.Illustration.User?.Name, url, context.Illustration.GetThumbnailUrl(ThumbnailUrlOption.SquareMedium));
                        return(new AnimatedIllustrationDownloadTask(downloadHistoryEntry, context, ugoiraMetadata));
                    }

                    throw new DownloadTaskInitializationException(DownloadTaskResources.GifSourceUrlNotFoundFormatted.Format(context.Id));
                }),
                false => Functions.Block(() =>
                {
                    var downloadHistoryEntry = new DownloadHistoryEntry(DownloadState.Created, null, path, false, context.Id, context.Illustration.Title, context.Illustration.User?.Name, context.Illustration.GetOriginalUrl() !, context.Illustration.GetThumbnailUrl(ThumbnailUrlOption.SquareMedium));
                    return(new IllustrationDownloadTask(downloadHistoryEntry, context));
                })
            };

            // TODO Check for unique
            await manager.InsertAsync(task.DatabaseEntry);

            return(task);
        }
Beispiel #5
0
 public LazyInitializedAnimatedIllustrationDownloadTask(DownloadHistoryEntry databaseEntry) : base(databaseEntry)
 {
     _illustId        = databaseEntry.Id !;
     _resultGenerator = new Lazy <Task <IllustrationViewModel> >(async() => new IllustrationViewModel(await App.AppViewModel.MakoClient.GetIllustrationFromIdAsync(_illustId)));
 }
Beispiel #6
0
 /// <summary>
 /// The disposal of <paramref name="imageStream"/> is not handled
 /// </summary>
 public IntrinsicIllustrationDownloadTask(DownloadHistoryEntry entry, IllustrationViewModel illustrationViewModel, IRandomAccessStream imageStream)
     : base(entry, illustrationViewModel)
 {
     Stream = imageStream;
 }
Beispiel #7
0
 protected ObservableDownloadTask(DownloadHistoryEntry entry)
 {
     DatabaseEntry      = entry;
     CancellationHandle = new CancellationHandle();
     Completion         = new TaskCompletionSource();
 }
Beispiel #8
0
 public IllustrationDownloadTask(DownloadHistoryEntry dataBaseEntry, IllustrationViewModel illustrationViewModel) : base(dataBaseEntry)
 {
     IllustrationViewModel = illustrationViewModel;
     CurrentState          = DownloadState.Created;
 }