Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <ICallbackRegistrar> GetRegistrarAsync(string userId)
        {
            await _lock.WaitAsync();

            try {
                if (string.IsNullOrEmpty(userId))
                {
                    userId = _config.SignalRUserId;
                    if (string.IsNullOrEmpty(userId))
                    {
                        userId = Guid.NewGuid().ToString();
                    }
                }
                if (!_clients.TryGetValue(userId, out var client))
                {
                    client = await SignalRClientRegistrar.CreateAsync(
                        _config.SignalREndpointUrl, _config.SignalRHubName,
                        userId, _logger);

                    _clients.Add(userId, client);
                }
                return(client.GetHandle());
            }
            finally {
                _lock.Release();
            }
        }
        /// <inheritdoc/>
        public async Task <ICallbackRegistrar> GetHubAsync(string endpointUrl,
                                                           string resourceId)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(SignalRHubClient));
            }
            if (string.IsNullOrEmpty(endpointUrl))
            {
                throw new ArgumentNullException(nameof(endpointUrl));
            }
            await _lock.WaitAsync();

            try {
                var lookup = endpointUrl;
                if (!string.IsNullOrEmpty(resourceId))
                {
                    lookup += resourceId;
                }
                if (!_clients.TryGetValue(lookup, out var client) ||
                    client.ConnectionId == null)
                {
                    if (client != null)
                    {
                        await client.DisposeAsync();

                        _clients.Remove(lookup);
                    }
                    client = await SignalRClientRegistrar.CreateAsync(_config,
                                                                      endpointUrl, _logger, resourceId, _provider, _jsonSettings);

                    _clients.Add(lookup, client);
                }
                return(client);
            }
            finally {
                _lock.Release();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create client
 /// </summary>
 /// <param name="outer"></param>
 public SignalRRegistrarHandle(SignalRClientRegistrar outer)
 {
     _outer = outer;
 }