/// <summary> /// Read the JSON object and convert to the object. This will allow the serializer to /// automatically convert the object. No special instructions need to be done and all /// the properties found in the JSON string need to be used. /// /// DataSet.ProfileEngineeringDataSet decodedEns = Newtonsoft.Json.JsonConvert.DeserializeObject{DataSet.ProfileEngineeringDataSet}(encodedEns) /// /// </summary> /// <param name="reader">NOT USED. JSON reader.</param> /// <param name="objectType">NOT USED> Type of object.</param> /// <param name="existingValue">NOT USED.</param> /// <param name="serializer">Serialize the object.</param> /// <returns>Serialized object.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.Null) { // Load the object JObject jsonObject = JObject.Load(reader); // Decode the data int NumElements = (int)jsonObject[DataSet.BaseDataSet.JSON_STR_NUMELEMENTS]; int ElementsMultiplier = (int)jsonObject[DataSet.BaseDataSet.JSON_STR_ELEMENTSMULTIPLIER]; // Create the object var data = new ProfileEngineeringDataSet(DataSet.Ensemble.DATATYPE_FLOAT, NumElements, ElementsMultiplier, DataSet.Ensemble.DEFAULT_IMAG, DataSet.Ensemble.DEFAULT_NAME_LENGTH, DataSet.Ensemble.ProfileEngineeringID); // PrePingVel JArray jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGVEL]; data.PrePingVel = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.PrePingVel[x] = (float)jArray[x]; } // PrePingCor jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGCOR]; data.PrePingCor = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.PrePingCor[x] = (float)jArray[x]; } // PrePingAmp jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGAMP]; data.PrePingAmp = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.PrePingAmp[x] = (float)jArray[x]; } // SamplesPerSecond data.SamplesPerSecond = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_SAMPLESPERSECOND]; // SystemFreqHz data.SystemFreqHz = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_SYSTEMFREQHZ]; // LagSamples data.LagSamples = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_LAGSAMPLES]; // CPCE data.CPCE = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_CPCE]; // NCE data.NCE = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_NCE]; // RepeatN data.RepeatN = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_REPEATN]; // PrePingGap data.PrePingGap = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGGAP]; // PrePingNCE data.PrePingNCE = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGNCE]; // PrePingRepeatN data.PrePingRepeatN = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGREPEATN]; // PrePingLagSamples data.PrePingLagSamples = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGLAGSAMPLES]; // TRHighGain data.TRHighGain = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGTRHIGHGAIN]; return(data); } return(null); }
/// <summary> /// Read the JSON object and convert to the object. This will allow the serializer to /// automatically convert the object. No special instructions need to be done and all /// the properties found in the JSON string need to be used. /// /// DataSet.ProfileEngineeringDataSet decodedEns = Newtonsoft.Json.JsonConvert.DeserializeObject{DataSet.ProfileEngineeringDataSet}(encodedEns) /// /// </summary> /// <param name="reader">NOT USED. JSON reader.</param> /// <param name="objectType">NOT USED> Type of object.</param> /// <param name="existingValue">NOT USED.</param> /// <param name="serializer">Serialize the object.</param> /// <returns>Serialized object.</returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType != JsonToken.Null) { // Load the object JObject jsonObject = JObject.Load(reader); // Decode the data int NumElements = (int)jsonObject[DataSet.BaseDataSet.JSON_STR_NUMELEMENTS]; int ElementsMultiplier = (int)jsonObject[DataSet.BaseDataSet.JSON_STR_ELEMENTSMULTIPLIER]; // Create the object var data = new ProfileEngineeringDataSet(DataSet.Ensemble.DATATYPE_FLOAT, NumElements, ElementsMultiplier, DataSet.Ensemble.DEFAULT_IMAG, DataSet.Ensemble.DEFAULT_NAME_LENGTH, DataSet.Ensemble.ProfileEngineeringID); // PrePingVel JArray jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGVEL]; data.PrePingVel = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.PrePingVel[x] = (float)jArray[x]; } // PrePingCor jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGCOR]; data.PrePingCor = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.PrePingCor[x] = (float)jArray[x]; } // PrePingAmp jArray = (JArray)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGAMP]; data.PrePingAmp = new float[jArray.Count]; for (int x = 0; x < jArray.Count; x++) { // Add all the values to the array data.PrePingAmp[x] = (float)jArray[x]; } // SamplesPerSecond data.SamplesPerSecond = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_SAMPLESPERSECOND]; // SystemFreqHz data.SystemFreqHz = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_SYSTEMFREQHZ]; // LagSamples data.LagSamples = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_LAGSAMPLES]; // CPCE data.CPCE = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_CPCE]; // NCE data.NCE = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_NCE]; // RepeatN data.RepeatN = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_REPEATN]; // PrePingGap data.PrePingGap = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGGAP]; // PrePingNCE data.PrePingNCE = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGNCE]; // PrePingRepeatN data.PrePingRepeatN = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGREPEATN]; // PrePingLagSamples data.PrePingLagSamples = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGLAGSAMPLES]; // TRHighGain data.TRHighGain = (float)jsonObject[DataSet.BaseDataSet.JSON_STR_PE_PREPINGTRHIGHGAIN]; return data; } return null; }