本文整理汇总了C#中Microsoft.Azure.Commands.Batch.Models.BatchClient.ListCertificates方法的典型用法代码示例。如果您正苦于以下问题:C# BatchClient.ListCertificates方法的具体用法?C# BatchClient.ListCertificates怎么用?C# BatchClient.ListCertificates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.Commands.Batch.Models.BatchClient
的用法示例。
在下文中一共展示了BatchClient.ListCertificates方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddTestCertificate
/// <summary>
/// Adds a test certificate for use in Scenario tests. Returns the thumbprint of the cert.
/// </summary>
public static string AddTestCertificate(BatchController controller, BatchAccountContext context, string filePath)
{
BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient);
X509Certificate2 cert = new X509Certificate2(filePath);
ListCertificateOptions getParameters = new ListCertificateOptions(context)
{
ThumbprintAlgorithm = BatchTestHelpers.TestCertificateAlgorithm,
Thumbprint = cert.Thumbprint,
Select = "thumbprint,state"
};
try
{
PSCertificate existingCert = client.ListCertificates(getParameters).FirstOrDefault();
DateTime start = DateTime.Now;
DateTime end = start.AddMinutes(5);
// Cert might still be deleting from other tests, so we wait for the delete to finish.
while (existingCert != null && existingCert.State == CertificateState.Deleting)
{
if (DateTime.Now > end)
{
throw new TimeoutException("Timed out waiting for existing cert to be deleted.");
}
Sleep(5000);
existingCert = client.ListCertificates(getParameters).FirstOrDefault();
}
}
catch (AggregateException ex)
{
foreach (Exception inner in ex.InnerExceptions)
{
BatchException batchEx = inner as BatchException;
// When the cert doesn't exist, we get a 404 error. For all other errors, throw.
if (batchEx == null || !batchEx.Message.Contains("CertificateNotFound"))
{
throw;
}
}
}
NewCertificateParameters parameters = new NewCertificateParameters(context, null, cert.RawData);
client.AddCertificate(parameters);
return cert.Thumbprint;
}
示例2: WaitForCertificateToFailDeletion
/// <summary>
/// Deletes a certificate.
/// </summary>
public static void WaitForCertificateToFailDeletion(BatchController controller, BatchAccountContext context, string thumbprintAlgorithm, string thumbprint)
{
BatchClient client = new BatchClient(controller.BatchManagementClient, controller.ResourceManagementClient);
ListCertificateOptions parameters = new ListCertificateOptions(context)
{
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();
}
}