Beispiel #1
0
        /// <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 DeployedServiceReplicaInfo GetFromJsonProperties(JsonReader reader)
        {
            DeployedServiceReplicaInfo obj;
            var propName = reader.ReadPropertyName();

            if (!propName.Equals("ServiceKind", StringComparison.Ordinal))
            {
                throw new JsonReaderException($"Incorrect discriminator property name {propName}, Expected discriminator property name is ServiceKind.");
            }

            var propValue = reader.ReadValueAsString();

            if (propValue.Equals("Stateful", StringComparison.Ordinal))
            {
                obj = DeployedStatefulServiceReplicaInfoConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("Stateless", StringComparison.Ordinal))
            {
                obj = DeployedStatelessServiceInstanceInfoConverter.GetFromJsonProperties(reader);
            }
            else
            {
                throw new InvalidOperationException("Unknown ServiceKind.");
            }

            return(obj);
        }
Beispiel #2
0
        /// <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 DeployedStatelessServiceInstanceDetailInfo 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 instanceId = default(ReplicaId);
            var deployedServiceReplicaQueryResult = default(DeployedStatelessServiceInstanceInfo);

            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("InstanceId", propName, StringComparison.Ordinal) == 0)
                {
                    instanceId = ReplicaIdConverter.Deserialize(reader);
                }
                else if (string.Compare("DeployedServiceReplicaQueryResult", propName, StringComparison.Ordinal) == 0)
                {
                    deployedServiceReplicaQueryResult = DeployedStatelessServiceInstanceInfoConverter.Deserialize(reader);
                }
                else
                {
                    reader.SkipPropertyValue();
                }
            }while (reader.TokenType != JsonToken.EndObject);

            return(new DeployedStatelessServiceInstanceDetailInfo(
                       serviceName: serviceName,
                       partitionId: partitionId,
                       currentServiceOperation: currentServiceOperation,
                       currentServiceOperationStartTimeUtc: currentServiceOperationStartTimeUtc,
                       reportedLoad: reportedLoad,
                       instanceId: instanceId,
                       deployedServiceReplicaQueryResult: deployedServiceReplicaQueryResult));
        }
Beispiel #3
0
        /// <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, DeployedServiceReplicaInfo obj)
        {
            var kind = obj.ServiceKind;

            if (kind.Equals(ServiceKind.Stateful))
            {
                DeployedStatefulServiceReplicaInfoConverter.Serialize(writer, (DeployedStatefulServiceReplicaInfo)obj);
            }
            else if (kind.Equals(ServiceKind.Stateless))
            {
                DeployedStatelessServiceInstanceInfoConverter.Serialize(writer, (DeployedStatelessServiceInstanceInfo)obj);
            }
            else
            {
                throw new InvalidOperationException("Unknown ServiceKind.");
            }
        }