/// <summary> /// 根据索引下载文件 /// </summary> /// <param name="fileUrl"></param> /// <param name="Index"></param> void DownloadFile(int Index) { DispatcherHelper.CheckBeginInvokeOnUI(() => { UnDownload[Index].DownTextShow = false; UnDownload[Index].CanDownload = false; UnDownload[Index].ProgressBarShow = true; if (!Directory.Exists(localDownload)) { Directory.CreateDirectory(localDownload); } bool IsCover = false; if (File.Exists(Path.Combine(localDownload, UnDownload[Index].FileName))) { //MessageBoxResult result = MessageBox.Show("存在相同文件名是否覆盖?", "提示", MessageBoxButton.YesNo); //IsCover = result == MessageBoxResult.OK; //if (result == MessageBoxResult.OK) File.Delete(Path.Combine(localDownload, UnDownload[Index].FileName)); //else // return; } TrayDownload _trayDownload = new TrayDownload(UnDownload[Index].FileUrl, Path.Combine(localDownload, UnDownload[Index].FileName)); _trayDownload.SetProgressBarValue += value => { UnDownload[Index].DownValue = value; if ((int)value == 100) { UnDownload[Index].ProgressBarShow = false; UnDownload[Index].OpenLocalDirectoryShow = true; UnDownload[Index].IsShow = false; XElement File = new XElement("File"); File.SetElementValue("Id", UnDownload[Index].Id); File.SetElementValue("FileName", UnDownload[Index].FileName); File.SetElementValue("FileUrl", UnDownload[Index].FileUrl); File.SetElementValue("DownLoadPath", Path.Combine(localDownload, UnDownload[Index].FileName)); File.SetElementValue("CreateTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm")); FileOperationHelper.WriteXml(History, File); var trayDownload = PageTrayHistoryDownloadedViewModel.GetInstance(); //修改下载记录表 ThreadPool.QueueUserWorkItem(delegate { SynchronizationContext.SetSynchronizationContext( new System.Windows.Threading.DispatcherSynchronizationContext(System.Windows .Application.Current.Dispatcher)); SynchronizationContext.Current.Post(p => { trayDownload.GetTrayHistoryDownload(); }, null); }); DelNoTransferAUDiskFile(UnDownload[Index].Id); } }; }); }
public static PageTrayHistoryDownloadedViewModel GetInstance() { if (PageTrayDownloaded == null) { lock (locker) { PageTrayDownloaded = new PageTrayHistoryDownloadedViewModel(); } } return(PageTrayDownloaded); }