-
Notifications
You must be signed in to change notification settings - Fork 368
/
KernelCommandAndEventSignalRHubConnectionSender.cs
37 lines (30 loc) · 1.55 KB
/
KernelCommandAndEventSignalRHubConnectionSender.cs
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
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.Connection;
using Microsoft.DotNet.Interactive.Events;
namespace Microsoft.DotNet.Interactive.Http;
public class KernelCommandAndEventSignalRHubConnectionSender : IKernelCommandAndEventSender
{
// QUESTION: (KernelCommandAndEventSignalRHubConnectionSender) tests?
private readonly HubConnection _hubConnection;
public KernelCommandAndEventSignalRHubConnectionSender(HubConnection sender)
{
_hubConnection = sender ?? throw new ArgumentNullException(nameof(sender));
RemoteHostUri = KernelHost.CreateHostUri($"signalrhub{_hubConnection.ConnectionId}");
}
public async Task SendAsync(KernelCommand kernelCommand, CancellationToken cancellationToken)
{
await _hubConnection.SendAsync("kernelCommandFromServer", KernelCommandEnvelope.Serialize(KernelCommandEnvelope.Create(kernelCommand)),
cancellationToken: cancellationToken);
}
public async Task SendAsync(KernelEvent kernelEvent, CancellationToken cancellationToken)
{
await _hubConnection.SendAsync("kernelEventFromServer", KernelEventEnvelope.Serialize(KernelEventEnvelope.Create(kernelEvent)), cancellationToken: cancellationToken);
}
public Uri RemoteHostUri { get; }
}