public async void DownLoad() { IsDownLoading = true; //下载信息 if (DetailMovie.IsToDownLoadInfo()) { HttpResult httpResult = await MyNet.DownLoadFromNet(DetailMovie); if (httpResult != null && !httpResult.Success) { string error = httpResult.Error != "" ? httpResult.Error : httpResult.StatusCode.ToStatusMessage(); MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($" {DetailMovie.id} {Jvedio.Language.Resources.DownloadMessageFailFor}:{error}")); } } DetailMovie dm = DataBase.SelectDetailMovieById(DetailMovie.id); if (dm == null || string.IsNullOrEmpty(dm.title)) { InfoUpdate?.Invoke(this, new DetailMovieEventArgs() { DetailMovie = dm, value = 1, maximum = 1 }); return; } InfoUpdate?.Invoke(this, new DetailMovieEventArgs() { DetailMovie = dm, value = Value, maximum = Maximum }); InfoDownloadCompleted?.Invoke(this, new MessageCallBackEventArgs(DetailMovie.id)); if (!File.Exists(BasePicPath + $"BigPic\\{dm.id}.jpg")) { DownLoadBigPic(dm); //下载大图 } if (!File.Exists(BasePicPath + $"SmallPic\\{dm.id}.jpg")) { DownLoadSmallPic(dm); //下载小图 } List <string> urlList = new List <string>(); foreach (var item in dm.extraimageurl?.Split(';')) { if (!string.IsNullOrEmpty(item)) { urlList.Add(item); } } Maximum = urlList.Count() == 0 ? 1 : urlList.Count; DownLoadExtraPic(dm);//下载预览图 }
private async void DownLoad(object o) { //下载信息 Movie movie = o as Movie; if (movie.id.ToUpper().StartsWith("FC2")) { SemaphoreFC2.WaitOne(); } else { Semaphore.WaitOne();//阻塞 } if (Cancel || string.IsNullOrEmpty(movie.id)) { if (movie.id.ToUpper().StartsWith("FC2")) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } return; } //下载信息 State = DownLoadState.DownLoading; if (movie.IsToDownLoadInfo() || enforce) { //满足一定条件才下载信息 HttpResult httpResult = await MyNet.DownLoadFromNet(movie); if (httpResult != null) { if (httpResult.Success) { InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = movie, progress = downLoadProgress.value, Success = httpResult.Success }); //委托到主界面显示 } else { string error = httpResult.Error != "" ? httpResult.Error : httpResult.StatusCode.ToStatusMessage(); MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($" {movie.id} {Jvedio.Language.Resources.DownloadMessageFailFor}:{error}")); } } } DetailMovie dm = DataBase.SelectDetailMovieById(movie.id); if (dm == null) { if (movie.id.ToUpper().StartsWith("FC2")) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } return; } if (!File.Exists(BasePicPath + $"BigPic\\{dm.id}.jpg") || enforce) { await MyNet.DownLoadImage(dm.bigimageurl, ImageType.BigImage, dm.id);//下载大图 } //fc2 没有缩略图 if (dm.id.IndexOf("FC2") >= 0) { //复制海报图作为缩略图 if (File.Exists(BasePicPath + $"BigPic\\{dm.id}.jpg") && !File.Exists(BasePicPath + $"SmallPic\\{dm.id}.jpg")) { FileHelper.TryCopyFile(BasePicPath + $"BigPic\\{dm.id}.jpg", BasePicPath + $"SmallPic\\{dm.id}.jpg"); } } else { if (!File.Exists(BasePicPath + $"SmallPic\\{dm.id}.jpg") || enforce) { await MyNet.DownLoadImage(dm.smallimageurl, ImageType.SmallImage, dm.id); //下载小图 } } dm.smallimage = ImageProcess.GetBitmapImage(dm.id, "SmallPic"); InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = dm, progress = downLoadProgress.value, state = State }); //委托到主界面显示 dm.bigimage = ImageProcess.GetBitmapImage(dm.id, "BigPic"); lock (downLoadProgress.lockobject) downLoadProgress.value += 1; //完全下载完一个影片 InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = dm, progress = downLoadProgress.value, state = State, Success = true }); //委托到主界面显示 Task.Delay(Delay.MEDIUM).Wait(); //每个线程之间暂停 //取消阻塞 if (movie.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } }