public static Uri GetDeploymentAndWaitForReady(string serviceName, string slot, int waitTime, int maxWaitTime) { DateTime startTime = DateTime.Now; while (true) { bool allReady = true; DeploymentInfoContext result = vmPowershellCmdlets.GetAzureDeployment(serviceName, slot); int instanceNum = result.RoleInstanceList.Count; bool[] isReady = new bool[instanceNum]; for (int j = 0; j < instanceNum; j++) { var instance = result.RoleInstanceList[j]; Console.WriteLine("Instance: {0}, Status: {1}", instance.InstanceName, instance.InstanceStatus); isReady[j] = (instance.InstanceStatus == "ReadyRole"); allReady &= isReady[j]; } if (!allReady && (DateTime.Now - startTime).TotalSeconds < maxWaitTime) { Console.WriteLine("Some roles are not ready, waiting for {0} seconds.", waitTime); Thread.Sleep(waitTime * 1000); } else if (!allReady) // some roles are not ready, and time-out. { Assert.Fail("Deployment is not ready within {0} seconds!", maxWaitTime); } else // all roles are ready { Console.WriteLine("Result of the deployment: {0}", result.Status); return(result.Url); } } }