private void UpdateProgress(ForegroundTransferEventArgs e) { DateTime now = DateTime.Now; if (!this.lastUpdateProgress.HasValue || (now - this.lastUpdateProgress) > UpdateProgressPeriod) { this.lastUpdateProgress = now; Deployment.Current.Dispatcher.BeginInvoke(() => { if (this.TransferProgressChanged != null) { this.TransferProgressChanged(this, e); } }); } }
private void UpdateStatus(ForegroundTransferEventArgs e) { Deployment.Current.Dispatcher.BeginInvoke(() => { if (this.TransferStatusChanged != null) { this.TransferStatusChanged(this, e); } }); }
private void ProcessTransfer(ForegroundTransferEventArgs transfer) { if (transfer.Error != null || this.Status == DownloadList.Enum_TransferStatus_Cancelled || this.Status == DownloadList.Enum_TransferStatus_Paused) { IsolatedStorageFileHelper.DeleteFileIfExists(this.ForegroundTransferRequest.DownloadLocation); this.UpdateStatus(transfer.Status == TransferStatus.Paused ? DownloadList.Enum_TransferStatus_CancelledByQuit : DownloadList.Enum_TransferStatus_Cancelled); this.UpdateProgress(0); this.UpdateTransferRate(null); } else if (transfer.Status == TransferStatus.Completed) { this.UpdateProgress(100); this.UpdateStatus(UIHelper.GetEnumLocalized<TransferStatus, DownloadList>(TransferStatus.Completed)); var type = MediaSupportService.GetMediaType(this.ForegroundTransferRequest.Tag); string filename = Guid.NewGuid().ToString() + Path.GetExtension(this.ForegroundTransferRequest.Tag); string filepath = Path.Combine(MediaSupportService.GetStorageDirectory(), filename); if (IsolatedStorageFileHelper.MoveFile(this.ForegroundTransferRequest.DownloadLocation, filepath)) { if (type == MediaType.Audio) { App.DataCacheServiceInstance.AddAudioMedia(Path.GetFileNameWithoutExtension(this.ForegroundTransferRequest.Tag), string.Empty, string.Empty, filename, false, TaskParam.Async()); } else { App.DataCacheServiceInstance.AddVideoMedia(Path.GetFileNameWithoutExtension(this.ForegroundTransferRequest.Tag), filename, false, TaskParam.Async()); } } this.UpdateTransferRate(null); } else { this.UpdateStatus(UIHelper.GetEnumLocalized<TransferStatus, DownloadList>(TransferStatus.Transferring)); } }