/// <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); } }; }); }
void UploadFileEvent(List <string> value) { NameValueCollection data = new NameValueCollection { { "sourceClient", "PC" }, { "audiskflag", "audiskpc" } }; Bll.AUFileDocument document = new AUFileDocument(); string temVal = document.AUDiskFilesCloud(AccountInfo.Token, value.ToArray(), data); JObject jo = (JObject)JsonConvert.DeserializeObject(temVal); if (JObjectHelper.GetStrNum(jo["code"].ToString()) == 200) { for (int i = 0; i < value.Count; i++) { XElement File = new XElement("File"); //File.SetElementValue("Id", UnDownload[Index].Id); File.SetElementValue("FileName", Path.GetFileName(value[i].ToString())); File.SetElementValue("FileUrl", value[i].ToString()); //File.SetElementValue("DownLoadPath", Path.Combine(localDownload, UnDownload[Index].FileName)); File.SetElementValue("CreateTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm")); FileOperationHelper.WriteXml(History, File); } DispatcherHelper.CheckBeginInvokeOnUI(() => { Delete(LocalTray); var trayUpload = PageTrayHistoryUploadedViewModel.GetInstance(); ThreadPool.QueueUserWorkItem(delegate { SynchronizationContext.SetSynchronizationContext( new System.Windows.Threading.DispatcherSynchronizationContext(System.Windows .Application .Current.Dispatcher)); SynchronizationContext.Current.Post(p => { trayUpload.GetLocalTrayHistoryUploaded(); }, null); }); }); } else { DispatcherHelper.CheckBeginInvokeOnUI(() => { MessageBox.Show(jo["message"].ToString()); }); } RunState = false; }