public static BackgroundDownload Download(Uri url, string destination) { var download = new BackgroundDownload(); //We dont want to await this. Just get it started #pragma warning disable 4014 download.DownloadFileAsync(url, destination); #pragma warning restore 4014 return(download); }
internal static void AddController(string url, BackgroundDownload controller) { lock (locker) { var list = GetControllers(url) ?? new List <BackgroundDownload>(); list.Add(controller); } BackgroundDownloadFile file; if (!Files.TryGetValue(url, out file)) { Files [url] = file = new BackgroundDownloadFile { Destination = controller.Destination, Url = url, }; saveState(); } }
public RootViewController() { var downloadButton = View = stackPanel = new StackPanel () { new SimpleButton { Title = "Simple ActionSheet", BackgroundColor = UIColor.Gray, Tapped = (btn) => { var popup = new SimpleActionSheet () { {"Red",UIColor.Red,()=> Console.WriteLine("red")}, {"Blue", UIColor.Blue, ()=> Console.WriteLine("Blue")}, {"Black", UIColor.Black, ()=> Console.WriteLine("Black")}, {"Green", UIColor.Green, ()=> Console.WriteLine("Green")}, {"Cancel",()=> Console.WriteLine("Cancel")} }; popup.ShowInView(View); } }, new SimpleButton{ Title = "I move on tilt", BackgroundColor = UIColor.Gray, }.AddMotion(-100,100), new SimpleButton{ Title = "Click to download", BackgroundColor = UIColor.Gray, Tapped = async (btn)=>{ btn.Enabled = false; var endPath = Path.Combine(DocumentsFolder,"test.zip"); if(File.Exists(endPath)) File.Delete(endPath); var downloader = new BackgroundDownload(); downloader.ProgressChanged += (float obj) => Device.EnsureInvokedOnMainThread(()=> btn.Title = obj.ToString()); await downloader.DownloadFileAsync(new Uri("http://ipv4.download.thinkbroadband.com/5MB.zip"),endPath ); btn.Title = "Click to download"; btn.Enabled = true; } }, new UIImageView(UIImage.FromBundle("monkey").Blur(30)) { ContentMode = UIViewContentMode.ScaleAspectFill }, }; }
async static void restoreTasks(NSUrlSession ses, NSUrlSessionDataTask[] sessions, NSUrlSessionUploadTask[] uploads, NSUrlSessionDownloadTask[] downloads) { List<BackgroundDownload> restoredDownloads = new List<BackgroundDownload>(); foreach(var d in downloads) { var url = d.OriginalRequest.Url.AbsoluteString; if(d.Error != null) { BackgroundDownloadManager.Errored(d); } BackgroundDownload download; BackgroundDownloadManager.BackgroundDownloadFile downloadFile; download = new BackgroundDownload (d) { SessionId = ses.Configuration.Identifier, }; foreach(var key in BackgroundDownloadManager.Files) { Console.WriteLine(key.Key); } if(BackgroundDownloadManager.Files.TryGetValue(url, out downloadFile)) download.Destination = downloadFile.Destination; BackgroundDownloadManager.AddController (url, download); restoredDownloads.Add(download); } if(RestoredDownloads != null) { RestoredDownloads(restoredDownloads); } }
internal static void AddController(string url, BackgroundDownload controller) { lock (locker) { var list = GetControllers (url) ?? new List<BackgroundDownload>(); list.Add (controller); } BackgroundDownloadFile file; if (!Files.TryGetValue (url, out file)) { Files [url] = file = new BackgroundDownloadFile { Destination = controller.Destination, Url = url, }; saveState (); } }
public static BackgroundDownload Download(Uri url, string destination) { var download = new BackgroundDownload (); //We dont want to await this. Just get it started #pragma warning disable 4014 download.DownloadFileAsync (url, destination); #pragma warning restore 4014 return download; }
internal static void AddController(string url, BackgroundDownload controller) { lock (locker) { var list = GetControllers (url) ?? new List<BackgroundDownload>(); list.Add (controller); } BackgroundDownloadFile file; if (!Files.TryGetValue (url, out file)) { Console.WriteLine ("Adding URL {0}", url); Files [url] = file = new BackgroundDownloadFile { Destination = MakeRelativePath(BaseDir, controller.Destination), Url = url, SessionId = controller.SessionId }; } saveState (); }