public static DownloadFileStatus ToDownloadFileStatus(this BackgroundTransferStatus status) { switch (status) { case BackgroundTransferStatus.Running: return(DownloadFileStatus.RUNNING); case BackgroundTransferStatus.PausedByApplication: return(DownloadFileStatus.PAUSED); case BackgroundTransferStatus.PausedCostedNetwork: return(DownloadFileStatus.PAUSED); case BackgroundTransferStatus.PausedNoNetwork: return(DownloadFileStatus.PAUSED); case BackgroundTransferStatus.Error: return(DownloadFileStatus.FAILED); case BackgroundTransferStatus.Completed: return(DownloadFileStatus.COMPLETED); case BackgroundTransferStatus.Canceled: return(DownloadFileStatus.CANCELED); case BackgroundTransferStatus.Idle: case BackgroundTransferStatus.PausedSystemPolicy: return(DownloadFileStatus.PAUSED); } return(DownloadFileStatus.INITIALIZED); }
public static bool IsTerminated(this BackgroundTransferStatus source) { return(source == BackgroundTransferStatus.Idle || source == BackgroundTransferStatus.Completed || source == BackgroundTransferStatus.Canceled || source == BackgroundTransferStatus.Error); }
public void SetStatus(BackgroundTransferStatus status) { _status = status; RaisePropertyChanged(); RaisePropertyChanged(nameof(StatusString)); RaisePropertyChanged(nameof(CanPauseDownload)); RaisePropertyChanged(nameof(CanResumeDownload)); }
public static bool IsPaused(this BackgroundTransferStatus source, bool byApplicationOnly = false) { return(byApplicationOnly ? source == BackgroundTransferStatus.PausedByApplication : source == BackgroundTransferStatus.PausedByApplication || source == BackgroundTransferStatus.PausedCostedNetwork || source == BackgroundTransferStatus.PausedNoNetwork || source == BackgroundTransferStatus.PausedRecoverableWebErrorStatus || source == BackgroundTransferStatus.PausedSystemPolicy); }
public async void StartDownload(DownModel downModel) { try { BackgroundDownloader downloader = new BackgroundDownloader(); downloader.TransferGroup = DownModel.group; if (setting.SettingContains("UseWifi")) { if ((bool)setting.GetSettingValue("UseWifi")) { downloader.CostPolicy = BackgroundTransferCostPolicy.Always; } else { downloader.CostPolicy = BackgroundTransferCostPolicy.UnrestrictedOnly; } } else { downloader.CostPolicy = BackgroundTransferCostPolicy.UnrestrictedOnly; setting.SetSettingValue("UseWifi", false); } StorageFolder DowFolder = await KnownFolders.VideosLibrary.CreateFolderAsync("Bili-Down", CreationCollisionOption.OpenIfExists); StorageFolder VideoFolder = await DowFolder.CreateFolderAsync(ReplaceSymbol(downModel.title), CreationCollisionOption.OpenIfExists); StorageFolder PartFolder = await VideoFolder.CreateFolderAsync(downModel.part, CreationCollisionOption.OpenIfExists); StorageFile file = await PartFolder.CreateFileAsync(downModel.mid + ".mp4", CreationCollisionOption.OpenIfExists); DownloadOperation downloadOp = downloader.CreateDownload(new Uri(downModel.url), file); downloadOp.CostPolicy = BackgroundTransferCostPolicy.UnrestrictedOnly; BackgroundTransferStatus downloadStatus = downloadOp.Progress.Status; downModel.Guid = downloadOp.Guid.ToString(); downModel.path = downloadOp.ResultFile.Path; string jsonInfo = JsonConvert.SerializeObject(downModel); StorageFile fileWrite = await PartFolder.CreateFileAsync(downModel.Guid + ".json", CreationCollisionOption.OpenIfExists); await FileIO.WriteTextAsync(fileWrite, jsonInfo); StorageFile fileWrite2 = await DowFolder.CreateFileAsync(downModel.Guid + ".bili", CreationCollisionOption.OpenIfExists); await FileIO.WriteTextAsync(fileWrite2, WebUtility.UrlEncode(PartFolder.Path)); DownDanMu(downModel.mid, PartFolder); downloadOp.StartAsync(); } catch (Exception ex) { //WebErrorStatus error = BackgroundTransferError.GetStatus(ex.HResult); MessageDialog md = new MessageDialog(ex.Message); await md.ShowAsync(); } }
public static bool IsPaused(this BackgroundTransferStatus status) { switch (status) { case BackgroundTransferStatus.PausedByApplication: case BackgroundTransferStatus.Error: return(true); default: return(false); } }
private DownloadStatus CreateDownloadStatus(BackgroundTransferStatus uwpStatus) { return(uwpStatus switch { BackgroundTransferStatus.Canceled => DownloadStatus.Failed, BackgroundTransferStatus.Completed => DownloadStatus.Successful, BackgroundTransferStatus.Error => DownloadStatus.Failed, BackgroundTransferStatus.Idle => DownloadStatus.Paused, BackgroundTransferStatus.PausedByApplication => DownloadStatus.Paused, BackgroundTransferStatus.PausedCostedNetwork => DownloadStatus.Paused, BackgroundTransferStatus.PausedNoNetwork => DownloadStatus.Paused, BackgroundTransferStatus.PausedRecoverableWebErrorStatus => DownloadStatus.Paused, BackgroundTransferStatus.PausedSystemPolicy => DownloadStatus.Paused, BackgroundTransferStatus.Running => DownloadStatus.Running, _ => throw new ArgumentException($"Got unexpected BackgroundTransferStatus: {uwpStatus}") });
private void UpdateInstallationStep(BackgroundTransferStatus status) { switch (status) { case BackgroundTransferStatus.PausedByApplication: case BackgroundTransferStatus.PausedSystemPolicy: case BackgroundTransferStatus.Idle: InstallationStep = Resources.waiting; IsDownloading = true; IsIndeterminate = true; break; case BackgroundTransferStatus.PausedNoNetwork: case BackgroundTransferStatus.PausedCostedNetwork: InstallationStep = Resources.waiting_for_wifi; IsDownloading = true; IsIndeterminate = true; break; case BackgroundTransferStatus.Running: InstallationStep = Description ?? Resources.loading_message; IsDownloading = true; IsIndeterminate = false; break; case BackgroundTransferStatus.Completed: InstallationStep = null; IsDownloading = false; IsIndeterminate = false; if (DownloadComplete != null) { DownloadComplete(this, null); } break; case BackgroundTransferStatus.Error: case BackgroundTransferStatus.Canceled: InstallationStep = null; IsDownloading = false; IsIndeterminate = false; if (DownloadCancelled != null) { DownloadCancelled(this, null); } break; } }
private void DownloadProgress(DownloadOperationItem item) { BackgroundDownloadProgress currentProgress = item.download.Progress; BackgroundTransferStatus status = currentProgress.Status; int percentComplete = 0; if (currentProgress.TotalBytesToReceive > 0) { percentComplete = (int)((currentProgress.BytesReceived * 100) / currentProgress.TotalBytesToReceive); } var ignore = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { item.stateText = status.ToString(); item.percentComplete = percentComplete; }); }
private string GetMessageTextFromStatus(BackgroundTransferStatus status) { switch (status) { case BackgroundTransferStatus.Idle: return(_locService["Message_Transfer_Idle_Text"]); case BackgroundTransferStatus.PausedCostedNetwork: return(_locService["Message_Transfer_PausedCostedNetwork_Text"]); case BackgroundTransferStatus.PausedNoNetwork: return(_locService["Message_Transfer_PausedNoNetwork_Text"]); case BackgroundTransferStatus.Error: return(_locService["Message_Transfer_Error_Text"]); } return(String.Empty); }
private bool IsFailed(DownloadOperation download) { BackgroundTransferStatus status = download.Progress.Status; if (status == BackgroundTransferStatus.Error || status == BackgroundTransferStatus.Canceled) { return(true); } ResponseInformation response = download.GetResponseInformation(); if (response == null || response.StatusCode != 200) { return(true); } return(false); }
private bool IsPasused(BackgroundTransferStatus status) { switch (status) { case BackgroundTransferStatus.PausedSystemPolicy: case BackgroundTransferStatus.PausedByApplication: case BackgroundTransferStatus.PausedCostedNetwork: case BackgroundTransferStatus.PausedNoNetwork: return(true); case BackgroundTransferStatus.Running: case BackgroundTransferStatus.Completed: case BackgroundTransferStatus.Canceled: case BackgroundTransferStatus.Error: default: return(false); } }
public static HttpTransferState FromNative(this BackgroundTransferStatus status) { switch (status) { case BackgroundTransferStatus.Canceled: return(HttpTransferState.Canceled); case BackgroundTransferStatus.Completed: return(HttpTransferState.Completed); case BackgroundTransferStatus.Error: return(HttpTransferState.Error); case BackgroundTransferStatus.Idle: return(HttpTransferState.Pending); case BackgroundTransferStatus.PausedByApplication: return(HttpTransferState.Paused); case BackgroundTransferStatus.PausedSystemPolicy: case BackgroundTransferStatus.PausedCostedNetwork: return(HttpTransferState.PausedByCostedNetwork); case BackgroundTransferStatus.PausedNoNetwork: return(HttpTransferState.PausedByNoNetwork); case BackgroundTransferStatus.PausedRecoverableWebErrorStatus: return(HttpTransferState.Retrying); case BackgroundTransferStatus.Running: return(HttpTransferState.InProgress); default: return(HttpTransferState.Unknown); } }
protected virtual void SetData(BackgroundTransferStatus status, ulong bytesXfer, ulong totalBytesToXfer, bool hasRestarted) { switch (status) { case BackgroundTransferStatus.PausedSystemPolicy: this.Status = TaskStatus.Paused; break; case BackgroundTransferStatus.PausedCostedNetwork: this.Status = TaskStatus.PausedByNoNetwork; break; case BackgroundTransferStatus.PausedByApplication: this.Status = TaskStatus.Paused; break; case BackgroundTransferStatus.Error: // TODO: get exception break; case BackgroundTransferStatus.Canceled: this.Status = TaskStatus.Cancelled; break; case BackgroundTransferStatus.Completed: this.Status = TaskStatus.Completed; break; case BackgroundTransferStatus.Running: this.Status = TaskStatus.Running; break; } this.BytesTransferred = (long)bytesXfer; this.FileSize = (long)totalBytesToXfer; this.RunCalculations(); }
public string StatusToString(BackgroundTransferStatus s) { return(s.GetDisplayName()); }
public static async void StartDownload(DownloadModel m, int index) { try { if (folderList == null) { await GetfolderList(); } BackgroundDownloader downloader = new BackgroundDownloader(); downloader.SetRequestHeader("Referer", "https://www.bilibili.com/blackboard/html5player.html?crossDomain=true"); downloader.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"); //设置下载模式 if (SettingHelper.Get_DownMode() == 0) { group.TransferBehavior = BackgroundTransferBehavior.Serialized; } else { group.TransferBehavior = BackgroundTransferBehavior.Parallel; } downloader.TransferGroup = group; //设置视频文件夹 StorageFolder videoFolder = null; var f = folderList.Find(x => x.id == m.folderinfo.id); if (f == null) { videoFolder = await DownFolder.CreateFolderAsync(m.folderinfo.id, CreationCollisionOption.OpenIfExists); m.folderinfo.folderPath = videoFolder.Path; m.folderinfo.thumb = await DownThumb(m.folderinfo.thumb, m.folderinfo.id, videoFolder); folderList.Add(m.folderinfo); } else { try { videoFolder = await StorageFolder.GetFolderFromPathAsync(f.folderPath); } catch (Exception ex) { MessageDialog md = new MessageDialog("Get videoFolder Error!\r\n" + ex.Message); } } //读取part文件夹 StorageFolder PartFolder = null; var partf = await videoFolder.CreateFolderAsync(m.videoinfo.mid, CreationCollisionOption.OpenIfExists); if (partf == null) { PartFolder = await videoFolder.CreateFolderAsync(m.videoinfo.mid, CreationCollisionOption.OpenIfExists); } else { PartFolder = partf; } //创建相关文件 //创建配置文件 //创建视频文件 StorageFile file = await PartFolder.CreateFileAsync(m.videoinfo.mid + "-" + index + ".flv", CreationCollisionOption.OpenIfExists); //下载弹幕文件 await DownDanMu(m.videoinfo.mid, PartFolder); DownloadOperation downloadOp = downloader.CreateDownload(new Uri(m.videoinfo.videoUrl), file); //设置下载策略 if (SettingHelper.Get_Use4GDown()) { downloadOp.CostPolicy = BackgroundTransferCostPolicy.Always; } else { downloadOp.CostPolicy = BackgroundTransferCostPolicy.UnrestrictedOnly; } BackgroundTransferStatus downloadStatus = downloadOp.Progress.Status; m.videoinfo.downGUID = downloadOp.Guid.ToString(); m.videoinfo.videoPath = downloadOp.ResultFile.Path; m.videoinfo.folderPath = PartFolder.Path; m.videoinfo.downstatus = false; StorageFile sefile = await PartFolder.CreateFileAsync(m.videoinfo.mid + ".json", CreationCollisionOption.OpenIfExists); await FileIO.WriteTextAsync(sefile, JsonConvert.SerializeObject(m.videoinfo)); await SetGUIDFile(m); downloadOp.StartAsync(); } catch (Exception ex) { MessageDialog md = new MessageDialog("StartDownload Eroor!\r\n" + ex.Message); await md.ShowAsync(); } finally { await SetfolderList(); await GetfolderList(); } }
public static async void StartDownload(DownloadModel m) { try { if (folderList == null) { await GetfolderList(); } BackgroundDownloader downloader = new BackgroundDownloader(); //设置下载模式 if (SettingHelper.Get_DownMode() == 0) { group.TransferBehavior = BackgroundTransferBehavior.Serialized; } else { group.TransferBehavior = BackgroundTransferBehavior.Parallel; } downloader.TransferGroup = group; //设置视频文件夹 StorageFolder videoFolder = null; var f = folderList.Find(x => x.id == m.folderinfo.id); if (f == null) { videoFolder = await DownFolder.CreateFolderAsync(m.folderinfo.id); m.folderinfo.folderPath = videoFolder.Path; m.folderinfo.thumb = await DownThumb(m.folderinfo.thumb, m.folderinfo.id, videoFolder); folderList.Add(m.folderinfo); } else { videoFolder = await StorageFolder.GetFolderFromPathAsync(f.folderPath); } //读取part文件夹 StorageFolder PartFolder = null; var partf = await videoFolder.CreateFolderAsync(m.videoinfo.mid, CreationCollisionOption.OpenIfExists); if (partf == null) { PartFolder = await videoFolder.CreateFolderAsync(m.videoinfo.mid, CreationCollisionOption.OpenIfExists); } else { PartFolder = partf; } //创建相关文件 //创建配置文件 //创建视频文件 StorageFile file = await PartFolder.CreateFileAsync(m.videoinfo.mid + ".mp4", CreationCollisionOption.OpenIfExists); //下载弹幕文件 await DownDanMu(m.videoinfo.mid, PartFolder); DownloadOperation downloadOp = downloader.CreateDownload(new Uri(m.videoinfo.videoUrl), file); //设置下载策略 if (SettingHelper.Get_Use4GDown()) { downloadOp.CostPolicy = BackgroundTransferCostPolicy.Always; } else { downloadOp.CostPolicy = BackgroundTransferCostPolicy.UnrestrictedOnly; } BackgroundTransferStatus downloadStatus = downloadOp.Progress.Status; m.videoinfo.downGUID = downloadOp.Guid.ToString(); m.videoinfo.videoPath = downloadOp.ResultFile.Path; m.videoinfo.folderPath = PartFolder.Path; m.videoinfo.downstatus = false; StorageFile sefile = await PartFolder.CreateFileAsync(m.videoinfo.mid + ".json", CreationCollisionOption.OpenIfExists); await FileIO.WriteTextAsync(sefile, JsonConvert.SerializeObject(m.videoinfo)); await SetGUIDFile(m); downloadOp.StartAsync(); } catch (Exception ex) { MessageDialog md = new MessageDialog(ex.Message); await md.ShowAsync(); } finally { await SetfolderList(); await GetfolderList(); } }
private void UpdateInstallationStep(BackgroundTransferStatus status) { switch (status) { case BackgroundTransferStatus.PausedByApplication: case BackgroundTransferStatus.PausedSystemPolicy: case BackgroundTransferStatus.Idle: InstallationStep = Resources.waiting; IsDownloading = true; IsIndeterminate = true; break; case BackgroundTransferStatus.PausedNoNetwork: case BackgroundTransferStatus.PausedCostedNetwork: InstallationStep = Resources.waiting_for_wifi; IsDownloading = true; IsIndeterminate = true; break; case BackgroundTransferStatus.Running: InstallationStep = Description ?? Resources.loading_message; IsDownloading = true; IsIndeterminate = false; break; case BackgroundTransferStatus.Completed: InstallationStep = null; IsDownloading = false; IsIndeterminate = false; if (DownloadComplete != null) { DownloadComplete(this, null); } break; case BackgroundTransferStatus.Error: case BackgroundTransferStatus.Canceled: InstallationStep = null; IsDownloading = false; IsIndeterminate = false; if (DownloadCancelled != null) { DownloadCancelled(this, null); } break; } }
private bool IsTerminalStatus(BackgroundTransferStatus status) { return status == BackgroundTransferStatus.Completed || status == BackgroundTransferStatus.Error || status == BackgroundTransferStatus.Canceled; }
private bool IsTerminalStatus(BackgroundTransferStatus status) { return(status == BackgroundTransferStatus.Completed || status == BackgroundTransferStatus.Error || status == BackgroundTransferStatus.Canceled); }
public static bool IsOnError(this BackgroundTransferStatus source) { return(source == BackgroundTransferStatus.Error || source == BackgroundTransferStatus.PausedRecoverableWebErrorStatus); }
private TransferStatus ToTransferStatus(BackgroundTransferStatus status) { return((TransferStatus)Enum.Parse(typeof(TransferStatus), status.ToString())); }
public static bool IsRunning(this BackgroundTransferStatus source) { return(source == BackgroundTransferStatus.Running); }
/// <summary> /// Initializes a new instance of the <see cref="BackgroundTransferInfo"/> class. /// </summary> /// <param name="status">The status of the transfer.</param> /// <param name="fileName">The full target file name.</param> /// <param name="transferred">The number of transferred bytes.</param> public BackgroundTransferInfo(BackgroundTransferStatus status, string fileName, long?transferred) { Status = status; FileName = fileName; Transferred = transferred; }