public async Task ConnectStatusStreamAsync() { if (_connectionConfig.ServerMode == "v1") { // older signalr client/server _legacyConnection = new Microsoft.AspNet.SignalR.Client.HubConnection(_statusHubUri); _legacyConnection.Credentials = System.Net.CredentialCache.DefaultCredentials; var hubProxy = _legacyConnection.CreateHubProxy("StatusHub"); hubProxy.On<ManagedCertificate>(Providers.StatusHubMessages.SendManagedCertificateUpdateMsg, (u) => OnManagedCertificateUpdated?.Invoke(u)); hubProxy.On<RequestProgressState>(Providers.StatusHubMessages.SendProgressStateMsg, (s) => OnRequestProgressStateUpdated?.Invoke(s)); hubProxy.On<string, string>(Providers.StatusHubMessages.SendMsg, (a, b) => OnMessageFromService?.Invoke(a, b)); _legacyConnection.Reconnecting += OnConnectionReconnecting; _legacyConnection.Reconnected += OnConnectionReconnected; _legacyConnection.Closed += OnConnectionClosed; await _legacyConnection.Start(); } else { // newer signalr client/server // TODO: auth: https://docs.microsoft.com/en-us/aspnet/core/signalr/authn-and-authz?view=aspnetcore-3.1 connection = new HubConnectionBuilder() .WithUrl(_statusHubUri) .WithAutomaticReconnect() .AddMessagePackProtocol() .Build(); connection.Closed += async (error) => { await Task.Delay(new Random().Next(0, 5) * 1000); await connection.StartAsync(); }; connection.On<RequestProgressState>(Providers.StatusHubMessages.SendProgressStateMsg, (s) => { OnRequestProgressStateUpdated?.Invoke(s); }); connection.On<ManagedCertificate>(Providers.StatusHubMessages.SendManagedCertificateUpdateMsg, (u) => { OnManagedCertificateUpdated?.Invoke(u); }); connection.On<string, string>(Providers.StatusHubMessages.SendMsg, (a, b) => { OnMessageFromService?.Invoke(a, b); }); await connection.StartAsync(); } }
public async Task ConnectStatusStreamAsync() { connection = new HubConnection(url); hubProxy = connection.CreateHubProxy("StatusHub"); hubProxy.On <ManagedSite>("ManagedSiteUpdated", (u) => OnManagedSiteUpdated?.Invoke(u)); hubProxy.On <RequestProgressState>("RequestProgressStateUpdated", (s) => OnRequestProgressStateUpdated?.Invoke(s)); hubProxy.On <string, string>("SendMessage", (a, b) => OnMessageFromService?.Invoke(a, b)); connection.Reconnecting += OnConnectionReconnecting; connection.Reconnected += OnConnectionReconnected; connection.Closed += OnConnectionClosed; await connection.Start(); }
public async Task ConnectStatusStreamAsync() { connection = new HubConnection(_statusHubUri); connection.Credentials = System.Net.CredentialCache.DefaultCredentials; hubProxy = connection.CreateHubProxy("StatusHub"); hubProxy.On <ManagedCertificate>("ManagedCertificateUpdated", (u) => OnManagedCertificateUpdated?.Invoke(u)); hubProxy.On <RequestProgressState>("RequestProgressStateUpdated", (s) => OnRequestProgressStateUpdated?.Invoke(s)); hubProxy.On <string, string>("SendMessage", (a, b) => OnMessageFromService?.Invoke(a, b)); connection.Reconnecting += OnConnectionReconnecting; connection.Reconnected += OnConnectionReconnected; connection.Closed += OnConnectionClosed; await connection.Start(); }
public async Task ConnectStatusStreamAsync() { if (_connectionConfig.ServerMode == "v1") { // older signalr client/server _legacyConnection = new Microsoft.AspNet.SignalR.Client.HubConnection(_statusHubUri); _legacyConnection.Credentials = System.Net.CredentialCache.DefaultCredentials; var hubProxy = _legacyConnection.CreateHubProxy("StatusHub"); hubProxy.On <ManagedCertificate>(Providers.StatusHubMessages.SendManagedCertificateUpdateMsg, (u) => OnManagedCertificateUpdated?.Invoke(u)); hubProxy.On <RequestProgressState>(Providers.StatusHubMessages.SendProgressStateMsg, (s) => OnRequestProgressStateUpdated?.Invoke(s)); hubProxy.On <string, string>(Providers.StatusHubMessages.SendMsg, (a, b) => OnMessageFromService?.Invoke(a, b)); _legacyConnection.Reconnecting += OnConnectionReconnecting; _legacyConnection.Reconnected += OnConnectionReconnected; _legacyConnection.Closed += OnConnectionClosed; await _legacyConnection.Start(); } else { // newer signalr client/server // TODO: auth: https://docs.microsoft.com/en-us/aspnet/core/signalr/authn-and-authz?view=aspnetcore-3.1 connection = new HubConnectionBuilder() .WithUrl(_statusHubUri, opts => { opts.HttpMessageHandlerFactory = (message) => { if (message is System.Net.Http.HttpClientHandler clientHandler) { if (_connectionConfig.AllowUntrusted) { // allow invalid tls cert clientHandler.ServerCertificateCustomValidationCallback += (sender, certificate, chain, sslPolicyErrors) => { return(true); }; } } return(message); }; }) .WithAutomaticReconnect() .AddMessagePackProtocol() .Build(); connection.Closed += async(error) => { await Task.Delay(new Random().Next(0, 5) * 1000); await connection.StartAsync(); }; connection.On <RequestProgressState>(Providers.StatusHubMessages.SendProgressStateMsg, (s) => { OnRequestProgressStateUpdated?.Invoke(s); }); connection.On <ManagedCertificate>(Providers.StatusHubMessages.SendManagedCertificateUpdateMsg, (u) => { OnManagedCertificateUpdated?.Invoke(u); }); connection.On <string, string>(Providers.StatusHubMessages.SendMsg, (a, b) => { OnMessageFromService?.Invoke(a, b); }); await connection.StartAsync(); } }