/// <summary>
 /// Called upon successfully establishing a connection (with accepted login) towards the GDS.
 /// </summary>
 /// <param name="header">The received header</param>
 /// <param name="data">The received login data</param>
 public virtual void OnConnectionSuccess(MessageHeader header, ConnectionAckData data)
 {
 }
Esempio n. 2
0
        private void OnMessageReceived(object sender, DataReceivedEventArgs eventArgs)
        {
            LogInfo("WebSocket client received message");
            try
            {
                byte[]        binary  = eventArgs.Data;
                Message       message = MessageManager.GetMessageFromBinary(binary);
                MessageHeader header  = message.Header;
                MessageData   data    = message.Data;

                switch (message.Data.GetDataType())
                {
                case DataType.ConnectionAck:
                {
                    countdown.Signal();
                    ConnectionAckData ackData = data.AsConnectionAckData();
                    if (ackData.Status != StatusCode.OK)
                    {
                        int oldState = Interlocked.CompareExchange(ref state, ConnectionState.FAILED, ConnectionState.LOGGING_IN);
                        if (oldState != ConnectionState.LOGGING_IN)
                        {
                            int currentState = State;
                            if (currentState != ConnectionState.DISCONNECTED)
                            {
                                throw new InvalidOperationException(string.Format("Expected state LOGGING_IN but got {0}", ConnectionState.AsText(currentState)));
                            }
                            else
                            {
                                return;
                            }
                        }
                        Close();
                        listener.OnConnectionFailure(new KeyValuePair <MessageHeader, ConnectionAckData>(header, ackData));
                    }
                    else
                    {
                        int oldState = Interlocked.CompareExchange(ref state, ConnectionState.LOGGED_IN, ConnectionState.LOGGING_IN);
                        if (oldState != ConnectionState.LOGGING_IN)
                        {
                            int currentState = State;
                            if (currentState != ConnectionState.DISCONNECTED)
                            {
                                throw new InvalidOperationException(string.Format("Expected state LOGGING_IN but got {0}", ConnectionState.AsText(currentState)));
                            }
                            else
                            {
                                return;
                            }
                        }
                        listener.OnConnectionSuccess(header, ackData);
                    }
                }
                break;

                case DataType.EventAck:
                    listener.OnEventAck3(header, data.AsEventAckData());
                    break;

                case DataType.AttachmentRequest:
                    listener.OnAttachmentRequest4(header, data.AsAttachmentRequestData());
                    break;

                case DataType.AttachmentRequestAck:
                    listener.OnAttachmentRequestAck5(header, data.AsAttachmentRequestAckData());
                    break;

                case DataType.AttachmentResponse:
                    listener.OnAttachmentResponse6(header, data.AsAttachmentResponseData());
                    break;

                case DataType.AttachmentResponseAck:
                    listener.OnAttachmentResponseAck7(header, data.AsAttachmentResponseAckData());
                    break;

                case DataType.EventDocument:
                    listener.OnEventDocument8(header, data.AsEventDocumentData());
                    break;

                case DataType.EventDocumentAck:
                    listener.OnEventDocumentAck9(header, data.AsEventDocumentAckData());
                    break;

                case DataType.QueryRequestAck:
                    listener.OnQueryRequestAck11(header, data.AsQueryRequestAck());
                    break;

                default:
                    LogWarn(string.Format("Unexpected type of message received: {0}", message.Data.GetDataType()));
                    break;
                }
            }
            catch (MessagePackSerializationException e)
            {
                LogError(string.Format("The format of the received binary message is invalid! {0}", e.ToString()));
            }
        }