示例#1
0
        private OSImageContext WaitForPIRAppear(string imageName, string publisherName, int waitTimeInMin = 1, int maxWaitTimeInMin = 30)
        {
            DateTime startTime = DateTime.Now;

            while (true)
            {
                Collection <OSImageContext> vmImages = vmPowershellCmdlets.GetAzureVMImage();
                foreach (OSImageContext image in vmImages)
                {
                    if (Utilities.MatchKeywords(image.ImageName, new[] { imageName }, false) >= 0 && image.PublisherName.Equals(publisherName))
                    {
                        Console.WriteLine("MATCHED PIR image found after {0} minutes:", (DateTime.Now - startTime).TotalMinutes);
                        PrintContext <OSImageContext>(image);
                        return(image);
                    }
                }

                if ((DateTime.Now - startTime).TotalMinutes < maxWaitTimeInMin)
                {
                    Thread.Sleep(waitTimeInMin * 1000 * 60);
                }
                else
                {
                    Assert.Fail("Cannot get PIR image, {0}, within {1} minutes!", imageName, maxWaitTimeInMin);
                }
            }
        }