using System; using System.Collections.Generic; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; namespace Adaptation.Shared.Metrology; public partial class WS { public class Results { #nullable enable [JsonConstructor] public Results(List? errors, long? headerId, long? subgroupId, bool? success, List? warnings) { Errors = errors; Success = success; HeaderId = headerId; Warnings = warnings; SubgroupId = subgroupId; } [JsonPropertyName("errors")] public List? Errors { get; set; } [JsonPropertyName("headerID")] public long? HeaderId { get; set; } [JsonPropertyName("subgroupId")] public long? SubgroupId { get; set; } [JsonPropertyName("success")] public bool? Success { get; set; } [JsonPropertyName("warnings")] public List? Warnings { get; set; } public override string ToString() { string result = JsonSerializer.Serialize(this, ResultsSourceGenerationContext.Default.Results); return result; } internal static Results Get(Results results, long? subgroupId) => new(results.Errors, results.HeaderId, subgroupId, results.Success, results.Warnings); internal static Results Get(string resultsJson, Exception e) { Results results; Exception? exception = e; List errors = new(); StringBuilder stringBuilder = new(); while (exception is not null) { _ = stringBuilder.AppendLine(exception.Message); exception = exception.InnerException; } errors.Add(resultsJson); errors.Add(stringBuilder.ToString()); results = new(errors: errors, headerId: null, subgroupId: null, success: false, warnings: new()); return results; } } } [JsonSourceGenerationOptions(WriteIndented = true)] [JsonSerializable(typeof(WS.Results))] internal partial class ResultsSourceGenerationContext : JsonSerializerContext { }