We are automatically deploying a package to Azure, then running tests against that instance. See Brady Gaster’s article for more details. I needed a way to make sure the deployment was complete, and if not wait for it. After digging through the objects with Intellisense, we found this solution:
public bool IsCloudServiceRunning()
{
var details = _computeManagementClient.HostedServices.GetDetailed(_parameters.CloudServiceName);
var deployment = details.Deployments.First(d => d.Name == _parameters.CloudServiceName + "Prod");
Debug.WriteLine("Checking is cloud service running. Current Status: " + deployment.Status);
return deployment.Status == DeploymentStatus.Running;
}
The constructor:
public AzureDeploymentManager(ServiceCreateParameters parameters)
{
this._parameters = parameters;
var credential = CertificateAuthenticationHelper.GetCredentials(
parameters.SubscriptionId,
parameters.Base64EncodedCertificate);
this._computeManagementClient = CloudContext.Clients.CreateComputeManagementClient(credential);
}
And the CertificateAuthenticationHelper from Brady’s post:
using System;
using System.Security.Cryptography.X509Certificates;
using Microsoft.WindowsAzure;
namespace Deployer.Common
{
public class CertificateAuthenticationHelper
{
public static SubscriptionCloudCredentials GetCredentials(
string subscriptionId, string base64EncodedCert)
{
return new CertificateCloudCredentials(subscriptionId,
new X509Certificate2(Convert.FromBase64String(base64EncodedCert)));
}
}
}