/// <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, PartitionHealth obj) { // Required properties are always serialized, optional properties are serialized when not null. writer.WriteStartObject(); writer.WriteProperty(obj.AggregatedHealthState, "AggregatedHealthState", HealthStateConverter.Serialize); if (obj.HealthEvents != null) { writer.WriteEnumerableProperty(obj.HealthEvents, "HealthEvents", HealthEventConverter.Serialize); } if (obj.UnhealthyEvaluations != null) { writer.WriteEnumerableProperty(obj.UnhealthyEvaluations, "UnhealthyEvaluations", HealthEvaluationWrapperConverter.Serialize); } if (obj.HealthStatistics != null) { writer.WriteProperty(obj.HealthStatistics, "HealthStatistics", HealthStatisticsConverter.Serialize); } if (obj.PartitionId != null) { writer.WriteProperty(obj.PartitionId, "PartitionId", PartitionIdConverter.Serialize); } if (obj.ReplicaHealthStates != null) { writer.WriteEnumerableProperty(obj.ReplicaHealthStates, "ReplicaHealthStates", ReplicaHealthStateConverter.Serialize); } writer.WriteEndObject(); }
/// <summary> /// Overloaded ToString function for formatting the output on the console. /// </summary> /// <param name="partitionHealth"> Object of type PartitionHealth </param> /// <returns> /// Returns formatted string. /// </returns> public static string ToString(PartitionHealth partitionHealth) { var strBuilder = new StringBuilder(); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "PartitionId", partitionHealth.PartitionId)); strBuilder.Append(Environment.NewLine); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "AggregatedHealthState", partitionHealth.AggregatedHealthState)); strBuilder.Append(Environment.NewLine); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "HealthEvents", OutputFormatter.ToString(partitionHealth.HealthEvents.ToList()))); strBuilder.Append(Environment.NewLine); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "HealthStatistics", OutputFormatter.ToString(partitionHealth.HealthStatistics))); strBuilder.Append(Environment.NewLine); return(strBuilder.ToString()); }
public void PartitionHealthSerializationTest() { PartitionHealth partitionHealth = this.random.CreateRandom <PartitionHealth>(); var replicaHealthState = new StatefulServiceReplicaHealthState() { AggregatedHealthState = this.random.CreateRandom <HealthState>(), PartitionId = partitionHealth.PartitionId, Id = this.random.Next() }; partitionHealth.ReplicaHealthStates = new List <ReplicaHealthState>(); partitionHealth.ReplicaHealthStates.Add(replicaHealthState); TestUsingSerializer(this.Serializer, partitionHealth); }