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.DataAccessGrpc.Client/DemoAccess.cs | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 289 insertions(+), 0 deletions(-)
diff --git a/HotelPms.DataAccessGrpc.Client/DemoAccess.cs b/HotelPms.DataAccessGrpc.Client/DemoAccess.cs
new file mode 100644
index 0000000..9c76bc9
--- /dev/null
+++ b/HotelPms.DataAccessGrpc.Client/DemoAccess.cs
@@ -0,0 +1,289 @@
+using Google.Protobuf;
+using Grpc.Core;
+using Grpc.Net.Client;
+using HotelPms.Data;
+using HotelPms.Data.Client;
+using HotelPms.Data.Common;
+using HotelPms.Data.Common.Interface.Access;
+using HotelPms.Data.Common.Pagination;
+using HotelPms.Data.Master;
+using HotelPms.Share.Util;
+using System.Data;
+using System.Text.Json;
+
+namespace HotelPms.DataAccessGrpc.Client
+{
+ public class DemoAccess : IDisposable, IDemo
+ {
+ /// <summary>
+ /// チャネル
+ /// </summary>
+ public GrpcChannel? Channel { get; private set; }
+ public DemoCore.DemoCoreClient? Client { get; private set; }
+
+ private static DemoAccess? m_Default;
+
+ public static DemoAccess Instance
+ {
+ get
+ {
+ if (m_Default == null) { m_Default = new DemoAccess(GrpcFactory.Instance.Channel); }
+ return m_Default;
+ }
+ }
+
+ public DemoAccess(GrpcChannel channel)
+ {
+ Channel = channel;
+ Client = new DemoCore.DemoCoreClient(Channel);
+ }
+
+ public void Dispose()
+ {
+
+ }
+
+ /// <summary>
+ /// 排他チェックのため、最新更新日取得する
+ /// </summary>
+ /// <param name="pID"></param>
+ /// <returns></returns>
+ public int GetUpdateID(int pID)
+ {
+ return CConvert.ToInt(GrpcClient.ExecuteScalarSync(Channel, $"SELECT UpdateID FROM M_Demo WHERE ID = {pID}"));
+ }
+
+ public bool Exists(int pID)
+ {
+ return GrpcClient.ExecuteScalarSync(Channel, $"IF EXISTS(SELECT 1 FROM M_Demo WHERE ID = {pID}) SELECT 1 ELSE SELECT 0") == "1";
+ }
+
+ public async Task<bool> ExistsAsync(int pID)
+ {
+ return await GrpcClient.ExecuteScalar(Channel, $"IF EXISTS(SELECT 1 FROM M_Demo WHERE ID = {pID}) SELECT 1 ELSE SELECT 0") == "1";
+
+ }
+
+ public async Task<FileGrpcData> OutputStream(PagingRequest request)
+ {
+ FileGrpcData data = null;
+ request.Table = "M_Demo";
+ string json = JsonSerializer.Serialize(request);
+ using (var call = Client.OutputStream(GrpcClient.CreateDataRequest(2, json)))
+ {
+ var reaponseStream = call.ResponseStream;
+ //データの取得
+ while (await reaponseStream.MoveNext(CancellationToken.None))
+ {
+ data = reaponseStream.Current;
+ }
+ }
+ return data;
+ }
+
+ public async Task<DemoTable> GetPageData(PagingRequest request)
+ {
+ request.Table = "M_Demo";
+ string json = JsonSerializer.Serialize(request);
+ return await Client.GetDataAsync(GrpcClient.CreateDataRequest(1, json));
+ }
+
+
+ public DataTable GetMasterGridData(string where)
+ {
+ GrpcTable table = GrpcClient.GetTable(Channel, (int)ETableActionType.DemoMasterGrid, where);
+ return table.ToDataTable();
+ }
+
+ /// <summary>
+ /// 同期データ取得
+ /// </summary>
+ /// <param name="where"></param>
+ /// <returns></returns>
+ public DemoTable GetData(string where)
+ {
+ return Client.GetData(GrpcClient.CreateDataRequest(0, where));
+ }
+
+ public async Task<DemoTable> GetDataAsync(string where)
+ {
+ return await Client.GetDataAsync(GrpcClient.CreateDataRequest(0, where));
+ }
+
+ /// <summary>
+ /// データ取得
+ /// </summary>
+ /// <returns></returns>
+ public Demo GetItem(int pID)
+ {
+ DemoTable table = GetData($"ID = {pID}");
+ if(table == null || table.ErrNo != 0 || table.Rows.Count == 0) { return null; }
+ return table.Rows[0];
+ }
+
+ public async Task<DemoTable> GetDataStream()
+ {
+ return await GetDataStream(string.Empty);
+ }
+
+ /// <summary>
+ /// データ取得
+ /// </summary>
+ /// <returns></returns>
+ public async Task<DemoTable> GetDataStream(string where)
+ {
+ DemoTable table = null;
+ using (var call = Client.GetDataStream())
+ {
+ await call.RequestStream.WriteAsync(GrpcClient.CreateDataRequest(0, where));
+ await call.RequestStream.CompleteAsync(); // Finish call and report results
+
+ //データの取得
+ await foreach (var message in call.ResponseStream.ReadAllAsync<DemoTable>())
+ {
+ table = message;
+ break;
+ }
+ }
+ return table;
+ }
+
+ public async Task<DataResult> AddAsync(Demo data)
+ {
+ return await Client.AddAsync(data);
+ }
+
+ public DataResult Add(Demo data)
+ {
+ return Client.Add(data);
+ }
+
+ public async Task<DataResult> UpdateAsync(Demo data)
+ {
+ return await Client.UpdateAsync(data);
+ }
+
+ public DataResult Update(Demo data)
+ {
+ return Client.Update(data);
+ }
+
+ /// <summary>
+ /// 追加若しくは更新
+ /// </summary>
+ /// <param name="data"></param>
+ /// <param name="add"></param>
+ /// <returns></returns>
+ private async Task<DataResult> AddOrUpdateStream(Demo data, bool add)
+ {
+ DataResult result = null;
+ using (var call = add ? Client.AddStream() : Client.UpdateStream())
+ {
+ await call.RequestStream.WriteAsync(data);
+ await call.RequestStream.CompleteAsync(); // Finish call and report results
+
+ //データの取得
+ await foreach (var message in call.ResponseStream.ReadAllAsync<DataResult>())
+ {
+ result = message;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /// <summary>
+ /// 追加
+ /// </summary>
+ /// <param name="data"></param>
+ /// <returns></returns>
+ public async Task<DataResult> AddStream(Demo data)
+ {
+ return await AddOrUpdateStream(data, true);
+ }
+
+ /// <summary>
+ /// 更新
+ /// </summary>
+ /// <param name="data"></param>
+ /// <returns></returns>
+ public async Task<DataResult> UpdateStream(Demo data)
+ {
+ return await AddOrUpdateStream(data, true);
+ }
+
+ public DataResult Remove(string where)
+ {
+ SqlWhere data = new SqlWhere()
+ {
+ Data = ByteString.CopyFromUtf8(where)
+ };
+ return Client.Remove(data);
+ }
+
+ public async Task<DataResult> RemoveAsync(string where)
+ {
+ SqlWhere data = new SqlWhere()
+ {
+ Data = ByteString.CopyFromUtf8(where)
+ };
+ return await Client.RemoveAsync(data);
+ }
+
+ /// <summary>
+ /// 削除
+ /// </summary>
+ /// <param name="where"></param>
+ /// <returns></returns>
+ public async Task<DataResult> RemoveStream(string where)
+ {
+ DataResult result = null;
+ SqlWhere data = new SqlWhere()
+ {
+ Data = ByteString.CopyFromUtf8(where)
+ };
+
+ using (var call = Client.RemoveStream())
+ {
+ await call.RequestStream.WriteAsync(data);
+ await call.RequestStream.CompleteAsync(); // Finish call and report results
+
+ //データの取得
+ await foreach (var message in call.ResponseStream.ReadAllAsync<DataResult>())
+ {
+ result = message;
+ break;
+ }
+ }
+ return result;
+ }
+
+ public DataResult SetData(DemoTable table)
+ {
+ return Client.SetData(table);
+ }
+
+ /// <summary>
+ /// バッチ更新
+ /// </summary>
+ /// <param name="table"></param>
+ /// <returns></returns>
+ public async Task<DataResult> SetDataStream(DemoTable table)
+ {
+ DataResult result = null;
+ using (var call = Client.SetDataStream())
+ {
+ await call.RequestStream.WriteAsync(table);
+ await call.RequestStream.CompleteAsync(); // Finish call and report results
+
+ //データの取得
+ await foreach (var message in call.ResponseStream.ReadAllAsync<DataResult>())
+ {
+ result = message;
+ break;
+ }
+ }
+ return result;
+ }
+ }
+}
--
Gitblit v1.10.0