Ejemplo n.º 1
0
        internal static JobLimits DeserializeJobLimits(JsonElement element)
        {
            if (element.TryGetProperty("jobLimitsType", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "Sweep": return(SweepJobLimits.DeserializeSweepJobLimits(element));

                case "Command": return(CommandJobLimits.DeserializeCommandJobLimits(element));
                }
            }
            JobLimitsType        jobLimitsType = default;
            Optional <TimeSpan?> timeout       = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("jobLimitsType"))
                {
                    jobLimitsType = new JobLimitsType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("timeout"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        timeout = null;
                        continue;
                    }
                    timeout = property.Value.GetTimeSpan("P");
                    continue;
                }
            }
            return(new JobLimits(jobLimitsType, Optional.ToNullable(timeout)));
        }
Ejemplo n.º 2
0
 internal SweepJobLimits(JobLimitsType jobLimitsType, TimeSpan?timeout, int?maxConcurrentTrials, int?maxTotalTrials, TimeSpan?trialTimeout) : base(jobLimitsType, timeout)
 {
     MaxConcurrentTrials = maxConcurrentTrials;
     MaxTotalTrials      = maxTotalTrials;
     TrialTimeout        = trialTimeout;
     JobLimitsType       = jobLimitsType;
 }
Ejemplo n.º 3
0
        internal static CommandJobLimits DeserializeCommandJobLimits(JsonElement element)
        {
            JobLimitsType        jobLimitsType = default;
            Optional <TimeSpan?> timeout       = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("jobLimitsType"))
                {
                    jobLimitsType = new JobLimitsType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("timeout"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        timeout = null;
                        continue;
                    }
                    timeout = property.Value.GetTimeSpan("P");
                    continue;
                }
            }
            return(new CommandJobLimits(jobLimitsType, Optional.ToNullable(timeout)));
        }
Ejemplo n.º 4
0
        internal static SweepJobLimits DeserializeSweepJobLimits(JsonElement element)
        {
            Optional <int?>      maxConcurrentTrials = default;
            Optional <int?>      maxTotalTrials      = default;
            Optional <TimeSpan?> trialTimeout        = default;
            JobLimitsType        jobLimitsType       = default;
            Optional <TimeSpan?> timeout             = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("maxConcurrentTrials"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        maxConcurrentTrials = null;
                        continue;
                    }
                    maxConcurrentTrials = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("maxTotalTrials"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        maxTotalTrials = null;
                        continue;
                    }
                    maxTotalTrials = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("trialTimeout"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        trialTimeout = null;
                        continue;
                    }
                    trialTimeout = property.Value.GetTimeSpan("P");
                    continue;
                }
                if (property.NameEquals("jobLimitsType"))
                {
                    jobLimitsType = new JobLimitsType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("timeout"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        timeout = null;
                        continue;
                    }
                    timeout = property.Value.GetTimeSpan("P");
                    continue;
                }
            }
            return(new SweepJobLimits(jobLimitsType, Optional.ToNullable(timeout), Optional.ToNullable(maxConcurrentTrials), Optional.ToNullable(maxTotalTrials), Optional.ToNullable(trialTimeout)));
        }
Ejemplo n.º 5
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     if (Optional.IsDefined(MaxConcurrentTrials))
     {
         if (MaxConcurrentTrials != null)
         {
             writer.WritePropertyName("maxConcurrentTrials");
             writer.WriteNumberValue(MaxConcurrentTrials.Value);
         }
         else
         {
             writer.WriteNull("maxConcurrentTrials");
         }
     }
     if (Optional.IsDefined(MaxTotalTrials))
     {
         if (MaxTotalTrials != null)
         {
             writer.WritePropertyName("maxTotalTrials");
             writer.WriteNumberValue(MaxTotalTrials.Value);
         }
         else
         {
             writer.WriteNull("maxTotalTrials");
         }
     }
     if (Optional.IsDefined(TrialTimeout))
     {
         if (TrialTimeout != null)
         {
             writer.WritePropertyName("trialTimeout");
             writer.WriteStringValue(TrialTimeout.Value, "P");
         }
         else
         {
             writer.WriteNull("trialTimeout");
         }
     }
     writer.WritePropertyName("jobLimitsType");
     writer.WriteStringValue(JobLimitsType.ToString());
     if (Optional.IsDefined(Timeout))
     {
         if (Timeout != null)
         {
             writer.WritePropertyName("timeout");
             writer.WriteStringValue(Timeout.Value, "P");
         }
         else
         {
             writer.WriteNull("timeout");
         }
     }
     writer.WriteEndObject();
 }
Ejemplo n.º 6
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("jobLimitsType");
     writer.WriteStringValue(JobLimitsType.ToString());
     if (Optional.IsDefined(Timeout))
     {
         if (Timeout != null)
         {
             writer.WritePropertyName("timeout");
             writer.WriteStringValue(Timeout.Value, "P");
         }
         else
         {
             writer.WriteNull("timeout");
         }
     }
     writer.WriteEndObject();
 }
Ejemplo n.º 7
0
 internal CommandJobLimits(JobLimitsType jobLimitsType, TimeSpan?timeout) : base(jobLimitsType, timeout)
 {
     JobLimitsType = jobLimitsType;
 }
Ejemplo n.º 8
0
 internal JobLimits(JobLimitsType jobLimitsType, TimeSpan?timeout)
 {
     JobLimitsType = jobLimitsType;
     Timeout       = timeout;
 }