예제 #1
0
        public static System.Object deserialize(string jsonString, ref SimCapiMessageType messageType)
        {
            JObject jObject;

            try
            {
                jObject = JsonConvert.DeserializeObject <JObject>(jsonString);
            }
            catch (System.Exception)
            {
                return(null);
            }

            JProperty type = jObject.Property("type");

            if (type == null)
            {
                throw new System.Exception("Invalid message structure");
            }

            JToken typeValue = jObject["type"];

            if (typeValue.Type != JTokenType.Integer)
            {
                throw new System.Exception("type property should be an Integer");
            }


            messageType = typeValue.ToObject <SimCapiMessageType>();



            switch (messageType)
            {
            case SimCapiMessageType.HANDSHAKE_RESPONSE:
                return(HandshakeResponse.create(jObject));

            case SimCapiMessageType.VALUE_CHANGE:
                return(ValueChange.create(jObject));

            case SimCapiMessageType.CONFIG_CHANGE:
                return(ConfigChange.create(jObject));

            case SimCapiMessageType.VALUE_CHANGE_REQUEST:
                return(ValueChangeRequest.create(jObject));

            case SimCapiMessageType.CHECK_COMPLETE_RESPONSE:
                return(CheckCompleteResponse.create(jObject));

            case SimCapiMessageType.CHECK_START_RESPONSE:
                return(CheckStartResponse.create(jObject));

            case SimCapiMessageType.GET_DATA_RESPONSE:
                return(GetDataResponse.create(jObject));

            case SimCapiMessageType.SET_DATA_RESPONSE:
                return(SetDataResponse.create(jObject));

            case SimCapiMessageType.API_CALL_RESPONSE:
                return(null);

            case SimCapiMessageType.INITIAL_SETUP_COMPLETE:
                return(InitialSetupComplete.create(jObject));

            case SimCapiMessageType.RESIZE_PARENT_CONTAINER_RESPONSE:
                return(ResizeParentContainerResponse.create(jObject));

            case SimCapiMessageType.ALLOW_INTERNAL_ACCESS:
                return(AllowInternalAccess.create(jObject));

            case SimCapiMessageType.REGISTERED_LOCAL_DATA_CHANGED:
                return(RegisteredLocalDataChanged.create(jObject));
            }

            throw new System.Exception("Invalid message type");
        }