Exemple #1
0
        private void OnServerHandshakeFrame(object source, HandshakeFrameReceivedEventArgs e)
        {
            if (_state != ClientState.ServerToClientHandshake)
            {
                throw new Exception("Server handshake should not be received during " + _state);
            }
            var frame = _extensionService.ClientConfirmExtensions(e.Handshake, _connection.Identity);

            _state = ClientState.Ready;
            _connection.SetHandshakeCompleted();
            _connection.Send(frame);

            //TODO: This is a mess. Create a better way
            // to identify and activate extensions.
            // maybe by defining extension behavior like IInboundMessageProcessor.

            var id = _extensionService.FindFirstExtensionId("json", "xml", "protobuf");

            if (id > 0)
            {
                _payloadSerializer = (((IPayloadExtension)_extensionService.Get(id))).CreatePayloadSerializer();
            }

            id = _extensionService.FindFirstExtensionId("dotnet");
            if (id > 0)
            {
                _dotNetExtension = (DotNetTypeExtension)_extensionService.Get(id);
            }

            _ackExtensionId = _extensionService.FindFirstExtensionId("batch-ack", "ack");
            if (_ackExtensionId != 0)
            {
                var name          = _extensionService.FindFirstExtensionNamed("batch-ack", "ack");
                var extProperties = frame.GetExtension(name);
                var ackExtension  = (IAckExtension)_extensionService.Get(_ackExtensionId);
                _ackReceiver = ackExtension.CreateAckReceiver(_connection, _ackExtensionId, DeliverMessage,
                                                              extProperties);
                _ackSender = ackExtension.CreateAckSender(_connection, _ackExtensionId, extProperties);
            }


            _authenticationEvent.Set();
        }
        private void OnServerHandshakeFrame(object source, HandshakeFrameReceivedEventArgs e)
        {
            if (_state != ClientState.ServerToClientHandshake)
            {
                throw new Exception("Server handshake should not be received during " + _state);
            }
            var frame = _extensionService.ClientConfirmExtensions(e.Handshake, _connection.Identity);

            _state = ClientState.Ready;
            _connection.SetHandshakeCompleted();
            _connection.Send(frame);


            var name = _extensionService.FindFirstExtensionNamed("json", "xml", "protobuf");

            switch (name)
            {
            case "json":
                _payloadSerializer = new FastJsonSerializer();
                break;
            }

            _ackExtensionId = _extensionService.FindFirstExtensionId("batch-ack", "ack");
            if (_ackExtensionId != 0)
            {
                name = _extensionService.FindFirstExtensionNamed("batch-ack", "ack");
                var extProperties = frame.GetExtension(name);
                var ackExtension  = (IAckExtension)_extensionService.Get(_ackExtensionId);
                _ackReceiver = ackExtension.CreateAckReceiver(_connection, _ackExtensionId, DeliverMessage,
                                                              extProperties);
                _ackSender = ackExtension.CreateAckSender(_connection, _ackExtensionId, extProperties);
            }


            _authenticationEvent.Set();
        }