Exemple #1
0
        private async Task <ClientWebSocketReceiver> TryConnectAsync(CancellationToken cancellationToken)
        {
            _webSocket = new ClientWebSocket();
            _webSocket.Options.SetRequestHeader(NCSConstants.ConnectorName, InvocatorContext.ConnectorName);
            try
            {
                await _webSocket.ConnectAsync(InvocatorContext.Uri, cancellationToken);
            }
            catch (Exception ex)
            {
                ProxyLogHelper.Log(_loggerFactory, InvocatorContext, "Error", ex);
                return(null);
            }

            var receiverContext = new ClientWebSocketReceiverContext
            {
                Compressor       = _compressor,
                InvocatorContext = InvocatorContext,
                LoggerFactory    = _loggerFactory,
                WebSocket        = _webSocket
            };

            var receiver = new ClientWebSocketReceiver(_serviceProvider, receiverContext, Close, (connectionId) => {
                _connectionId = connectionId;
            });

            return(receiver);
        }
Exemple #2
0
 public ClientWebSocketReceiver(IServiceProvider serviceProvider,
                                ClientWebSocketReceiverContext context,
                                Action <ClientWebSocketReceiverContext> closeCallback,
                                Action <string> handshakeCallback = null)
 {
     _serviceProvider   = serviceProvider;
     _context           = context;
     _closeCallback     = closeCallback;
     _handshakeCallback = handshakeCallback;
     _logger            = context.LoggerFactory.CreateLogger <ClientWebSocketReceiver>();
 }
Exemple #3
0
        public static IClientWebSocketCommandInvocator GetInvocator(this ClientWebSocketReceiverContext context, IServiceProvider serviceProvider)
        {
            if (context.InvocatorContext != null)
            {
                var instance = serviceProvider.GetService(context.InvocatorContext.Invocator);
                if (instance != null && instance is IClientWebSocketCommandInvocator)
                {
                    return((IClientWebSocketCommandInvocator)instance);
                }
            }

            return(null);
        }
Exemple #4
0
 internal void Close(ClientWebSocketReceiverContext context)
 {
     context.WebSocket.Abort();
 }