From 1a1c8e71fcd14858f595029f089b2d4a00202b32 Mon Sep 17 00:00:00 2001
From: ogi <Administrator@S-OGI-PC>
Date: Fri, 05 Dec 2025 09:24:16 +0900
Subject: [PATCH] プロジェクトファイルを追加。
---
HotelPms.GrpcService/Services/FileService.cs | 79 +++++++++++++++++++++++++++++++++++++++
1 files changed, 79 insertions(+), 0 deletions(-)
diff --git a/HotelPms.GrpcService/Services/FileService.cs b/HotelPms.GrpcService/Services/FileService.cs
new file mode 100644
index 0000000..982cc20
--- /dev/null
+++ b/HotelPms.GrpcService/Services/FileService.cs
@@ -0,0 +1,79 @@
+using HotelPms.Data;
+using Google.Protobuf;
+using Grpc.Core;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace HotelPms.GrpcService
+{
+ public class FileService : FileCore.FileCoreBase
+ {
+ private readonly ILogger<FileService> _logger;
+ private IConfiguration m_Configuration;
+
+ public FileService(ILogger<FileService> logger, IConfiguration configuration)
+ {
+ _logger = logger;
+ m_Configuration = configuration;
+ }
+
+ public async override Task DownLoad(FileGrpcHead request, IServerStreamWriter<FileGrpcData> responseStream, ServerCallContext context)
+ {
+ //1M単位送信する
+ string path = System.AppDomain.CurrentDomain.BaseDirectory + @"DownLoad\" + request.FileName;
+ if (System.IO.File.Exists(path))
+ {
+ System.IO.FileInfo fileInfo = new System.IO.FileInfo(path);
+ long fileLength = fileInfo.Length;
+
+ using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read))
+ {
+ using (System.IO.BinaryReader br = new System.IO.BinaryReader(fs))
+ {
+ long offsetFile = 0;
+ long buffSize = 1024 * 1024; //1M
+ long lastBiteSize = fileLength % buffSize; //余り
+ long currentTimes = 1;
+ long loopTimes = fileLength / buffSize; //回数
+ if (lastBiteSize > 0) { loopTimes++; }
+ long blockSize = 0;
+ FileGrpcData contentStruct;
+ while (currentTimes <= loopTimes)
+ {
+ fs.Seek(offsetFile, System.IO.SeekOrigin.Begin);
+ if (currentTimes == loopTimes)
+ {
+ blockSize = lastBiteSize;
+ }
+ else
+ {
+ blockSize = buffSize;
+ }
+
+ byte[] byteArray = br.ReadBytes((int)blockSize);
+ ByteString sbytes = ByteString.CopyFrom(byteArray);
+ contentStruct = new FileGrpcData
+ {
+ FileName = request.FileName,
+ Block = (int)currentTimes,
+ Content = sbytes,
+ };
+ await responseStream.WriteAsync(contentStruct);
+ currentTimes++;
+ offsetFile += blockSize;
+ }
+ }
+ }
+ }
+ }
+
+ public override Task<FileGrpcHead> UpLoad(IAsyncStreamReader<FileGrpcData> requestStream, ServerCallContext context)
+ {
+ return base.UpLoad(requestStream, context);
+ }
+ }
+}
--
Gitblit v1.10.0