public async Task Download(Progress <double> progress = null) { HttpResponse r; r. var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader(); Task s; // Create a new download operation. var ownload = downloader.CreateDownload(null, null, null).StartAsync().AsTask().w; // Start the download and persist the promise to be able to cancel the download. promise = ownload.Progress....startAsync().then(complete, error, progress); }
internal async void Save() { var url = new Uri(post.photourl.First().Value); var folder = KnownFolders.PicturesLibrary; var photoFile = await folder.CreateFileAsync($"tumblrViewer.jpg", CreationCollisionOption.GenerateUniqueName); var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader(); var dl = downloader.CreateDownload(url, photoFile); await dl.StartAsync(); SavedPopUp(); }
private async void Player(VoiceData data) { if (data.source.Contains("http://")) { var file = await(await appFolder.CreateFolderAsync("WelcomeVoice", CreationCollisionOption.OpenIfExists)).CreateFileAsync(data.id.ToString() + ".mp3", CreationCollisionOption.ReplaceExisting); var downer = new Windows.Networking.BackgroundTransfer.BackgroundDownloader(); var downop = downer.CreateDownload(new Uri(data.source), file); await downop.StartAsync(); mediaplayer.SetSource(await file.OpenReadAsync(), file.ContentType); } else { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(data.source)); mediaplayer.SetSource(await file.OpenReadAsync(), file.ContentType); } }
/// <summary> /// Initiate the download of the user its profile picture /// </summary> public async Task LoadProfilePicture() { try { StorageFolder LocalFolder = ApplicationData.Current.LocalFolder; StorageFile File = await LocalFolder.CreateFileAsync(ID + ".png", CreationCollisionOption.ReplaceExisting); var Downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader(); var DownloadOperation = Downloader.CreateDownload(new Uri(String.Format("https://apis.live.net/v5.0/{0}/picture", ID)), File); await ProcessDownloadProfilePicture(DownloadOperation, File); NotifyPropertyChanged("ProfilePicture"); } catch (Exception e) { ExtendedEventArgs eea = new ExtendedEventArgs(); eea.Error = String.Format("An error occurred while accessing the profile picture of your Microsoft account: {0}", e.Message); OnConnectionError(eea); } }
public static async Task AddTaskAsync(string url, string filename) { await getpicfolder(); string ex; try { ex = Path.GetExtension(url); } catch { ex = ".jpg"; } if (Uri.TryCreate(url, UriKind.Absolute, out Uri result)) { int policy; try { policy = (int)AppDataHelper.GetValue("BackgroundTransferCostPolicy"); } catch { policy = 0; } try { var file = await pictureFolder.CreateFileAsync(filename + ex, CreationCollisionOption.FailIfExists); Windows.Networking.BackgroundTransfer.BackgroundTransferCostPolicy costpolicy; switch (policy) { default: case 0: costpolicy = Windows.Networking.BackgroundTransfer.BackgroundTransferCostPolicy.UnrestrictedOnly; break; case 1: costpolicy = Windows.Networking.BackgroundTransfer.BackgroundTransferCostPolicy.Default; break; case 2: costpolicy = Windows.Networking.BackgroundTransfer.BackgroundTransferCostPolicy.Always; break; case 3: using (var res = await Data.TmpData.CurrentAuth.Tokens.SendRequestToGetImageAsync(Pixeez.MethodType.GET, url)) { using (var stream = await res.GetResponseStreamAsync()) { using (var filestream = await file.OpenStreamForWriteAsync()) { await stream.CopyToAsync(filestream); } } } return; } var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader() { CostPolicy = costpolicy }; downloader.SetRequestHeader("Referer", "https://app-api.pixiv.net/"); var op = downloader.CreateDownload(result, file); var a = op.StartAsync(); } catch { } } }
private async void Player(VoiceData data) { if(data.source.Contains("http://")) { var file = await (await appFolder.CreateFolderAsync("WelcomeVoice", CreationCollisionOption.OpenIfExists)).CreateFileAsync(data.id.ToString() + ".mp3", CreationCollisionOption.ReplaceExisting); var downer = new Windows.Networking.BackgroundTransfer.BackgroundDownloader(); var downop= downer.CreateDownload(new Uri(data.source), file); await downop.StartAsync(); mediaplayer.SetSource(await file.OpenReadAsync(), file.ContentType); } else { var file =await StorageFile.GetFileFromApplicationUriAsync(new Uri(data.source)); mediaplayer.SetSource(await file.OpenReadAsync(), file.ContentType); } }