コード例 #1
0
ファイル: Index.razor.cs プロジェクト: zama202/BlazorApp1
        protected override async Task OnInitializedAsync()
        {
            hubConnection = new HubConnectionBuilder()
                            .WithUrl("https://localhost:5001/NotificationHub")
                            .Build();

            hubConnection.On <string, Event>("UpdateTwin", (action, eventArg) =>
            {
                Twin.DoAction(action, eventArg);
                StateHasChanged();
            });
            hubConnection.On <string, Event>("UpdateAlerts", (action, eventArg) =>
            {
                LastTsAlerts = DateTime.Now.ToString("dddd, dd MMMM yyyy - HH:mm:ss");
                AlertService.DoAction(action, eventArg);
                StateHasChanged();
            });
            hubConnection.On <string, Event>("UpdateTelemetry", (action, eventArg) =>
            {
                lineChartComponent.DoAction(action, eventArg);
                _lineChartJs.Update();
                StateHasChanged();
            });
            hubConnection.On <string, Event>("UpdateStatistics", (action, eventArg) =>
            {
                LastTsStatistics = DateTime.Now.ToString("dddd, dd MMMM yyyy - HH:mm:ss");
                pieChartComponent.DoAction(action, eventArg);
                _pieChartJs.Update();
                StateHasChanged();
            });


            hubConnection.On <string, string>("ReceiveMessage", (user, message) =>
            {
                var encodedMsg = $"{user}: {message}";
                Message        = encodedMsg;
                Messages.Add(encodedMsg);
                StateHasChanged();
            });

            await hubConnection.StartAsync();
        }