void DownloadDocumentFromServer(Guid jobID, string filename, string dstFilePathname) { // Get file size from server long fileLength = _server.GetJobDocumentSize(_userID, jobID, filename); // Get max chunk size from app.config file int chunkSize = ((NetTcpBinding)_server.ChannelFactory.Endpoint.Binding).ReaderQuotas.MaxArrayLength; int chunkCount = (int)(fileLength / chunkSize); int lastChunkSize = (int)(fileLength % chunkSize); // Create local file stream and downlaod server chunks using (Stream stream = System.IO.File.Create(dstFilePathname)) { int pos = 0; for (int i = 0; i < chunkCount; i++) { JobDocumentChunk chunk = _server.DownloadJobDocumentChunk(_userID, jobID, filename, pos, chunkSize); stream.Write(chunk.Data, 0, chunkSize); pos += chunkSize; } if (lastChunkSize > 0) { JobDocumentChunk chunk = _server.DownloadJobDocumentChunk(_userID, jobID, filename, pos, lastChunkSize); stream.Write(chunk.Data, 0, lastChunkSize); } } }
void StreamUploadDocumentToServer(Guid jobID, string filePathname) { // Stream the file to the server string filename = Path.GetFileName(filePathname); _server.BeginUploadJobDocument(_userID, jobID, Path.GetFileName(filePathname)); // Initializes a stream to the server FileInfo fileInfo = new FileInfo(filePathname); JobDocumentChunk chunk = new JobDocumentChunk(); // Determines the size of the chunks and how many we need to stream the whole file int chunkSize = ((NetTcpBinding)_server.ChannelFactory.Endpoint.Binding).ReaderQuotas.MaxArrayLength; int chunkCount = (int)(fileInfo.Length / chunkSize); int lastChunkSize = (int)(fileInfo.Length % chunkSize); chunk.Data = new byte[chunkSize]; chunk.ByteCount = chunkSize; // Streams data to PixEdit Server Core using (FileStream stream = new FileStream(filePathname, FileMode.Open)) { for (int i = 0; i < chunkCount; i++) { stream.Read(chunk.Data, 0, chunkSize); _server.UploadJobDocumentChunk(_userID, jobID, filename, chunk); } if (lastChunkSize > 0) { stream.Read(chunk.Data, 0, lastChunkSize); chunk.ByteCount = (int)lastChunkSize; _server.UploadJobDocumentChunk(_userID, jobID, filename, chunk); } } }