private static bool ClientSendFileDataBlock(byte[] fileDataArry, int CanReadLength, string fileName, string guId, string serverDir, bool EndFlag) { bool result = false; if (WCFClientProxy.TestPCClientProxy()) { string resultStr = GlobalStaticObj.Instance.proxyFile.ReceiveFile2(fileDataArry, CanReadLength, fileName, guId, serverDir, EndFlag); bool.TryParse(resultStr, out result); } return(result); }
static void upLoadTimer_Elapsed(object sender, ElapsedEventArgs e) { Thread.CurrentThread.IsBackground = true; if (WCFClientProxy.TestPCClientProxy()) { lock (mylock0) { string resultStr = GlobalStaticObj.Instance.proxyFile.GetUploadFileStatus(UpLoadReceiveFileId.ToArray <string>(), UserId, PCClientCookieStr); if (string.IsNullOrEmpty(resultStr)) { return; } else if (resultStr == "Session Error") { MessageBox.Show("会话认证异常"); return; } List <TransferReceiveFileObj> myList = JsonConvert.DeserializeObject <List <TransferReceiveFileObj> >(resultStr); foreach (TransferReceiveFileObj obj in myList) { UpLoadFileReceiveMsg(new UpLoadFileReceiveEventArgs(obj)); if (obj == null) { } else { if (obj.WriteSize == obj.FileSize) { RemoveIdList(obj.guId); } } } if (UpLoadReceiveFileId.Count == 0) { if (upLoadTimer == null) { } else { upLoadTimer.Stop(); upLoadTimer = null; } } } } }
//private static void loadData(string path, string fileName, string guId) //{ // DownLoadFileDataObj obj = new DownLoadFileDataObj(); // if (GlobalStaticObj.Instance.proxyFile.GetSucDataBlock(guId)) // { // DownLoadFileOoj_Client fileObj = new DownLoadFileOoj_Client(); // fileObj.FileName = fileName; // fileObj.guId = guId; // fileObj.DownLoadStatus = GetFileDownLoadStatus.StartDownLoad; // fileObj.DownLoadSize = 0; // DownLoadFilesQueue.Instance.Add(guId, fileObj); // DownLoadFileMsg(new DownLoadFileEventArgs(guId,fileObj)); // getFileDataBlocks(path, fileName, guId, out obj); // if (!obj.EndFlag) // { // loadData(path, fileName, guId); // } // else // { // DownLoadFileOoj_Client fileObj0 = new DownLoadFileOoj_Client(); // fileObj0.FileName = fileName; // fileObj0.guId = guId; // fileObj0.DownLoadStatus = GetFileDownLoadStatus.DownLoadEnd; // DownLoadFilesQueue.Instance.Add(guId, fileObj0); // DownLoadFileMsg(new DownLoadFileEventArgs(guId,fileObj0)); // return; // } // } // else { // loadData(path, fileName, guId); // } //} // private static void getFileDataBlocks(string path, string fileName, string guId, out DownLoadFileDataObj obj0) //{ // string resultStr = GlobalStaticObj.Instance.proxyFile.DownLoadFileDataBlock(path, fileName, guId); // DownLoadFileDataObj obj = JsonConvert.DeserializeObject<DownLoadFileDataObj>(resultStr); // if (!string.IsNullOrEmpty(resultStr)) // { // obj0 = obj; // DownLoadFilesBlocksQueue.Instance.Add(obj); // DownLoadFileOoj_Client fileObj0 = new DownLoadFileOoj_Client(); // fileObj0.FileName = fileName; // fileObj0.guId = guId; // fileObj0.DownLoadStatus = GetFileDownLoadStatus.DownLoadEnd; // fileObj0.DownLoadSize = fileObj0.DownLoadSize + obj.FileData.Length; // DownLoadFilesQueue.Instance.Add(guId, fileObj0); // DownLoadFileMsg(new DownLoadFileEventArgs(guId,fileObj0)); // } // if(obj.EndFlag) // { // obj0 = obj; // DownLoadFileOoj_Client fileObj0 = new DownLoadFileOoj_Client(); // fileObj0.FileName = fileName; // fileObj0.guId = guId; // fileObj0.DownLoadStatus = GetFileDownLoadStatus.DownLoadEnd; // fileObj0.DownLoadSize = fileObj0.DownLoadSize + obj.FileData.Length; // DownLoadFilesQueue.Instance.Add(guId, fileObj0); // DownLoadFileMsg(new DownLoadFileEventArgs(guId, fileObj0)); // return; // } // getFileDataBlocks(path,fileName,guId,out obj0); //} //private static void getFileDataBlocks(string guId) //{ // string resultStr = GlobalStaticObj.Instance.proxyFile.DownLoadFileDataBlock(guId); // DownLoadFileDataObj obj = JsonConvert.DeserializeObject<DownLoadFileDataObj>(resultStr); // if (!string.IsNullOrEmpty(resultStr)) // { // DownLoadFileOoj_Client fileObj0 = new DownLoadFileOoj_Client(); // DownLoadFilesQueue.Instance.Get(obj.guId, out fileObj0); // DownLoadFilesBlocksQueue.Instance.Add(obj); // fileObj0.DownLoadStatus = GetFileDownLoadStatus.DownLoadEnd; // fileObj0.DownLoadSize = fileObj0.DownLoadSize + obj.FileData.Length; // DownLoadFilesQueue.Instance.Add(guId, fileObj0); // DownLoadFileMsg(new DownLoadFileEventArgs(guId, fileObj0)); // } // if (obj.EndFlag) // { // obj0 = obj; // DownLoadFileOoj_Client fileObj0 = new DownLoadFileOoj_Client(); // fileObj0.FileName = fileName; // fileObj0.guId = guId; // fileObj0.DownLoadStatus = GetFileDownLoadStatus.DownLoadEnd; // fileObj0.DownLoadSize = fileObj0.DownLoadSize + obj.FileData.Length; // DownLoadFilesQueue.Instance.Add(guId, fileObj0); // DownLoadFileMsg(new DownLoadFileEventArgs(guId, fileObj0)); // return; // } // getFileDataBlocks(path, fileName, guId, out obj0); //} public static bool ClientSendFileDataBlock(TransferFileDataObj item) { bool result = false; if (WCFClientProxy.TestPCClientProxy()) { TransferSendFileObj fileObj = new TransferSendFileObj(); FilesQueue.Instance.Get(item.guId, out fileObj); string resultStr = GlobalStaticObj.Instance.proxyFile.ReceiveFile(item.FileData, item.CanReadLength, item.FilePath, item.FileName, item.Order_Num, item.guId, fileObj.serverDir, fileObj.FileSize, item.EndFlag, fileObj.DataBlockCount, UserId, PCClientCookieStr); bool.TryParse(resultStr, out result); if (FilesBlocksQueue.PCClientFilesBlocksQueue.IsEmpty) { FilesBlocksQueue.RunFlag = true; //Utility.Log.Log.writeLineToLog("发送线程终止:" + item.Order_Num.ToString() + " 结果:" + result.ToString(), "Send"); } //Utility.Log.Log.writeLineToLog("发送文件块:" + item.Order_Num.ToString() + " 结果:" + result.ToString(), "Send"); } return(result); }
public static bool ClientDownLoadFile(string path, string fileName, string guId, out string msg, out long FileSize) { if (WCFClientProxy.TestPCClientProxy()) { if (GlobalStaticObj.Instance.proxyFile.DownLoadFile(path, fileName, guId, UserId, PCClientCookieStr, out msg, out FileSize)) { DownLoadFileOoj_Client fileObj = new DownLoadFileOoj_Client(); fileObj.FileName = fileName; fileObj.guId = guId; fileObj.FileSize = FileSize; fileObj.path = path; fileObj.NextDataBlockNum = 1; fileObj.DownLoadStatus = GetFileDownLoadStatus.waiting; DownLoadFilesQueue.Instance.Add(guId, fileObj); DownLoadFileMsg(new DownLoadFileEventArgs(guId, fileObj)); lock (mylock3) { ParameterizedThreadStart ParStart = new ParameterizedThreadStart(ThreadDownLoadMethod); Thread myThread = new Thread(ParStart); myThread.IsBackground = true; FileThreadPramObj o = new FileThreadPramObj(); o.guId = guId; o.myThread = myThread; myThread.Start(o); } return(true); } return(false); } else { msg = "无法连接服务端"; FileSize = 0; return(false); } }