private void UploadFile(ResourceNode node, string remotePath, string localPath, string taskId, string farmId) { var binding = new BasicHttpBinding { MaxReceivedMessageSize = 16777216 }; binding.MessageEncoding = WSMessageEncoding.Mtom; var address = new EndpointAddress("http://" + node.NodeAddress + "/FileService"); var fsservice = new FileStreamServiceClient(binding, address); FileStream fs = null; try { fs = new FileStream(localPath, FileMode.Open, FileAccess.Read); var lgth = fs.Length; var chunkSize = 67108864; var itr = lgth / chunkSize; if (itr * chunkSize < lgth) { itr++; } for (int i = 0; i < itr; i++) { var sm = new MemoryStream(); var leftBytes = Math.Min(fs.Length - chunkSize * i, chunkSize); sm.SetLength(leftBytes); fs.Read(sm.GetBuffer(), 0, (int)leftBytes); fs.Flush(); fsservice.SendFileChunkAsStream(new ChunkedFileStreamedMessage(chunkSize, farmId, remotePath, i, taskId, sm)); //CopyFile(fs, i, chuckSize); Log.Info("send " + i); sm.Close(); } } catch (Exception e) { Log.Error(e.Message); throw; } finally { if (fs != null) { fs.Close(); } } }
private void DownloadFile(ResourceNode node, string remotePath, string localPath, ulong taskId, string farmId) { var binding = new BasicHttpBinding { MaxReceivedMessageSize = 16777216 }; binding.MessageEncoding = WSMessageEncoding.Mtom; var address = new EndpointAddress("http://" + node.NodeAddress + "/FileService"); var fsservice = new FileStreamServiceClient(binding, address); int m = 0; bool finished = false; while (!finished) { const int bufferSize = 2048; var buffer = new byte[bufferSize]; var chunkSize = 67108864; using (var outputStream = new FileStream(localPath, FileMode.OpenOrCreate, FileAccess.Write)) { while (!finished) { //(chunkSize, farmId, remotePath, i, taskId, sm)) Stream resFileStream = fsservice.GetFileChunkAsStream(new GetFileChunkAsStreamRequest(remotePath, taskId, m, chunkSize)).GetFileChunkAsStreamResult; //resFileStream.Position = m; var bytesRead = resFileStream.Read(buffer, 0, bufferSize); var readFilebytes = 0; while (bytesRead > 0 && readFilebytes < chunkSize) { outputStream.Write(buffer, 0, bytesRead); bytesRead = resFileStream.Read(buffer, 0, bufferSize); readFilebytes += bufferSize; } if (bytesRead == 0 && readFilebytes < chunkSize) { finished = true; } m++; Console.WriteLine(m); resFileStream.Close(); } outputStream.Close(); } } }
private void DownloadFile(ResourceNode node, string remotePath, string localPath, ulong taskId, string farmId) { var binding = new BasicHttpBinding { MaxReceivedMessageSize = 16777216 }; binding.MessageEncoding = WSMessageEncoding.Mtom; var address = new EndpointAddress("http://" + node.NodeAddress + "/FileService"); var fsservice = new FileStreamServiceClient(binding, address); int m = 0; bool finished = false; while (!finished) { const int bufferSize = 2048; var buffer = new byte[bufferSize]; var chunkSize = 67108864; using (var outputStream = new FileStream(localPath, FileMode.OpenOrCreate, FileAccess.Write)) { while (!finished) { //(chunkSize, farmId, remotePath, i, taskId, sm)) Stream resFileStream = fsservice.GetFileChunkAsStream(new GetFileChunkAsStreamRequest(remotePath,taskId,m,chunkSize)).GetFileChunkAsStreamResult; //resFileStream.Position = m; var bytesRead = resFileStream.Read(buffer, 0, bufferSize); var readFilebytes = 0; while (bytesRead > 0 && readFilebytes < chunkSize) { outputStream.Write(buffer, 0, bytesRead); bytesRead = resFileStream.Read(buffer, 0, bufferSize); readFilebytes += bufferSize; } if (bytesRead == 0 && readFilebytes < chunkSize) { finished = true; } m++; Console.WriteLine(m); resFileStream.Close(); } outputStream.Close(); } } }