コード例 #1
0
ファイル: FServer.cs プロジェクト: mamasha/f-storage
        async Task IServer.DownloadFile(SrvDownloadRequest request, ITcpOp tcpOp)
        {
            _log.Info(request.TrackingId, request);

            validate(request);

            var user = await getUser(request);

            authenticate(user, request);

            var srcPath = makeFilePath(user, request.FileName);

            if (!File.Exists(srcPath))
            {
                throw new ApplicationException($"Can't find '{request.FileName}'");
            }

            var file = File.Open(srcPath, FileMode.Open, FileAccess.Read);

            var response = makeResponse <SrvDownloadResponse>(request);

            response.FileSize = file.Length;
            await tcpOp.Write(response);

            await tcpOp.WriteBytesFrom(file, file.Length);

            file.Close();

            _log.Info(request.TrackingId, response);
        }
コード例 #2
0
        async Task IClient.Download(string fileName, string dstPath)
        {
            var request = new SrvDownloadRequest {
                FileName  = fileName,
                LocalPath = dstPath
            };

            var tcpOp = startTcpOp(request);

            await tcpOp.Write(request);

            var response = await tcpOp.Read <SrvDownloadResponse>();

            validate(response);

            var file = File.Open(dstPath, FileMode.Create);

            await tcpOp.ReadBytesTo(file, response.FileSize);

            file.Close();
        }