ホテル管理システム
ogi
yesterday 1a1c8e71fcd14858f595029f089b2d4a00202b32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using Google.Protobuf;
using Grpc.Core;
using Grpc.Net.Client;
using HotelPms.Data.Common;
using HotelPms.Data.UseInfo;
using HotelPms.Share.Util;
using System;
using System.Data;
using System.Threading.Tasks;
using HotelPms.Data;
using System.Collections.Generic;
using HotelPms.Data.Common.Pagination;
using System.Text.Json;
using System.Threading;
using HotelPms.Data.Client;
 
namespace HotelPms.DataAccessGrpc.Client
{
    public class UseAccess : IDisposable
    {
        /// <summary>
        /// チャネル
        /// </summary>
        public GrpcChannel Channel { get; private set; }
        public UseCore.UseCoreClient Client { get; private set; }
 
 
        public UseAccess(GrpcChannel channel)
        {
            Channel = channel;
            Client = new UseCore.UseCoreClient(Channel);
        }
 
        public void Dispose()
        {
 
        }
 
        /// <summary>
        /// 同期データ取得
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public Use GetData(string where)
        {
            return Client.GetData(GrpcClient.CreateDataRequest(0, where));
        }
 
        public async Task<Use> GetDataAsync(string where)
        {
            return await Client.GetDataAsync(GrpcClient.CreateDataRequest(0, where));
        }
 
        public async Task<Use> GetDataStream()
        {
            return await GetDataStream(string.Empty);
        }
 
        /// <summary>
        /// データ取得
        /// </summary>
        /// <returns></returns>
        public async Task<Use> GetDataStream(string where)
        {
            Use 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<Use>())
                {
                    table = message;
                    break;
                }
            }
            return table;
        }
 
        public DataResult SetData(Use table)
        {
            return Client.SetData(table);
        }
 
        public async Task<DataResult> SetDataAsync(Use table)
        {
            return await Client.SetDataAsync(table);
        }
 
        /// <summary>
        /// バッチ更新
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public async Task<DataResult> SetDataStream(Use 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;
        }
    }
}