async Task IClient.Upload(string fileName, string srcPath) { var file = File.Open(srcPath, FileMode.Open, FileAccess.Read); var request = new SrvUploadRequest { FileName = fileName, FileSize = file.Length }; var tcpOp = startTcpOp(request); await tcpOp.Write(request); var response = await tcpOp.Read <SrvUploadResponse>(); validate(response); await tcpOp.WriteBytesFrom(file, file.Length); file.Close(); response = await tcpOp.Read <SrvUploadResponse>(); validate(response); }
async Task IServer.UploadFile(SrvUploadRequest request, ITcpOp tcpOp) { _log.Info(request.TrackingId, request); validate(request); var user = await getUser(request); authenticate(user, request); var dstPath = makeFilePath(user, request.FileName); Directory.CreateDirectory(user.Folder); var file = File.Open(dstPath, FileMode.Create); var response = makeResponse <SrvUploadResponse>(request); await tcpOp.Write(response); await tcpOp.ReadBytesTo(file, request.FileSize); file.Flush(); file.Close(); await tcpOp.Write(response); _log.Info(request.TrackingId, response); }