Beispiel #1
0
        async void PauseOnce(DownloadOperation download)
        {
            download.Pause();
            await Task.Delay(100);

            download.Resume();
        }
Beispiel #2
0
 public void ResumeDownload(DownloadOperation download)
 {
     if (download.Progress.Status == BackgroundTransferStatus.PausedByApplication)
     {
         download.Resume();
     }
 }
 public void Resume()
 {
     if (op.Progress.Status == BackgroundTransferStatus.PausedByApplication)
     {
         op.Resume();
     }
     OnPropertyChanged("CanPause");
     OnPropertyChanged("CanResume");
 }
Beispiel #4
0
 private void ResumeDownload_Click(object sender, RoutedEventArgs e)
 {
     if (download != null)
     {
         download.Resume();
         pauseDownloadButton.IsEnabled  = true;
         resumeDownloadButton.IsEnabled = false;
     }
 }
        private async void OnDownloadProgress(IAsyncOperationWithProgress <DownloadOperation, DownloadOperation> sender, DownloadOperation progress)
        {
            // We capture a snapshot of DownloadOperation.Progress because
            // it is is updated in real-time while the operation is ongoing.
            BackgroundDownloadProgress currentProgress = progress.Progress;

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                // Prepare the progress message to display in the UI.
                ulong percent = 100;
                if (currentProgress.TotalBytesToReceive > 0)
                {
                    percent = currentProgress.BytesReceived * 100 / currentProgress.TotalBytesToReceive;
                }

                DownloadedStatusText.Text = $"{currentProgress.Status} - {percent}% downloaded.";

                if (currentProgress.HasRestarted)
                {
                    rootPage.NotifyUser("Download has restarted.", NotifyType.StatusMessage);
                }

                if (currentProgress.Status == BackgroundTransferStatus.PausedRecoverableWebErrorStatus)
                {
                    // The only value we put in RecoverableWebErrorStatuses is WebErrorStatus.Forbidden,
                    // so that will be the only value observed here.
                    System.Diagnostics.Debug.Assert(download.CurrentWebErrorStatus == WebErrorStatus.Forbidden);

                    rootPage.NotifyUser("URL has expired.", NotifyType.ErrorMessage);

                    // The URL expired. Ask the user for information so we can get a new URL.
                    ContentDialogResult result = await ReauthorizeDialog.ShowAsync();

                    if (result == ContentDialogResult.Primary)
                    {
                        // For the purpose of this sample, we simply remove "?shouldExpire=yes" from the URL
                        // to indicate that the sample server should treat it like a new, unexpired URL.
                        string originalUrlString = download.RequestedUri.OriginalString;
                        string newUrlString      = originalUrlString.Replace("?shouldExpire=yes", "");

                        rootPage.NotifyUser("Updating URL and resuming the download.", NotifyType.StatusMessage);
                        download.RequestedUri = new Uri(newUrlString);
                        download.Resume();
                    }
                    else
                    {
                        // Cancel the download.
                        downloadCancellationTokenSource.Cancel();
                        downloadCancellationTokenSource.Dispose();

                        // Re-create the CancellationTokenSource for future downloads.
                        downloadCancellationTokenSource = new CancellationTokenSource();
                    }
                }
            });
        }
        /// <summary>
        /// Возобновляет выполнение приостановленного запроса
        /// </summary>
        public void Resume()
        {
            if (State != RequestState.Paused)
            {
                return;
            }

            DownloadOperation.Resume();
            State = RequestState.Processing;
        }
 //resume a download operation
 public void ResumeDownload(Download download)
 {
     download.Status = "downloading";
     try
     {
         downloadOperation.Resume();
     } catch (InvalidOperationException)
     {
         UsefulMethods.UsefulMethods.ErrorMessage("Couldn't resume the download.");
     }
 }
Beispiel #8
0
 private void Resume_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (slowDownload != null)
         {
             slowDownload.Resume();
         }
     }
     catch (InvalidOperationException ex)
     {
         DisplayException(ex);
     }
 }
Beispiel #9
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            if ((string)b.Content == "Pause")
            {
                download.Pause();
                b.Content = "Resume";
            }
            else
            {
                download.Resume();
                b.Content = "Pause";
            }
        }
 private void BtPauseDownload_Click(object sender, RoutedEventArgs e)
 {
     if (DownloadFile.Progress.Status != BackgroundTransferStatus.PausedByApplication)
     {
         DownloadFile.Pause();
         tbSize.Text     = "Resuming";
         btPause.Content = "\uE103";
     }
     else
     {
         DownloadFile.Resume();
         tbSize.Text     = "Downloading Paused";
         btPause.Content = "\uE102";
     }
 }
 public void resume(DownloadOperation download)
 {
     try
     {
         download.Resume();
     }
     catch (Exception ex)
     {
     }
     finally
     {
         PauseEnabled  = true;
         ResumeEnabled = false;
         Status        = download.Progress.Status.ToString();
     }
 }
