Microsoft.Azure.Commands.Batch.Models.BatchClient.ListCertificates C# (CSharp) Method

ListCertificates() public method

Lists the certificates matching the specified filter options.
public ListCertificates ( Microsoft.Azure.Commands.Batch.Models.ListCertificateOptions options ) : IEnumerable
options Microsoft.Azure.Commands.Batch.Models.ListCertificateOptions The options to use when querying for certificates.
return IEnumerable
        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)));
            }
        }

Usage Example

        /// <summary>
        /// Deletes a certificate.
        /// </summary>
        public static void WaitForCertificateToFailDeletion(BatchController controller, BatchAccountContext context, string thumbprintAlgorithm, string thumbprint)
        {
            RequestInterceptor interceptor = CreateHttpRecordingInterceptor();

            BatchClientBehavior[] behaviors = new BatchClientBehavior[] { interceptor };
            BatchClient           client    = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient);

            ListCertificateOptions parameters = new ListCertificateOptions(context, behaviors)
            {
                ThumbprintAlgorithm = BatchTestHelpers.TestCertificateAlgorithm,
                Thumbprint          = thumbprint
            };

            PSCertificate cert = client.ListCertificates(parameters).First();

            DateTime timeout = DateTime.Now.AddMinutes(2);

            while (cert.State != CertificateState.DeleteFailed)
            {
                if (DateTime.Now > timeout)
                {
                    throw new TimeoutException("Timed out waiting for failed certificate deletion");
                }
                Sleep(10000);
                cert = client.ListCertificates(parameters).First();
            }
        }
All Usage Examples Of Microsoft.Azure.Commands.Batch.Models.BatchClient::ListCertificates
BatchClient