public async Task <IDictionary <Guid, int> > LoadDownloadedFeeds() { var updated = await BackgroundDownload.LoadDownloadedFeedsAsync(_subscribedFeeds, _dbContext); //await SaveAsync(); return(updated); }
private void Image_Tapped(object sender, TappedRoutedEventArgs e) { Image im = sender as Image; bool isBegin = false; if (im.Name == "ImageStart") { this.ImageStart.Visibility = Visibility.Collapsed; this.ImagePauset.Visibility = Visibility.Visible; isBegin = true; } else { this.ImageStart.Visibility = Visibility.Visible; this.ImagePauset.Visibility = Visibility.Collapsed; } if (!isBegin) { _download.PauseAll(); } else { if (_download == null) { string url = CommonString.URL; _download = new BackgroundDownload(); _download.GetPercent += (current, total) => { PBarDownload.Value = current; TextBlockPercent.Text = current + "%"; if (current >= 100) { TextBlockState.Text = "下载完成"; _download = null; MyToast.ShowToast(" ", Global.Current.Globalization.Video_DownloadMessage); } }; _download.ErrorException += (o, s) => { TextBlockState.Text = "下载错误 " + s; }; TextBlockState.Text = "下载进度"; TextBlockPercent.Text = 0 + "%"; PBarDownload.Value = 0; _download.StartDownload(url); } else { TextBlockState.Text = Global.Current.Globalization.Video_Downloading; _download.ResumeAll(); } } }
private void OnBackgroundTransferRequestStateChanged(BackgroundTransferRequest request, EventArgsState e) { BackgroundDownload download = Requests.FirstOrDefault(r => r.Id == request.RequestId); if (download == null) { return; } download.Status = GetStatusText(e.State); if (e.State == DownloadRequestState.Downloading) { download.BytesReceived = request.BytesReceived; if (download.TotalBytesToReceive == -1) { download.TotalBytesToReceive = download.BytesReceived * 2; } } if (e.State == DownloadRequestState.Completed) { Requests.Remove(download); } TxtNothingToDownload.Visibility = Requests.Any() ? Visibility.Collapsed : Visibility.Visible; }
IEnumerator DownloadFileTest(string filePath) { using (var download = BackgroundDownload.Start(new Uri(TEST_URL), filePath)) { yield return(download); Assert.AreEqual(BackgroundDownloadStatus.Done, download.status); Assert.IsTrue(File.Exists(Path.Combine(Application.persistentDataPath, filePath))); } }
IEnumerator WaitForDownload(BackgroundDownload download) { yield return(download); if (download.status == BackgroundDownloadStatus.Done) { Debug.Log("File successfully downloaded"); } else { Debug.Log("File download failed with error: " + download.error); } }
private void DownloadFile(bool isBegin) { SetButtonVisable(isBegin); if (!isBegin) { StateTextBlock.Text = Global.Current.Globalization.Video_Pause; _download.PauseAll(); } else { if (_download == null) { var url = CommonString.URL; _download = new BackgroundDownload(); _download.GetPercent += (current, total) => { PBar.Value = current; PercentTextBlock.Text = current + "%"; if (current >= 100) { SetButtonVisable(false); StateTextBlock.Text = Global.Current.Globalization.Video_DownloadMessage; _download = null; StartButton.IsEnabled = false; } }; _download.ErrorException += (sender, s) => { StateTextBlock.Text = Global.Current.Globalization.Video_DownloadError + ":" + s; }; StateTextBlock.Text = Global.Current.Globalization.Video_Downloading; PercentTextBlock.Text = 0 + "%"; PBar.Value = 0; _download.StartDownload(url); } else { StateTextBlock.Text = Global.Current.Globalization.Video_Downloading; _download.ResumeAll(); } } }
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 }, }; }
private async void GetMVDowning() { mvresult = await BackgroundDownload.GetList(BackgroundDownload.DownloadType.mv); if (mvresult != null) { MVDowningNum.Text = mvresult.transfers.Count.ToString(); MVFileNum.Text = mvresult.files.Count.ToString(); MVDowningList.ItemsSource = mvresult.transfers; LocalMVList.Items.Clear(); foreach (var file in mvresult.files) { LocalMVList.Items.Add(file); } } }
private async void GetSongDowning() { //await Task.Delay(3000); songresult = await BackgroundDownload.GetList(BackgroundDownload.DownloadType.song); if (songresult != null) { SongDowningNum.Text = songresult.transfers.Count.ToString(); SongFileNum.Text = songresult.files.Count.ToString(); SongDowningList.ItemsSource = songresult.transfers; LocalSongList.Items.Clear(); foreach (var file in songresult.files) { LocalSongList.Items.Add(file); } } }
/// <summary> /// Agent that runs a scheduled task /// </summary> /// <param name="task"> /// The invoked task /// </param> /// <remarks> /// This method is called when a periodic or resource intensive task is invoked /// Not over 25 seconds and comsumes 6MB RAM /// </remarks> /// protected override void OnInvoke(ScheduledTask task) { #if DEBUG //MemoryDiagnostic.BeginRecording(); #endif //TODO: Add code to perform your task in background try { if (!NetworkInterface.GetIsNetworkAvailable() || !AppConfig.AllowBackgroundUpdate || (AppConfig.DisAllowBackgroundInMidNight && IsMidNight()) || (AppConfig.JustUpdateOverWifi && (!AppConfig.JustUpdateOverWifi || NetworkInterface.NetworkInterfaceType != NetworkInterfaceType.Wireless80211))) { var reason = string.Format("Exit - User allows: {0} - WifiOnly: {1} - CurrentNework: {2} - DisAllowInMidNight: {3} - CurrentTime: {4}", AppConfig.AllowBackgroundUpdate, AppConfig.JustUpdateOverWifi, NetworkInterface.NetworkInterfaceType.ToString(), AppConfig.DisAllowBackgroundInMidNight, DateTime.Now.TimeOfDay.ToString()); GA.LogBackgroundAgent(reason, 0); return; } var feedsDownloaded = BackgroundDownload.DownloadFeeds(); if (feedsDownloaded != null && feedsDownloaded.Count > 0) { BackgroundDownload.PostDownload(feedsDownloaded); BackgroundDownload.CleanOldFiles(); GA.LogBackgroundAgent("Downloaded completed", feedsDownloaded.Sum(f => f.Items.Count)); } } catch (OutOfMemoryException) { } catch (Exception ex) { GA.LogException(ex); } finally { NotifyComplete(); } }
void Start() { string fileName = "success.jpb"; string destinationFile = Path.Combine(Application.persistentDataPath, fileName); if (File.Exists(destinationFile)) { Debug.Log("File already downloaded"); return; } var downloads = BackgroundDownload.backgroundDownloads; if (downloads.Length > 0) { StartCoroutine(WaitForDownload(downloads[0])); } else { Uri url = new Uri("https://memegenerator.net/img/images/1154731/success-baby.jpg"); StartCoroutine(WaitForDownload(BackgroundDownload.Start(url, fileName))); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { Requests.Clear(); foreach (var r in BackgroundTransferService.Requests) { var bd = new BackgroundDownload { Id = r.RequestId, Filename = r.Tag, BytesReceived = r.BytesReceived, TotalBytesToReceive = r.TotalBytesToReceive }; if (bd.TotalBytesToReceive == -1) { bd.TotalBytesToReceive = bd.BytesReceived * 2; } Requests.Add(bd); } TxtNothingToDownload.Visibility = Requests.Any() ? Visibility.Collapsed : Visibility.Visible; }
public void Cancel(BackgroundDownload backgroundDownload) { backgroundDownload.CancellationTokenSrc.Cancel(); }
public void CreateFeedsToUpdate() { BackgroundDownload.CreateFeedsToDownload(_subscribedFeeds); }
// monitor this download in a progress box to either abort or completion public abstract void DownloadProgressBox(BackgroundDownload bgl, string title, int progress_start = 0, int progress_end = 100);