Beispiel #1
0
            public override void DidWriteData(NSUrlSession session, NSUrlSessionDownloadTask downloadTask, long bytesWritten, long totalBytesWritten, long totalBytesExpectedToWrite)
            {
                float progress = totalBytesWritten / (float)totalBytesExpectedToWrite;

                Console.WriteLine(string.Format("DownloadTask: {0}  progress: {1}", downloadTask.Handle.ToString(), progress));
                BackgroundDownloadManager.UpdateProgress(downloadTask, progress);
            }
Beispiel #2
0
        public async Task DownloadFileAsync(Uri url, string destination)
        {
            this.url = url.AbsoluteUri;
            if (downloadTask != null)
            {
                return;
            }
            if (session == null)
            {
                session = InitBackgroundSession();
            }
            Destination = destination;
            if (!BackgroundDownloadManager.Tasks.TryGetValue(url.AbsoluteUri, out Tcs))
            {
                Tcs = new TaskCompletionSource <bool> ();
                BackgroundDownloadManager.Tasks.Add(url.AbsoluteUri, Tcs);
                using (var request = new NSUrlRequest(new NSUrl(url.AbsoluteUri))) {
                    downloadTask = session.CreateDownloadTask(request);
                    downloadTask.Resume();
                }
            }

            BackgroundDownloadManager.AddController(this.url, this);

            await Tcs.Task;
        }
Beispiel #3
0
 public override void DidCompleteWithError(NSUrlSession session, NSUrlSessionTask task, NSError error)
 {
     Console.WriteLine("DidCompleteWithError");
     if (error != null)
     {
         Console.WriteLine(error.LocalizedDescription);
         BackgroundDownloadManager.Failed(session, task, error);
     }
     else
     {
         Console.WriteLine("False positive");
     }
 }
Beispiel #4
0
 public override void DidFinishDownloading(NSUrlSession session, NSUrlSessionDownloadTask downloadTask, NSUrl location)
 {
     Console.WriteLine("File downloaded in : {0}", location);
     BackgroundDownloadManager.Completed(downloadTask, location);
 }
        internal static void UpdateProgress(string url, float progress)
        {
            var controllers = BackgroundDownloadManager.GetControllers(url);

            controllers.ForEach(x => Device.EnsureInvokedOnMainThread(() => x.Progress = progress));
        }