public static RegisteredLocalDataChanged create(JObject jObject) { JProperty handshakeProperty = jObject.Property("handshake"); JProperty valuesProperty = jObject.Property("values"); if (handshakeProperty == null) { return(null); } if (valuesProperty == null) { return(null); } JToken keyProperty = valuesProperty.Value["key"]; JToken valueProperty = valuesProperty.Value["value"]; JToken simIdProperty = valuesProperty.Value["simId"]; // Check all properties are present and valid if (keyProperty == null && keyProperty.Type == JTokenType.String) { return(null); } if (valueProperty == null && valueProperty.Type == JTokenType.String) { return(null); } if (simIdProperty == null && simIdProperty.Type == JTokenType.String) { return(null); } RegisteredLocalDataChanged registeredLocalDataChanged = new RegisteredLocalDataChanged(); registeredLocalDataChanged.handshake = handshakeProperty.Value.ToObject <SimCapiHandshake>(); registeredLocalDataChanged.key = keyProperty.ToObject <string>(); registeredLocalDataChanged.value = valueProperty.ToObject <string>(); registeredLocalDataChanged.simId = simIdProperty.ToObject <string>(); return(registeredLocalDataChanged); }
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"); }