private void OnFileDownloadReq(Datagram datagram) { FileDownloadReq req = datagram.UnSerialData <FileDownloadReq>(); string path = FileRootPath + "\\" + datagram.Sender.ToString(); path += ("" == req.Path ? "" : req.Path + "\\") + req.Name; Download download = new Download(path); Guid download_id = Guid.NewGuid(); if (FileCache.TryAdd(download_id, download)) { FileDownloadRes res = new FileDownloadRes { DownloadID = download_id, Size = (int)download.Length }; datagram.DataType = DatagramType.Client; datagram.MessageType = CloudDatagramDefine.FileDownloadRes; datagram.Datas = res.ToByteArray(); if (!Send(datagram.ToByteArray())) { Notify(IKXTServer.LogLevel.Error, "数据发送异常"); Close(); } } else { download.Close(); } }
private void OnCloud_FileDownloadRes(Datagram datagram) { FileDownloadRes response = datagram.UnSerialData <FileDownloadRes>(); if (RunningDatas.RequestTable.TryRemove(datagram.RequestID, out RequestSender value)) { value.RequestCallback(response); } }
public void RequestCallback(object response) { if (null != response) { if (response.GetType() == FileUploadResTemp.GetType()) { WaitTimer.Stop(); FileUploadRes res = response as FileUploadRes; Root.ToStartUpload(res.UploadID, File, ID); } else if (response.GetType() == FileDownloadResTemp.GetType()) { WaitTimer.Stop(); FileDownloadRes res = response as FileDownloadRes; File.Size = res.Size; Root.ToStartDownload(res.DownloadID, File, ID); } } }