public static void DeleteCertMonitor(CertificateOperations certOps, ITestOutputHelper testOutputHelper, string thumbAlgo, string thumb) { bool found; testOutputHelper.WriteLine("polling for deletion of thumbprint: " + thumb); do { found = false; foreach (Certificate curCert in certOps.ListCertificates()) { if (thumbAlgo.Equals(curCert.ThumbprintAlgorithm, StringComparison.InvariantCultureIgnoreCase) && thumb.Equals(curCert.Thumbprint, StringComparison.InvariantCultureIgnoreCase)) { testOutputHelper.WriteLine("DeleteCertMonitor: thumb " + curCert.Thumbprint + ", state: " + curCert.State); found = true; break; } } if (found) { System.Threading.Thread.Sleep(5000); } }while (found); }
/// <summary> /// Lists the certificates matching the specified filter options. /// </summary> /// <param name="options">The options to use when querying for certificates.</param> /// <returns>The certificates matching the specified filter options.</returns> public IEnumerable <PSCertificate> ListCertificates(ListCertificateOptions options) { if (options == null) { throw new ArgumentNullException("options"); } // Get the single certificate matching the specified thumbprint if (!string.IsNullOrWhiteSpace(options.Thumbprint)) { WriteVerbose(string.Format(Resources.GetCertificateByThumbprint, options.Thumbprint)); CertificateOperations certOperations = options.Context.BatchOMClient.CertificateOperations; ODATADetailLevel getDetailLevel = new ODATADetailLevel(selectClause: options.Select); Certificate certificate = certOperations.GetCertificate(options.ThumbprintAlgorithm, options.Thumbprint, detailLevel: getDetailLevel, additionalBehaviors: options.AdditionalBehaviors); PSCertificate psCertificate = new PSCertificate(certificate); return(new PSCertificate[] { psCertificate }); } // List certificates using the specified filter else { string verboseLogString = null; ODATADetailLevel listDetailLevel = new ODATADetailLevel(selectClause: options.Select); if (!string.IsNullOrEmpty(options.Filter)) { verboseLogString = Resources.GetCertificatesByFilter; listDetailLevel.FilterClause = options.Filter; } else { verboseLogString = Resources.GetCertificatesNoFilter; } WriteVerbose(verboseLogString); CertificateOperations certOperations = options.Context.BatchOMClient.CertificateOperations; IPagedEnumerable <Certificate> certificates = certOperations.ListCertificates(listDetailLevel, options.AdditionalBehaviors); Func <Certificate, PSCertificate> mappingFunction = c => { return(new PSCertificate(c)); }; return(PSPagedEnumerable <PSCertificate, Certificate> .CreateWithMaxCount( certificates, mappingFunction, options.MaxCount, () => WriteVerbose(string.Format(Resources.MaxCount, options.MaxCount)))); } }