Ejemplo n.º 1
0
 internal Certificate(string thumbprint, string thumbprintAlgorithm, string url, CertificateState?state, DateTimeOffset?stateTransitionTime, CertificateState?previousState, DateTimeOffset?previousStateTransitionTime, string publicData, DeleteCertificateError deleteCertificateError)
 {
     Thumbprint          = thumbprint;
     ThumbprintAlgorithm = thumbprintAlgorithm;
     Url   = url;
     State = state;
     StateTransitionTime         = stateTransitionTime;
     PreviousState               = previousState;
     PreviousStateTransitionTime = previousStateTransitionTime;
     PublicData             = publicData;
     DeleteCertificateError = deleteCertificateError;
 }
        internal static Certificate DeserializeCertificate(JsonElement element)
        {
            string                 thumbprint          = default;
            string                 thumbprintAlgorithm = default;
            string                 url   = default;
            CertificateState?      state = default;
            DateTimeOffset?        stateTransitionTime         = default;
            CertificateState?      previousState               = default;
            DateTimeOffset?        previousStateTransitionTime = default;
            string                 publicData             = default;
            DeleteCertificateError deleteCertificateError = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("thumbprint"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    thumbprint = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("thumbprintAlgorithm"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    thumbprintAlgorithm = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("url"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    url = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("state"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    state = property.Value.GetString().ToCertificateState();
                    continue;
                }
                if (property.NameEquals("stateTransitionTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    stateTransitionTime = property.Value.GetDateTimeOffset("S");
                    continue;
                }
                if (property.NameEquals("previousState"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    previousState = property.Value.GetString().ToCertificateState();
                    continue;
                }
                if (property.NameEquals("previousStateTransitionTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    previousStateTransitionTime = property.Value.GetDateTimeOffset("S");
                    continue;
                }
                if (property.NameEquals("publicData"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    publicData = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("deleteCertificateError"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    deleteCertificateError = DeleteCertificateError.DeserializeDeleteCertificateError(property.Value);
                    continue;
                }
            }
            return(new Certificate(thumbprint, thumbprintAlgorithm, url, state, stateTransitionTime, previousState, previousStateTransitionTime, publicData, deleteCertificateError));
        }