예제 #1
0
 HubConnection DefaultConnectionBuilder(string route, IHubConnectionBuilder builder)
 {
     builder = builder.WithUrl(route, ConfigureOptions);
     if (AutoReconnect)
     {
         builder.WithAutomaticReconnect();
     }
     if (ConfigureLogging != null)
     {
         builder.ConfigureLogging(ConfigureLogging);
     }
     return(builder.Build());
 }
예제 #2
0
        /// <inheritdoc/>
        public Task StartAsync(CancellationToken cancellationToken)
        {
            logger.LogDebug("Starting");
            connection = builder.WithAutomaticReconnect()
                         .WithUrl(options.CurrentValue.ConnectionString)
                         .Build();
            receiveHistoryHandel     = connection.On <IEnumerable <ChatMessage> >(ReceiveHistoryMethodName, OnReceiveHistory);
            receiveMessageHandel     = connection.On <ChatMessage>(ReceiveMethodName, OnReceiveMessage);
            connection.Closed       += OnStateChangedAsync;
            connection.Reconnected  += OnStateChangedAsync;
            connection.Reconnecting += OnStateChangedAsync;

            // Don't block the application's startup by awaiting the end of the successful connection establishment.
            InitalizeConnection(cancellationToken).FireAndForgetSafeAsync(logger);
            logger.LogDebug("Started");
            return(Task.CompletedTask);
        }