public DownloadResponse DownloadFile(TCPProtocol protocol, string repository) { try { DownloadResponse response; protocol.SendMessage(this); response = (DownloadResponse)protocol.RecieveMessage(); if (response.Result != TransferResponseEnum.OK) { return(response); } protocol.SendMessage(this); bool resp = protocol.RecieveFile(string.Format("{0}\\{1}", repository, this.FileName), Rest == 0, response.FileLength - this.Rest); response.Result = resp ? TransferResponseEnum.OK : TransferResponseEnum.Error; return(response); } catch (Exception ex) { throw new Exception("Error enviando mensaje " + ex.Message); } }
private void UploadFile(TCPProtocol protocol, UploadRequest request) { var response = new UploadResponse(); try { //Le comunico al servidor de conciliacion un usuario pidio subir un archivo. var remotingRequest = new ClientUploadRequest() { ClientName = request.ClientName, FileName = request.FileName }; _remotingService.SendMessage(remotingRequest); response.Result = ServerData.Instance.FileExists(request.FileName) ? TransferResponseEnum.FileExists : TransferResponseEnum.OK; protocol.SendMessage(response); if (response.Result == TransferResponseEnum.OK) { bool archivo = protocol.RecieveFile(string.Format("{0}\\{1}", ServerData.Instance.FileRepository, request.FileName), true, request.FileLength); response = new UploadResponse(); response.Result = (archivo) ? TransferResponseEnum.OK : TransferResponseEnum.Error; if (response.Result == TransferResponseEnum.OK) { ServerData.Instance.AddFile(request.FileName); } else { FileHelper.DeleteFile(string.Format("{0}\\{1}", ServerData.Instance.FileRepository, request.FileName)); } protocol.SendMessage(response); } else { Console.WriteLine("Error subiendo archivo"); } } catch (Exception ex) { FileHelper.DeleteFile(string.Format("{0}\\{1}", ServerData.Instance.FileRepository, request.FileName)); response.Result = TransferResponseEnum.ConnectionError; protocol.SendMessage(response); } }