Beispiel #12
0
        public async void AttachAsync()
        {
            var progress = DownloadOperation.AttachAsync();

            progress.Progress = (_, op) => OnProgress(op);
            await progress
            .AsTask()
            .ContinueWith(OnDownloadCompleted);

            try
            {
                DownloadOperation.Resume();
            }
            catch
            {
                if (DownloadOperation.Progress.Status != BackgroundTransferStatus.Running)
                {
                    Failed?.Invoke(this, EventArgs.Empty);
                }
            }
        }
Beispiel #13
0
 private void btnPauseResume_Click(object sender, RoutedEventArgs e)
 {
     if (btnPauseResume.Content.ToString().ToLower().Equals("pause"))
     {
         try
         {
             downloadOperation.Pause();
         }
         catch (InvalidOperationException)
         {
         }
     }
     else
     {
         try
         {
             downloadOperation.Resume();
         }
         catch (InvalidOperationException)
         { }
     }
 }
    private void StartDownload(Operation operationToStart, bool attachToExisting, bool handleCompleteness)
    {
        DownloadOperation operation = operationToStart.operation;

        if (operation.Progress.Status == BackgroundTransferStatus.Canceled || operation.Progress.Status == BackgroundTransferStatus.Error)
        {
            if (_operations.ContainsKey(operation.RequestedUri))
            {
                _operations.Remove(operation.RequestedUri);
            }

            if (operation.ResultFile != null)
            {
                try
                {
#pragma warning disable 4014
                    operation.ResultFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
#pragma warning restore 4014
                }
                catch { }
            }

            Task.Run(() =>
            {
                UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                {
                    try
                    {
                        operationToStart.FireComplete(operation.RequestedUri, string.Empty, false);
                    }
                    catch { }
                }, false);
            });

            return;
        }

        operation.RangesDownloaded += (DownloadOperation sender, BackgroundTransferRangesDownloadedEventArgs args) =>
        {
            UnityEngine.WSA.Application.InvokeOnAppThread(() =>
            {
                if (_operations.ContainsKey(sender.RequestedUri))
                {
                    try
                    {
                        _operations[sender.RequestedUri].FireProgress(sender.RequestedUri, sender.Progress.BytesReceived, sender.Progress.TotalBytesToReceive);
                    }
                    catch { }
                }
            }, false);
        };

        var initialStatus = operation.Progress.Status;
        if (initialStatus == BackgroundTransferStatus.PausedByApplication ||
            initialStatus == BackgroundTransferStatus.PausedRecoverableWebErrorStatus)
        {
            operation.Resume();
        }

        bool bAttach = attachToExisting ||
                       (initialStatus == BackgroundTransferStatus.Running);

        Task <DownloadOperation> task = bAttach ? operation.AttachAsync().AsTask() : operation.StartAsync().AsTask();

        if (handleCompleteness)
        {
            task.ContinueWith(async(Task <DownloadOperation> resOperation) =>
            {
                if (!attachToExisting && _operations.ContainsKey(operation.RequestedUri))
                {
                    _operations.Remove(operation.RequestedUri);
                }

                var status = resOperation.Result.Progress.Status;

                bool bRes = resOperation.Status == TaskStatus.RanToCompletion &&
                            (status == BackgroundTransferStatus.Completed ||
                             (status == BackgroundTransferStatus.Idle && operation.Progress.BytesReceived == operation.Progress.TotalBytesToReceive));

                if (resOperation.Status == TaskStatus.Faulted || resOperation.Status == TaskStatus.Canceled ||
                    resOperation.Result.Progress.Status == BackgroundTransferStatus.Error || resOperation.Result.Progress.Status == BackgroundTransferStatus.Canceled)
                {
                    if (operation.ResultFile != null)
                    {
                        try
                        {
                            await operation.ResultFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
                        }
                        catch { }
                    }
                }

#pragma warning disable 4014
                Task.Run(() =>
                {
                    UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                    {
                        try
                        {
                            operationToStart.FireComplete(operation.RequestedUri, operation.ResultFile.Path, bRes);
                        }
                        catch { }
                    }, false);
                });
#pragma warning restore 4014
            });
        }
    }
Beispiel #15
0
 public void Resume()
 {
     DownloadOperation.Resume();
     DownloadStatus = DownloadStatus.Run;
 }
Beispiel #16
0
 private void btn_resume_Click(object sender, RoutedEventArgs e)
 {
     downloadOperation.Resume();
 }
 internal void ResumeDownloadAction()
 {
     downloadOperation.Resume();
 }