Пример #1
0
        private void AddFurtherMessageFields(IncommingMessage message, JObject messageAsJsonObject)
        {
            JToken data = messageAsJsonObject["data"];

            switch (message.Type)
            {
            case MessageType.DEAL_CARDS:
                message.Cards = GetCardsFromMessage(data);
                break;

            case MessageType.REQUEST_TRUMPF:
                message.SchiebenAllowed = GetIsSchiebenAllowed(data);
                break;

            case MessageType.BROADCAST_TRUMPF:
                message.Trumpf = GetTrumpf(data);
                break;

            case MessageType.REQUEST_CARD:
                message.CardsOnTable = GetCardsFromMessageAsList(data);
                break;

            case MessageType.BROADCAST_STICH:
                message.Stich = GetStichFromMessage(data);
                break;
            }
        }
Пример #2
0
        public IncommingMessage Read(string messageFromServer)
        {
            JObject messageAsJsonObject = JObject.Parse(messageFromServer);

            JToken typePrimitive = messageAsJsonObject["type"];

            if (typePrimitive == null)
            {
                throw new IllegalMessageException("Field \"type\" is missing.", messageFromServer);
            }
            var         type = typePrimitive.Value <string>();
            MessageType messageType;

            if (!Enum.TryParse(type, out messageType))
            {
                throw new ArgumentException("Can't parse type " + type);
            }
            IncommingMessage message = new IncommingMessage(messageType);

            AddFurtherMessageFields(message, messageAsJsonObject);
            return(message);
        }