private void Uploadfile(云数据类型Enum dicom数据压缩包) { DataListItem[] orderList = (DataListItem[])dataGridOrderList.DataContext; DataListItem selectedOrder = orderList[dataGridOrderList.SelectedIndex]; var openFileDialog = new Microsoft.Win32.OpenFileDialog(); string vrAviFilePath = new FileInfo(Path.Combine(Path.Combine(SelectedUser, selectedOrder.DataID), "vr.avi")).FullName; openFileDialog.FileName = vrAviFilePath; if (openFileDialog.ShowDialog() == true) { MESPDownloadUpload.UserId = LungCare.SupportPlatform.Security.SessionManager.UserName; MESPDownloadUpload.OrderId = selectedOrder.DataID; MESPDownloadUpload.OrderNo = selectedOrder.DataID; ThreadPool.QueueUserWorkItem(delegate { new UploadFileWorker().UploadFile( dicom数据压缩包, filename : openFileDialog.FileName, isResume : false, successCallback : delegate() { this.Dispatcher.BeginInvoke(new Action(delegate() { MessageBox.Show("SUCCESS"); })); }, failureCallback : delegate(string errMsg) { MessageBox.Show(errMsg); }, errorCallback : delegate(Exception ex) { Util.ShowExceptionMessage(ex); }, uploadProgressCallback : delegate(ProgressArgs eProgress) { this.Dispatcher.BeginInvoke(new Action(delegate() { })); } ); }); } }
private void DownloadFile(云数据类型Enum 云数据类型, DataGrid gridFileList) { DataListItem[] orderList = (DataListItem[])dataGridOrderList.DataContext; DataListItem selectedOrder = orderList[dataGridOrderList.SelectedIndex]; MESPDownloadUpload.UserId = SelectedUser; MESPDownloadUpload.OrderId = MESPDownloadUpload.OrderNo = selectedOrder.DataID; ThreadPool.QueueUserWorkItem(delegate { new MESPDownloadUpload().FetchFileListAsync( 云数据类型, new EventHandler <ExceptionArgs>( delegate(Object senderInner, ExceptionArgs eInner) { MessageBox.Show(eInner.Exception.Message); }), new EventHandler <FileListFinishedArgs>(delegate(Object senderInner, FileListFinishedArgs eInner) { Dispatcher.BeginInvoke(new Action(delegate() { gridFileList.DataContext = eInner.Result; gridFileList.SetBinding(System.Windows.Controls.ListView.ItemsSourceProperty, new System.Windows.Data.Binding()); })); })); }); }
public static void Download( FileListItem fli, string localDstFullName, Action <string> successCallback, Action <string> failureCallback, Action <Exception> errorCallback, Action <ProgressArgs> uploadProgressCallback, 云数据类型Enum 云数据类型Enum) { Console.WriteLine("Downloading to " + localDstFullName); new MESPDownloadUpload().DownloadFileAsync( 云数据类型Enum, fli.FileName, (int)fli.FileSize, localDstFullName, new EventHandler <ExceptionArgs>(delegate(Object senderInner, ExceptionArgs eInner) { errorCallback(eInner.Exception); }), new EventHandler <FileDownloadFinishedArgs>(delegate(Object senderInnerDownload, FileDownloadFinishedArgs eInnerDownload) { successCallback(fli.FileName); }), new EventHandler <ProgressArgs>(delegate(Object senderInnerDownload, ProgressArgs eInnerDownload) { uploadProgressCallback(eInnerDownload); }) ); }
public CCUpDownFile(DataListItem dataItem, 云数据类型Enum 云数据类型Enum) { this.InitializeComponent(); this._dataItem = dataItem; this._云数据类型Enum = 云数据类型Enum; GetFile(_dataItem); }
public void DownloadFileAsync( 云数据类型Enum 云数据类型, string filename, int filesize, string localDstFullName, EventHandler <ExceptionArgs> onExceptionOccurred, EventHandler <FileDownloadFinishedArgs> onFinished, EventHandler <ProgressArgs> onProgress) { DownloadFileAsync(云数据类型, filename: filename, filesize: filesize, localDstFullName: localDstFullName, userId: UserId, orderId: OrderId, orderNo: OrderNo, onExceptionOccurred: onExceptionOccurred, onFinished: onFinished, onProgress: onProgress); }
private void DownloadFile(DataGrid gridFileList, 云数据类型Enum 云数据类型Enum) { DataListItem[] orderList = (DataListItem[])dataGridOrderList.DataContext; DataListItem selectedOrder = orderList[dataGridOrderList.SelectedIndex]; List <FileListItem> fileList = (List <FileListItem>)gridFileList.DataContext; FileListItem selectedFile = fileList[gridFileList.SelectedIndex]; MESPDownloadUpload.OrderId = MESPDownloadUpload.OrderNo = selectedOrder.DataID; string selectedDicomPackageLocalPath = new FileInfo(Path.Combine(Path.Combine(SelectedUser, selectedOrder.DataID), selectedOrder.PatientName + "-" + selectedOrder.PatientAge + "-" + selectedOrder.PatientSex + "-" + selectedOrder.InstitutionName + "-" + selectedOrder.AcquisitionDate + "-" + selectedFile.FileName)).FullName; ThreadPool.QueueUserWorkItem(delegate { Download(selectedFile, selectedDicomPackageLocalPath, 云数据类型Enum); }); }
private void Uploadfile(云数据类型Enum dicom数据压缩包) { var openFileDialog = new Microsoft.Win32.OpenFileDialog(); string vrAviFilePath = new FileInfo(Path.Combine(Path.Combine(_UserID, _selectedOrder.DataID), "vr.avi")).FullName; openFileDialog.FileName = vrAviFilePath; if (openFileDialog.ShowDialog() == true) { PauseGUI(); MESPDownloadUpload.UserId = LungCare.SupportPlatform.Security.SessionManager.UserName; MESPDownloadUpload.OrderId = _selectedOrder.DataID; MESPDownloadUpload.OrderNo = _selectedOrder.DataID; ThreadPool.QueueUserWorkItem(delegate { new UploadFileWorker().UploadFile( dicom数据压缩包, filename : openFileDialog.FileName, isResume : false, successCallback : delegate() { this.Dispatcher.BeginInvoke(new Action(delegate() { //ListBoxItem item = new ListBoxItem(); //item.Content = openFileDialog.SafeFileName; //listboxUserFiles.Items.Add(item); listboxUserFiles.Items.Clear(); GetUserFiles(); ResumeGUI(); MessageBox.Show("SUCCESS"); })); }, failureCallback : delegate(string errMsg) { MessageBox.Show(errMsg); ResumeGUI(); }, errorCallback : delegate(Exception ex) { Util.ShowExceptionMessage(ex); ResumeGUI(); }, uploadProgressCallback : delegate(ProgressArgs eProgress) { this.Dispatcher.BeginInvoke(new Action(delegate() { })); } ); }); } }
public void UploadFile( 云数据类型Enum 云数据类型, string filename, bool isResume, Action successCallback, Action <string> failureCallback, Action <Exception> errorCallback, Action <ProgressArgs> uploadProgressCallback) { MESPDownloadUpload.UploadFileAsync( 云数据类型, filename, SessionManager.UserName, MESPDownloadUpload.OrderId, MESPDownloadUpload.OrderNo, isResume, new EventHandler <ExceptionArgs>(delegate(Object senderUploadFile, ExceptionArgs eUploadFile) { //CancelOrderWorker.SendCancelOrderRequeset( // MESPDownloadUpload.OrderId, // successCallback: delegate (Models.CancelOrderResponse response) // { // }, // failureCallback: delegate (string cancelOrderFailureReason) // { // }, // errorCallback: delegate (Exception ex) // { // }); errorCallback(eUploadFile.Exception); }), new EventHandler <FileUploadFinishedArgs>(delegate(Object senderUploadFile, FileUploadFinishedArgs eUploadFile) { successCallback(); }), new EventHandler <ProgressArgs>(delegate(Object senderProgress, ProgressArgs eProgress) { uploadProgressCallback(eProgress); }) ); }
private void Download(FileListItem selectedFile, string selectedDicomPackageLocalPath, 云数据类型Enum 云数据类型Enum) { DownloadFileWorker.Download( selectedFile, selectedDicomPackageLocalPath, delegate(string filename) { UIUtil.Invoke(this, delegate { try { string tempPath = selectedDicomPackageLocalPath.Substring(0, selectedDicomPackageLocalPath.LastIndexOf(Path.DirectorySeparatorChar)); System.Diagnostics.Process.Start(tempPath); ResumeGUI(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }); }, delegate(string errMsg) { UIUtil.Invoke(this, delegate { MessageBox.Show(errMsg); ResumeGUI(); }); }, delegate(Exception ex) { UIUtil.Invoke(this, delegate { Util.ShowExceptionMessage(ex); //Download(selectedFile, selectedDicomPackageLocalPath, 云数据类型Enum.处理结果); ResumeGUI(); }); }, delegate(ProgressArgs progressArgs) { UIUtil.Invoke(this, delegate { Console.WriteLine(progressArgs); }); }, 云数据类型Enum); }
public void DownloadFileAsync( 云数据类型Enum 云数据类型, string filename, int filesize, string localDstFullName, string userId, string orderId, string orderNo, EventHandler <ExceptionArgs> onExceptionOccurred, EventHandler <FileDownloadFinishedArgs> onFinished, EventHandler <ProgressArgs> onProgress) { FileStream fs = null; var urlPath = 云数据类型 == 云数据类型Enum.Dicom数据压缩包 ? "/lungcare/DealFileUpDown" : "/lungcare/FileUpDown"; var ws = new WebSocket(ServerUrl + urlPath); DateTime startUploadDateTime = DateTime.Now; try { Console.ResetColor(); string filename2Download = filename; _cancelDownload = false; int beginPos = 1; Stopwatch sw = Stopwatch.StartNew(); bool downloading = false; if (!Directory.Exists(new FileInfo(localDstFullName).Directory.FullName)) { Directory.CreateDirectory(new FileInfo(localDstFullName).Directory.FullName); } foreach (var item in _openFileStreams) { try { item.Close(); item.Dispose(); } catch (Exception) { } } _openFileStreams.Clear(); if (File.Exists(localDstFullName)) { beginPos = 1 + (int)new FileInfo(localDstFullName).Length; Console.WriteLine("Open fs for " + localDstFullName); fs = new FileStream(localDstFullName, FileMode.Append); } else { Console.WriteLine("Open fs for " + localDstFullName); fs = new FileStream(localDstFullName, FileMode.Create); } Console.WriteLine("fs Hash = " + fs.GetHashCode()); _openFileStreams.Add(fs); ws.OnOpen += delegate { Console.WriteLine("Connected: " + ws.Url); }; ws.OnError += delegate(object sender, WebSocketSharp.ErrorEventArgs e) { try { Console.WriteLine("Closing fs for " + localDstFullName + (fs == null ? "fs is null" : "fs hash = " + fs.GetHashCode())); fs.Close(); //fs = null; Console.WriteLine("Closed fs for " + localDstFullName); } catch (Exception closeFSEx) { Console.WriteLine("Close fs failed for " + closeFSEx); } //try { ws.Close(); } catch { } Console.WriteLine("ws says(OnError): " + e.Message); if (!_cancelDownload) { _cancelDownload = true; onExceptionOccurred(this, new ExceptionArgs(e.Exception)); } _cancelDownload = true; }; ws.OnMessage += delegate(object sender, MessageEventArgs e) { Console.ForegroundColor = ConsoleColor.Red; if (e.Data.Length > 1000) { Console.WriteLine("ws says(OnMessage): Length : " + e.RawData.Length); } else { Console.WriteLine("ws says(OnMessage): " + e.Data); } if (_cancelDownload) { try { Console.WriteLine("Closing fs for " + localDstFullName + (fs == null ? "fs is null" : "fs hash = " + fs.GetHashCode())); fs.Close(); Console.WriteLine("Closed fs for " + localDstFullName); } catch (Exception closeFSEx) { Console.WriteLine("Close fs failed for " + closeFSEx); } return; } if (_filedownloadEvt != null) { Console.WriteLine("_filedownloadEvt.Set();"); _filedownloadEvt.Set(); } Console.WriteLine(); if (!downloading) { // File.WriteAllBytes("示范案例1.jpg", new byte[0]); FileDownload(orderId, filename2Download, ws, beginPos, delegate(Exception ex) { try { Console.WriteLine("Closing fs for " + localDstFullName + (fs == null ? "fs is null" : "fs hash = " + fs.GetHashCode())); fs.Close(); Console.WriteLine("Closed fs for " + localDstFullName); } catch (Exception closeFSEx) { Console.WriteLine("Close fs failed for " + closeFSEx); } _cancelDownload = true; onExceptionOccurred(this, new ExceptionArgs(ex)); }); downloading = true; } else { Console.WriteLine("About to write fs for " + fs.GetHashCode()); fs.WriteBytes(e.RawData); beginPos += e.RawData.Length; if (beginPos > filesize) //if (e.RawData.Length < 20000) { fs.Close(); onFinished(this, new FileDownloadFinishedArgs()); return; } TimeSpan ellapsed = DateTime.Now - startUploadDateTime; onProgress(this, new ProgressArgs(beginPos, filesize, beginPos / ellapsed.TotalSeconds)); FileDownload(orderId, filename2Download, ws, beginPos, delegate(Exception ex) { try { Console.WriteLine("Closing fs for " + localDstFullName + (fs == null ? "fs is null" : "fs hash = " + fs.GetHashCode())); fs.Close(); Console.WriteLine("Closed fs for " + localDstFullName); } catch (Exception closeFSEx) { Console.WriteLine("Close fs failed for " + closeFSEx); } _cancelDownload = true; onExceptionOccurred(this, new ExceptionArgs(ex)); }); // File.WriteAllBytes("Java WebSocket API_1.0_Final.pdf", e.RawData); // Process.Start("Java WebSocket API_1.0_Final.pdf"); } // Console.WriteLine("beginPos = " + beginPos); // long ellm = sw.ElapsedMilliseconds / 1000; // if (ellm != 0 && beginPos != 0) // { // Console.WriteLine("Percentage: " + (beginPos / (float)filesize).ToString("P1")); // Console.WriteLine("Remains: " + ((filesize - beginPos) / (beginPos / ellm)) + "s"); // Console.WriteLine("Speed: " + ((beginPos / 1024) / ellm) + "KB/s"); // } }; ws.Connect(); Console.ForegroundColor = ConsoleColor.Yellow; //string msg = "G##orderid1##orderno1##user1"; string msg = "G##" + orderId + "##" + orderNo + "##" + userId; Console.WriteLine("Sending(Text): " + msg); ws.Send(msg); } catch (Exception ex) { try { Console.WriteLine("Closing fs for " + localDstFullName + (fs == null ? " fs is null" : " fs hash = " + fs.GetHashCode())); fs.Close(); Console.WriteLine("Closed fs for " + localDstFullName); } catch (Exception closeFSEx) { Console.WriteLine("Close fs failed for " + closeFSEx); } try { ws.Close(); } catch { } _cancelDownload = true; onExceptionOccurred(this, new ExceptionArgs(ex)); } }
public void FetchFileListAsync(云数据类型Enum 云数据类型, EventHandler <ExceptionArgs> onExceptionOccurred, EventHandler <FileListFinishedArgs> onFinished) { FetchFileListAsync(云数据类型, UserId, OrderId, OrderNo, onExceptionOccurred, onFinished); }
private void DownloadAirwayResultFileWithoutOpen(FileListItem selectedFileItem, string selectedAirwayPackageLocalPath, 云数据类型Enum 云数据类型Enum) { DownloadFileWorker.Download( selectedFileItem, selectedAirwayPackageLocalPath, delegate(string filename) { UIUtil.Invoke(this, delegate { try { while (!File.Exists(selectedAirwayPackageLocalPath)) { } //Thread.Sleep(1000); Process.Start(System.IO.Path.GetDirectoryName(selectedAirwayPackageLocalPath)); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }); }, delegate(string errMsg) { UIUtil.Invoke(this, delegate { MessageBox.Show(errMsg); }); }, delegate(Exception ex) { UIUtil.Invoke(this, delegate { Util.ShowExceptionMessage(ex); //Download(selectedFile, selectedDicomPackageLocalPath, 云数据类型Enum.处理结果); }); }, delegate(ProgressArgs progressArgs) { UIUtil.Invoke(this, delegate { Console.WriteLine(progressArgs.Percentage.Value); Progress.Value = progressArgs.Percentage.Value; tbPercent.Text = ((progressArgs.Percentage.Value * 100).ToString("F2")).ToString() + " %"; Console.WriteLine(progressArgs); }); }, 云数据类型Enum); }
private void DownloadResultFile(FileListItem selectedFileItem, string selectedDicomPackageLocalPath, 云数据类型Enum 云数据类型Enum) { DownloadFileWorker.Download( selectedFileItem, selectedDicomPackageLocalPath, delegate(string filename) { UIUtil.Invoke(this, delegate { try { lbWaiting.Visibility = Visibility.Hidden; ResumeGUI(); while (!File.Exists(selectedDicomPackageLocalPath)) { } //Thread.Sleep(1000); openPatientsMsgWindow(selectedDicomPackageLocalPath); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }); }, delegate(string errMsg) { UIUtil.Invoke(this, delegate { MessageBox.Show(errMsg); ResumeGUI(); }); }, delegate(Exception ex) { UIUtil.Invoke(this, delegate { Util.ShowExceptionMessage(ex); //Download(selectedFile, selectedDicomPackageLocalPath, 云数据类型Enum.处理结果); ResumeGUI(); }); }, delegate(ProgressArgs progressArgs) { UIUtil.Invoke(this, delegate { lbWaiting.Content = "正在下载,请稍候。" + progressArgs.ToString(); lbDownloadProgress.Content = progressArgs.ToString(); Console.WriteLine(progressArgs); }); }, 云数据类型Enum); }
private void Download(FileListItem selectedFile, string selectedDicomPackageLocalPath, 云数据类型Enum 云数据类型Enum) { DownloadFileWorker.Download( selectedFile, selectedDicomPackageLocalPath, delegate(string filename) { UIUtil.Invoke(this, delegate { System.Diagnostics.Process.Start(selectedDicomPackageLocalPath); }); }, delegate(string errMsg) { UIUtil.Invoke(this, delegate { MessageBox.Show(errMsg); }); }, delegate(Exception ex) { UIUtil.Invoke(this, delegate { //Util.ShowExceptionMessage(ex); Download(selectedFile, selectedDicomPackageLocalPath, 云数据类型Enum.处理结果); }); }, delegate(ProgressArgs progressArgs) { UIUtil.Invoke(this, delegate { Console.WriteLine(progressArgs); }); }, 云数据类型Enum); }
public static void DownloadFile( 云数据类型Enum 云数据类型, string orderId, Action <string> successCallback, Action <string> failureCallback, Action <Exception> errorCallback, Action <ProgressArgs> uploadProgressCallback) { new MESPDownloadUpload().FetchFileListAsync( 云数据类型, SessionManager.UserName, orderId, orderId, new EventHandler <ExceptionArgs>(delegate(Object senderInner, ExceptionArgs eInner) { errorCallback(eInner.Exception); }), new EventHandler <FileListFinishedArgs>(delegate(Object senderInner, FileListFinishedArgs eInner) { //UIUtil.Invoke(this, delegate //{ FileListItem fli = eInner.Result.FirstOrDefault(item => item.FileName.ToLower().EndsWith(".avi") || item.FileName.ToLower().EndsWith(".m4v")); string orderDataFolder = new DirectoryInfo(Path.Combine(Security.SessionManager.UserName, orderId)).FullName; Console.WriteLine("orderDataFolder = " + orderDataFolder); if (!Directory.Exists(orderDataFolder)) { Console.WriteLine("Creating orderDataFolder = " + orderDataFolder); Directory.CreateDirectory(orderDataFolder); } string tmpVrFileName = Path.Combine(orderDataFolder, fli.FileName + ".tmp"); string vrFileName = Path.Combine(orderDataFolder, fli.FileName); if (fli != null) { if (File.Exists(vrFileName) && new FileInfo(vrFileName).Length == fli.FileSize) { successCallback(vrFileName); } else { Download(fli, tmpVrFileName, delegate { if (File.Exists((vrFileName))) { File.Delete(vrFileName); } File.Move(tmpVrFileName, vrFileName); successCallback(vrFileName); }, failureCallback, errorCallback, uploadProgressCallback, 云数据类型); } } else { failureCallback("没有找到视频规划结果"); } // if (fli == null) // { // MessageBox.Show("No video found."); // } //}); } )); }
public void UploadFileAsync( 云数据类型Enum 云数据类型, string filename, string userId, string orderId, string orderNo, bool isResume, EventHandler <ExceptionArgs> onExceptionOccurred, EventHandler <FileUploadFinishedArgs> onFinished, EventHandler <ProgressArgs> onProgress) { if (_cancelUploadManually) { throw new Exception("本次上传操作已被永久取消。请启动新的上传。"); } if (onExceptionOccurred == null) { throw new ArgumentNullException("onExceptionOccurred"); } if (onFinished == null) { throw new ArgumentNullException("onFinished"); } if (onProgress == null) { throw new ArgumentNullException("onProgress"); } var urlPath = 云数据类型 == 云数据类型Enum.处理结果 ? "/lungcare/DealFileUpDown" : "/lungcare/FileUpDown"; wsUpload = new WebSocket(url: ServerUrl + urlPath); try { _cancelUpload = false; _cancelUploadManually = false; DateTime startUploadDateTime = DateTime.Now; //const int sizePerBlock = 1024 * 100; const int sizePerBlock = 1024 * 30; //const int sizePerBlock = 2; if (byteUploadContent == null) { byteUploadContent = new List <byte>(File.ReadAllBytes(filename)); } int totalLength = byteUploadContent.Count; int totalBlocks = (int)Math.Ceiling((float)totalLength / sizePerBlock); int byteSent = 0; int indexLengthIdx = 0; IndexLength[] IndexLengthList = new IndexLength[totalBlocks]; for (int i = 0; i < totalBlocks; ++i) { IndexLength item = new IndexLength(); item = new IndexLength(); item.Index = i * sizePerBlock; item.Length = sizePerBlock; if (item.Index + item.Length > totalLength) { item.Length = totalLength - item.Index; } IndexLengthList[i] = item; } UploadFileStatus status = UploadFileStatus.NotStartYet; wsUpload.OnOpen += delegate { Console.WriteLine("Connected: " + wsUpload.Url); }; wsUpload.OnError += delegate(object sender, WebSocketSharp.ErrorEventArgs e) { Console.WriteLine("ws says(OnError): " + e.Message); if (!waitingResponse) { CancelTaskResumable(ex: e.Exception, onExceptionOccurred: onExceptionOccurred, reason: "WebSocket出错。没有等待返回消息。"); } }; wsUpload.OnMessage += delegate(object sender, MessageEventArgs e) { waitingResponse = false; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(Now + " ws says(OnMessage): " + e.Data); while (true) { bool shouldLoop = false; if (_cancelUpload) { ReleaseUploadResource(wsUpload, "原因未知"); return; } if (status == UploadFileStatus.申请开始上传文件RequestSent) { if (_fileuploadEvt != null) { Console.WriteLine("_fileuploadEvt.Set();"); _fileuploadEvt.Set(); } status = UploadFileStatus.申请开始上传文件ResponseReceived; if (!isResume) { string expected0Response = "0##" + byteSent; if (e.Data != expected0Response) { Exception inconsistentDataEx = new Exception(string.Format("Expected response: {0}. Actually: {1}", expected0Response, e.Data)); CancelTaskResumable(ex: inconsistentDataEx, onExceptionOccurred: onExceptionOccurred, reason: "数据跟服务器端不一致"); return; } } else { byteSent = int.Parse(e.Data.Split(new string[] { "##" }, StringSplitOptions.RemoveEmptyEntries)[1]); if (byteSent != 0) { int tmpByteSent = 0; for (int i = 0; i < IndexLengthList.Length; ++i) { tmpByteSent += IndexLengthList[indexLengthIdx].Length; if (tmpByteSent == byteSent) { indexLengthIdx = i + 1; break; } } } else { indexLengthIdx = 0; } } if (indexLengthIdx == IndexLengthList.Length) { // 已经传完了。传完最后一piece后没有收到服务器响应。 status = UploadFileStatus.输数据ResponseReceived; SendText(wsUpload, "2"); waitingResponse = true; return; } else { status = UploadFileStatus.准备开始上传数据; } } if (status == UploadFileStatus.准备开始上传数据 || status == UploadFileStatus.输数据ResponseReceived) { byte[] piece = byteUploadContent.GetRange( IndexLengthList[indexLengthIdx].Index, IndexLengthList[indexLengthIdx].Length).ToArray(); SendBytes(wsUpload, piece); waitingResponse = true; _fileuploadEvt = new ManualResetEvent(true); _fileuploadEvt.Reset(); ThreadPool.QueueUserWorkItem(delegate { Console.WriteLine("start _fileuploadEvt.WaitOne"); bool waitRet = _fileuploadEvt.WaitOne(new TimeSpan(0, 0, 0, 25)); Console.WriteLine("end _fileuploadEvt.WaitOne: " + waitRet); if (!waitRet) { Exception inconsistentDataEx = new Exception("上传文件时服务器返回超时。SendBytes"); CancelTaskResumable(ex: inconsistentDataEx, onExceptionOccurred: onExceptionOccurred, reason: "上传文件时服务器返回超时。SendBytes"); } }); byteSent += IndexLengthList[indexLengthIdx].Length; indexLengthIdx++; status = UploadFileStatus.输数据RequestSent; } else if (status == UploadFileStatus.输数据RequestSent) { if (_fileuploadEvt != null) { Console.WriteLine("_fileuploadEvt.Set();"); _fileuploadEvt.Set(); } status = UploadFileStatus.输数据ResponseReceived; string expected1Response = "1##" + IndexLengthList[indexLengthIdx - 1].Length; if (e.Data != expected1Response) { Exception inconsistentDataEx = new Exception(string.Format("Expected response: {0}. Actually: {1}", expected1Response, e.Data)); CancelTaskResumable(ex: inconsistentDataEx, onExceptionOccurred: onExceptionOccurred, reason: "数据跟服务器端不一致"); return; } TimeSpan ellapsed = DateTime.Now - startUploadDateTime; onProgress(this, new ProgressArgs(byteSent, totalLength, byteSent / ellapsed.TotalSeconds)); if (indexLengthIdx > IndexLengthList.Length - 1) { status = UploadFileStatus.文件结束RequestSent; SendText(wsUpload, "2"); waitingResponse = true; return; } else { shouldLoop = true; //SendText(ws, "0##" + new FileInfo(filename).Name + "##" + byteContent.Count + "##" + orderId + "##0##" + userId + "##" + orderNo); status = UploadFileStatus.准备开始上传数据; } } else if (status == UploadFileStatus.文件结束RequestSent) { status = UploadFileStatus.文件结束ResponseReceived; string expected2Response = "2##" + totalLength; if (e.Data != expected2Response) { Exception inconsistentDataEx = new Exception(string.Format("Expected response: {0}. Actually: {1}", expected2Response, e.Data)); CancelTaskResumable(ex: inconsistentDataEx, onExceptionOccurred: onExceptionOccurred, reason: "数据跟服务器端不一致"); return; } wsUpload.Close(); onProgress(this, new ProgressArgs(totalLength, totalLength, null)); onFinished(this, new FileUploadFinishedArgs(filename)); } if (!shouldLoop) { break; } } }; wsUpload.Connect(); status = UploadFileStatus.NotStartYet; // 是否重传文件 // 1--删除服务器上已存在的文件,重新传输。 // 0--保留服务器上的文件 string msg = "0##" + new FileInfo(filename).Name + "##" + byteUploadContent.Count + "##" + orderId + "##" + (isResume ? 0 : 1) + "##" + userId + "##" + orderNo; SendText(wsUpload, msg); _fileuploadEvt = new ManualResetEvent(true); _fileuploadEvt.Reset(); ThreadPool.QueueUserWorkItem(delegate { Console.WriteLine("start _fileuploadEvt.WaitOne"); bool waitRet = _fileuploadEvt.WaitOne(new TimeSpan(0, 0, 0, 5)); Console.WriteLine("end _fileuploadEvt.WaitOne: " + waitRet); if (!waitRet) { Exception inconsistentDataEx = new Exception("上传文件时服务器返回超时。Sent:" + msg); CancelTaskResumable(ex: inconsistentDataEx, onExceptionOccurred: onExceptionOccurred, reason: "上传文件时服务器返回超时。Sent:" + msg); } }); waitingResponse = true; status = UploadFileStatus.申请开始上传文件RequestSent; } catch (Exception ex) { CancelTaskResumable(ex: ex, onExceptionOccurred: onExceptionOccurred, reason: "主线程异常。"); } }
public void FetchFileListAsync( 云数据类型Enum 云数据类型, string userId, string orderId, string orderNo, EventHandler <ExceptionArgs> onExceptionOccurred, EventHandler <FileListFinishedArgs> onFinished) { if (onExceptionOccurred == null) { throw new ArgumentNullException("onExceptionOccurred"); } if (onFinished == null) { throw new ArgumentNullException("onFinished"); } Console.ResetColor(); try { var urlPath = 云数据类型 == 云数据类型Enum.Dicom数据压缩包 ? "/lungcare/DealFileUpDown" : "/lungcare/FileUpDown"; var ws = new WebSocket(ServerUrl + urlPath); ws.OnOpen += delegate { Console.WriteLine("Connected: " + ws.Url); }; ws.OnError += delegate(object sender, WebSocketSharp.ErrorEventArgs e) { Console.WriteLine("ws says(OnError): " + e.Message); onExceptionOccurred(this, new ExceptionArgs(e.Exception)); }; ws.OnMessage += delegate(object sender, MessageEventArgs e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ws says(OnMessage): " + e.Data); string filesStr = e.Data.Split(new string[] { "##" }, StringSplitOptions.RemoveEmptyEntries)[1]; string sizeStr = e.Data.Split(new string[] { "##" }, StringSplitOptions.RemoveEmptyEntries)[2]; string[] filesname = filesStr.Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries); string[] sizesname = sizeStr.Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries); FileListFinishedArgs flfa = new FileListFinishedArgs(); try { IEnumerable <FileListItem> items = filesname.Select( (item, index) => new FileListItem() { FileName = filesname[index], FileSize = long.Parse(sizesname[index]), OrderId = orderId, OrderNo = orderNo, UserId = userId }); flfa.Result = new List <FileListItem>(items); } catch (Exception) { //throw; } onFinished(this, flfa); }; ws.Connect(); Console.ForegroundColor = ConsoleColor.Yellow; //string msg = "G##orderid1##orderno1##user1"; string msg = "G##" + orderId + "##" + orderNo + "##" + userId; SendText(ws, msg); } catch (Exception ex) { onExceptionOccurred(this, new ExceptionArgs(ex)); } }
private void DownloadDicom(FileListItem selectedFile, DataListItem dataListItem, string selectedDicomPackageLocalPath, 云数据类型Enum 云数据类型Enum) { DownloadFileWorker.Download( selectedFile, selectedDicomPackageLocalPath, delegate(string filename) { UIUtil.Invoke(this, delegate { try { //string tempPath = selectedDicomPackageLocalPath.Substring(0, selectedDicomPackageLocalPath.LastIndexOf(Path.DirectorySeparatorChar)); //System.Diagnostics.Process.Start(tempPath); //ResumeGUI(); lbWaiting.Visibility = Visibility.Hidden; ResumeGUI(); while (!File.Exists(selectedDicomPackageLocalPath)) { } //System.Diagnostics.Process.Start(System.IO.Path.GetDirectoryName(selectedDicomPackageLocalPath)); string destFolder = AirwayPatients.BaseDicomFolder + "\\" + dataListItem.PatientName + "_" + dataListItem.StudyInstanceUID; //解压缩并用dicomviewer打开 FileDAO.upZip(selectedDicomPackageLocalPath, destFolder); ImportDicomWindow3 dicomViewer = new ImportDicomWindow3(destFolder); dicomViewer.ShowDialog(); //Thread.Sleep(1000); //openPatientsMsgWindow(selectedDicomPackageLocalPath); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }); }, delegate(string errMsg) { UIUtil.Invoke(this, delegate { MessageBox.Show(errMsg); ResumeGUI(); }); }, delegate(Exception ex) { UIUtil.Invoke(this, delegate { Util.ShowExceptionMessage(ex); //Download(selectedFile, selectedDicomPackageLocalPath, 云数据类型Enum.处理结果); ResumeGUI(); }); }, delegate(ProgressArgs progressArgs) { UIUtil.Invoke(this, delegate { lbWaiting.Content = "正在下载,请稍候。" + progressArgs.ToString(); lbDownloadProgress.Content = progressArgs.ToString(); Console.WriteLine(progressArgs); }); }, 云数据类型Enum); }
private void DownloadDicom(FileListItem selectedFile, DataListItem dataListItem, string selectedDicomPackageLocalPath, 云数据类型Enum 云数据类型Enum) { DownloadFileWorker.Download( selectedFile, selectedDicomPackageLocalPath, delegate(string filename) { UIUtil.Invoke(this, delegate { try { //string tempPath = selectedDicomPackageLocalPath.Substring(0, selectedDicomPackageLocalPath.LastIndexOf(Path.DirectorySeparatorChar)); //System.Diagnostics.Process.Start(tempPath); //ResumeGUI(); while (!File.Exists(selectedDicomPackageLocalPath)) { } string destFileRAR = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(selectedDicomPackageLocalPath), System.IO.Path.GetFileNameWithoutExtension(selectedDicomPackageLocalPath) + ".zip"); File.Copy(selectedDicomPackageLocalPath, destFileRAR); File.Delete(selectedDicomPackageLocalPath); selectedDicomPackageLocalPath = destFileRAR; //System.Diagnostics.Process.Start(System.IO.Path.GetDirectoryName(selectedDicomPackageLocalPath)); string destFolder = AirwayPatients.BaseDicomFolder + "\\" + dataListItem.PatientName + "_" + dataListItem.StudyInstanceUID; //解压缩并用dicomviewer打开 FileDAO.upZip(selectedDicomPackageLocalPath, destFolder); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }); }, delegate(string errMsg) { UIUtil.Invoke(this, delegate { MessageBox.Show("下载发生异常!", "提示"); }); }, delegate(Exception ex) { UIUtil.Invoke(this, delegate { Util.ShowExceptionMessage(ex); }); }, delegate(ProgressArgs progressArgs) { UIUtil.Invoke(this, delegate { Console.WriteLine(progressArgs.Percentage.Value); Progress.Value = progressArgs.Percentage.Value; tbPercent.Text = ((progressArgs.Percentage.Value * 100).ToString("F2")).ToString() + " %"; txtFileSize.Text = FileDAO.HumanReadableFilesize(progressArgs.Total - progressArgs.Remains) + " / " + FileDAO.HumanReadableFilesize(_selectedFile.FileSize); tbSpeed.Text = progressArgs.Speed.HasValue ? FileDAO.HumanReadableFilesize((long)progressArgs.Speed.Value) + "/s" : ""; Console.WriteLine(progressArgs); }); }, 云数据类型Enum); }