public DownloadViewModel(ActiveDownload activeDownload) { Name = activeDownload.Name; var dp = activeDownload.Progress .Sample(TimeSpan.FromMilliseconds(100)) .Buffer(2, 1) .Select(progList => new DownloadProgressCombined(progList.Last(), progList.First())); speed = LogErrorsAndDispose(dp .Select(p => p.Speed.Humanize("G03")) .ToProperty(this, x => x.Speed, scheduler: RxApp.MainThreadScheduler)); downloaded = LogErrorsAndDispose(activeDownload.Progress .Sample(TimeSpan.FromMilliseconds(250)) .Select(p => p.Downloaded.Humanize("G03")) .ToProperty(this, x => x.Downloaded, scheduler: RxApp.MainThreadScheduler)); var dpRealtime = activeDownload.Progress .Sample(TimeSpan.FromSeconds(1.0 / 60)); progress = LogErrorsAndDispose(dpRealtime .Where(p => p.Size.Bits > 0) .Select(p => 100d * p.Downloaded.Bits / p.Size.Bits) .ToProperty(this, x => x.Progress, scheduler: RxApp.MainThreadScheduler)); size = LogErrorsAndDispose(dpRealtime .Select(p => p.Size.Humanize("G03")) .ToProperty(this, x => x.Size, scheduler: RxApp.MainThreadScheduler)); state = LogErrorsAndDispose(dpRealtime .Select(p => p.State) .ToProperty(this, x => x.State, scheduler: RxApp.MainThreadScheduler)); status = LogErrorsAndDispose(dp .Select(p => $"{p.Current.Downloaded.Humanize("G03")}/{p.Current.Size.Humanize("G03")} @ {p.Speed.Humanize("G03")}") .ToProperty(this, x => x.Status, scheduler: RxApp.MainThreadScheduler)); }
public async Task Download() { if (!this.ActiveDownload.IsDownloading) { // If downloaded offline and stuck in temp storage if (await FileUtils.FileExists(FileUtils.BaseFolder, _zipFileName)) { await ActiveDownload.FinishDownload(await FileUtils.GetFile(FileUtils.BaseFolder, _zipFileName)); ActiveDownload.Reset(); if (await FileUtils.HaveAllImages()) { return; } } if (!this.HasAskedToDownload) { this.HasAskedToDownload = true; var askingToDownloadResult = await QuranApp.NativeProvider.ShowQuestionMessageBox(Resources.downloadPrompt, Resources.downloadPrompt_title); if (askingToDownloadResult) { await ActiveDownload.DownloadSingleFile(_zipFileServerUrl, Path.Combine(FileUtils.BaseFolder.Path, _zipFileName)); } } } }
public void FinishActionCalls() { var finishedCalled = false; var prog = new Subject <DownloadProgress>(); var ad = new ActiveDownload(prog.Publish(), () => finishedCalled = true, ""); prog.OnCompleted(); finishedCalled.Should().BeTrue("because ActiveDownload should be called when download is finished"); }
public override async Task Initialize() { _zipFileServerUrl = FileUtils.GetZipFileUrl(); _zipFileName = Path.GetFileName(_zipFileServerUrl); if (!this.IsDataLoaded) { LoadSuraList(); LoadJuz2List(); this.IsDataLoaded = true; } await LoadBookmarkList(); await ActiveDownload.Initialize(); }
private void c_oWorldWindow_Updated(object sender, EventArgs e) { int iBuilderPos, iBuilderTotal; // Do the work in the update thread and just invoke to update the GUI int iPos = 0; int iTotal = 0; bool bDownloading = false; List<ActiveDownload> currentList = new List<ActiveDownload>(); RenderableObject roBMNG = GetActiveBMNG(); if (roBMNG != null && roBMNG.IsOn && ((QuadTileSet)((RenderableObjectList)roBMNG).ChildObjects[1]).bIsDownloading(out iBuilderPos, out iBuilderTotal)) { bDownloading = true; iPos += iBuilderPos; iTotal += iBuilderTotal; ActiveDownload dl = new ActiveDownload(); dl.builder = null; dl.bOn = true; dl.bRead = false; currentList.Add(dl); } foreach (LayerBuilder oBuilder in c_oLayerList.AllLayers) { if (oBuilder.bIsDownloading(out iBuilderPos, out iBuilderTotal)) { bDownloading = true; iPos += iBuilderPos; iTotal += iBuilderTotal; ActiveDownload dl = new ActiveDownload(); dl.builder = oBuilder; dl.bOn = true; dl.bRead = false; currentList.Add(dl); } } // In rare cases, the WorldWindow's background worker thread might start sending back updates before the // MainForm's window handle has been created. Don't let it, or you'll cascade the system into failure. if (this.IsHandleCreated) { this.BeginInvoke(new UpdateDownloadIndicatorsDelegate(UpdateDownloadIndicators), new object[] { bDownloading, iPos, iTotal, currentList }); } }