/// <summary> /// Serializes the object to JSON. /// </summary> /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param> /// <param name="obj">The object to serialize to JSON.</param> internal static void Serialize(JsonWriter writer, ReplicaStatusBase obj) { var kind = obj.Kind; if (kind.Equals(ReplicaKind.KeyValueStore)) { KeyValueStoreReplicaStatusConverter.Serialize(writer, (KeyValueStoreReplicaStatus)obj); } else { throw new InvalidOperationException("Unknown Kind."); } }
/// <summary> /// Gets the object from Json properties. /// </summary> /// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from.</param> /// <returns>The object Value.</returns> internal static ReplicaStatusBase GetFromJsonProperties(JsonReader reader) { ReplicaStatusBase obj = null; var propName = reader.ReadPropertyName(); if (!propName.Equals("Kind", StringComparison.Ordinal)) { throw new JsonReaderException($"Incorrect discriminator property name {propName}, Expected discriminator property name is Kind."); } var propValue = reader.ReadValueAsString(); if (propValue.Equals("KeyValueStore", StringComparison.Ordinal)) { obj = KeyValueStoreReplicaStatusConverter.GetFromJsonProperties(reader); } else { throw new InvalidOperationException("Unknown Kind."); } return(obj); }
/// <summary> /// Gets the object from Json properties. /// </summary> /// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from, reader must be placed at first property.</param> /// <returns>The object Value.</returns> internal static DeployedStatefulServiceReplicaDetailInfo GetFromJsonProperties(JsonReader reader) { var serviceName = default(ServiceName); var partitionId = default(PartitionId); var currentServiceOperation = default(ServiceOperationName?); var currentServiceOperationStartTimeUtc = default(DateTime?); var reportedLoad = default(IEnumerable <LoadMetricReportInfo>); var replicaId = default(ReplicaId); var currentReplicatorOperation = default(ReplicatorOperationName?); var readStatus = default(PartitionAccessStatus?); var writeStatus = default(PartitionAccessStatus?); var replicatorStatus = default(ReplicatorStatus); var replicaStatus = default(KeyValueStoreReplicaStatus); var deployedServiceReplicaQueryResult = default(DeployedStatefulServiceReplicaInfo); do { var propName = reader.ReadPropertyName(); if (string.Compare("ServiceName", propName, StringComparison.Ordinal) == 0) { serviceName = ServiceNameConverter.Deserialize(reader); } else if (string.Compare("PartitionId", propName, StringComparison.Ordinal) == 0) { partitionId = PartitionIdConverter.Deserialize(reader); } else if (string.Compare("CurrentServiceOperation", propName, StringComparison.Ordinal) == 0) { currentServiceOperation = ServiceOperationNameConverter.Deserialize(reader); } else if (string.Compare("CurrentServiceOperationStartTimeUtc", propName, StringComparison.Ordinal) == 0) { currentServiceOperationStartTimeUtc = reader.ReadValueAsDateTime(); } else if (string.Compare("ReportedLoad", propName, StringComparison.Ordinal) == 0) { reportedLoad = reader.ReadList(LoadMetricReportInfoConverter.Deserialize); } else if (string.Compare("ReplicaId", propName, StringComparison.Ordinal) == 0) { replicaId = ReplicaIdConverter.Deserialize(reader); } else if (string.Compare("CurrentReplicatorOperation", propName, StringComparison.Ordinal) == 0) { currentReplicatorOperation = ReplicatorOperationNameConverter.Deserialize(reader); } else if (string.Compare("ReadStatus", propName, StringComparison.Ordinal) == 0) { readStatus = PartitionAccessStatusConverter.Deserialize(reader); } else if (string.Compare("WriteStatus", propName, StringComparison.Ordinal) == 0) { writeStatus = PartitionAccessStatusConverter.Deserialize(reader); } else if (string.Compare("ReplicatorStatus", propName, StringComparison.Ordinal) == 0) { replicatorStatus = ReplicatorStatusConverter.Deserialize(reader); } else if (string.Compare("ReplicaStatus", propName, StringComparison.Ordinal) == 0) { replicaStatus = KeyValueStoreReplicaStatusConverter.Deserialize(reader); } else if (string.Compare("DeployedServiceReplicaQueryResult", propName, StringComparison.Ordinal) == 0) { deployedServiceReplicaQueryResult = DeployedStatefulServiceReplicaInfoConverter.Deserialize(reader); } else { reader.SkipPropertyValue(); } }while (reader.TokenType != JsonToken.EndObject); return(new DeployedStatefulServiceReplicaDetailInfo( serviceName: serviceName, partitionId: partitionId, currentServiceOperation: currentServiceOperation, currentServiceOperationStartTimeUtc: currentServiceOperationStartTimeUtc, reportedLoad: reportedLoad, replicaId: replicaId, currentReplicatorOperation: currentReplicatorOperation, readStatus: readStatus, writeStatus: writeStatus, replicatorStatus: replicatorStatus, replicaStatus: replicaStatus, deployedServiceReplicaQueryResult: deployedServiceReplicaQueryResult)); }