public override async Task GetYDTEntryDataFrom(GetYDTEntryDataRequest request, IServerStreamWriter <GetYDTEntryDataResponse> responseStream, ServerCallContext context) { //获取请求 logger.LogDebug($"Peer:{context.Peer},DataFrom:{request.DateFrom}"); var time = request.DateFrom.ToDateTime().ToLocalTime(); string beginFile = time.ToString("yyyyMMddHH") + ".zip"; foreach (string file in Directory.GetFiles(zipPath)) { if (file.CompareTo(zipPath + beginFile) >= 0) { //读取文件 var fileBytes = File.ReadAllBytes(file); //返回结果 GetYDTEntryDataResponse ret = new GetYDTEntryDataResponse() { FileName = new FileInfo(file).Name }; logger.LogDebug($"GeneralFile:{ret.FileName}"); if (fileBytes != null) { ret.Data = Google.Protobuf.ByteString.CopyFrom(fileBytes); } await responseStream.WriteAsync(ret); } } logger.LogDebug($"responseStream:{responseStream}"); }
public override async Task <GetYDTEntryDataResponse> GetYDTEntryDataAt(GetYDTEntryDataRequest request, ServerCallContext context) { logger.LogDebug($"Peer:{context.Peer},DataFrom:{request.DateFrom}"); var time = request.DateFrom.ToDateTime().ToLocalTime(); string filePath = Directory.GetFiles(zipPath) .Where(file => string.Compare(new FileInfo(file).Name, time.ToString("yyyyMMddHH")) < 0) .OrderBy(file => new FileInfo(file).Name).Last(); Task <byte[]> t = new Task <byte[]>(() => { return(File.ReadAllBytes(filePath)); }); t.Start(); byte[] fileBytes = await t; GetYDTEntryDataResponse response = new GetYDTEntryDataResponse(); if (fileBytes != null) { response.FileName = new FileInfo(filePath).Name; response.Data = Google.Protobuf.ByteString.CopyFrom(fileBytes); } logger.LogDebug($"GeneralFile:{response.FileName}"); return(response); }