Exemple #1
0
        private async Task Download(TDownloadTask task)
        {
            IncrementCounter();

            var args = new DownloadStartingEventArgs();

            task.DownloadStarting(args);
            if (await args.DeferralAwaiter)
            {
                await DownloadInternal(task);
            }

            await DecrementCounterAsync();
        }
Exemple #2
0
        public override async void DownloadStarting(DownloadStartingEventArgs args)
        {
            var deferral = args.GetDeferral();

            if (!App.AppViewModel.AppSetting.OverwriteDownloadedFile && File.Exists(Destination))
            {
                ProgressPercentage = 100;
                CurrentState       = DownloadState.Completed;
                deferral.Complete(false);
                return;
            }
            if (App.AppViewModel.AppSetting.UseFileCache && await App.AppViewModel.Cache.TryGetAsync <IRandomAccessStream>(IllustrationViewModel.Illustration.GetIllustrationOriginalImageCacheKey()) is { } stream)
            {
                // fast path
                deferral.Complete(false);
                ProgressPercentage = 100;
                try
                {
                    using (stream)
                    {
                        IOHelper.CreateParentDirectories(Destination);
                        await using var fs = File.Open(Destination, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
                        await stream.AsStreamForRead().CopyToAsync(fs);
                    }
                }
                catch (Exception e)
                {
                    CurrentState = DownloadState.Error;
                    ErrorCause   = e;
                    return;
                }
                CurrentState = DownloadState.Completed;
            }
            // slow path
            deferral.Complete(true);
        }
Exemple #3
0
 public override async void DownloadStarting(DownloadStartingEventArgs args)
 {
     args.GetDeferral().Complete(false);
     await IOHelper.CreateAndWriteToFileAsync(Stream, Destination);
 }
 public override void DownloadStarting(DownloadStartingEventArgs args)
 {
     args.GetDeferral().Complete(App.AppViewModel.AppSetting.OverwriteDownloadedFile || !File.Exists(Destination));
 }