ホテル管理システム
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
using HotelPms.Data.Common.Dtos;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace HotelPms.SourceFactory
{
    public partial class FormSignalR : Form
    {
        private HubConnection hubConnection;
 
        public FormSignalR()
        {
            InitializeComponent();
        }
 
        private async void button1_Click(object sender, EventArgs e)
        {
            hubConnection = new HubConnectionBuilder()
                //.WithUrl(NavigationManager.ToAbsoluteUri("/notifyhub"))
                .WithUrl("https://localhost:44375/notifyhub")
                .AddMessagePackProtocol()
                .Build();
 
            hubConnection.On<MessageDto>("ReceiveMessage", (data) =>
            {
                var encodedMsg = $"【{data.Id}】【{data.ConnectionId} ⇒ {data.DestConnectionId}】{data.Data};{data.Tag}";
                listBox1.Items.Add(encodedMsg);
 
                var options = new JsonSerializerOptions
                {
                    WriteIndented = true
                };
                string json = JsonSerializer.Serialize(data, options);
                System.Diagnostics.Debug.WriteLine(json);
            });
 
            await hubConnection.StartAsync();
            label1.Text = hubConnection.ConnectionId;
        }
 
        private async Task Send()
        {
            MessageDto dto = new MessageDto()
            {
                Id = Guid.NewGuid(),
                UserID = "Client1",
                Data = textBox1.Text,
                Tag = "1000",
            };
            await hubConnection.SendAsync("SendMessage", dto);
        }
 
        public bool IsConnected =>
            hubConnection.State == HubConnectionState.Connected;
 
        public async ValueTask DisposeAsync()
        {
            await hubConnection.DisposeAsync();
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            _= Send();
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
 
        }
    }
}