RunPSScript() public method

public RunPSScript ( string script ) : Collection
script string
return Collection
        private static void Retry(string cmdlet, string message, int maxTry = 1, int intervalSecond = 10)
        {
            ServiceManagementCmdletTestHelper pscmdlet = new ServiceManagementCmdletTestHelper();

            for (int i = 0; i < maxTry; i++)
            {
                try
                {
                    pscmdlet.RunPSScript(cmdlet);
                    break;
                }
                catch (Exception e)
                {
                    if (i == maxTry)
                    {
                        Console.WriteLine("Max try reached.  Couldn't perform within the given time.");
                    }
                    if (e.ToString().Contains(message))
                    {
                        //Thread.Sleep(intervalSecond * 1000);
                        continue;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
        protected static void CopyTestData(string srcContainer, string srcBlob, string destContainer, string destBlob)
        {
            Process          currentProcess = Process.GetCurrentProcess();
            StringDictionary environment    = currentProcess.StartInfo.EnvironmentVariables;

            string storageAccount    = environment[CredentialHelper.StorageAccountVariable];
            string storageAccountKey = environment[CredentialHelper.StorageAccountKeyVariable];

            // Create a container
            try
            {
                vmPowershellCmdlets.RunPSScript("Get-AzureStorageContainer -Name " + destContainer);
            }
            catch
            {
                // Create a container.
                vmPowershellCmdlets.RunPSScript("New-AzureStorageContainer -Name " + destContainer);
            }

            // Make SAS Uri for the source blob.
            string srcSasUri = Utilities.GenerateSasUri(CredentialHelper.CredentialBlobUriFormat, storageAccount, storageAccountKey, srcContainer, srcBlob);

            vmPowershellCmdlets.RunPSScript(string.Format("Start-AzureStorageBlobCopy -SrcUri \"{0}\" -DestContainer {1} -DestBlob {2} -Force", srcSasUri, destContainer, destBlob));
            vmPowershellCmdlets.RunPSScript(string.Format("Start-AzureStorageBlobCopy -SrcUri \"{0}\" -DestContainer {1} -DestBlob {2} -Force", srcSasUri, destContainer, destBlob));

            for (int i = 0; i < 60; i++)
            {
                var result = vmPowershellCmdlets.CheckCopyBlobStatus(destContainer, destBlob);
                if (result.Status.ToString().Equals("Success"))
                {
                    break;
                }
                else
                {
                    Thread.Sleep(10 * 1000);
                }
            }
        }
        private static void Retry(string cmdlet, string message, int maxTry = 1, int intervalSecond = 10)
        {
            ServiceManagementCmdletTestHelper pscmdlet = new ServiceManagementCmdletTestHelper();

            for (int i = 0; i < maxTry; i++)
            {
                try
                {
                    pscmdlet.RunPSScript(cmdlet);
                    break;
                }
                catch (Exception e)
                {
                    if (i == maxTry)
                    {
                        Console.WriteLine("Max try reached.  Couldn't perform within the given time.");
                    }
                    if (e.ToString().Contains(message))
                    {
                        //Thread.Sleep(intervalSecond * 1000);
                        continue;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void CopyTestData(string srcContainer, string srcBlob, string destContainer, string destBlob)
        {
            ServiceManagementCmdletTestHelper vmPowershellCmdlets = new ServiceManagementCmdletTestHelper();
            Process currentProcess = Process.GetCurrentProcess();
            StringDictionary environment = currentProcess.StartInfo.EnvironmentVariables;

            string storageAccount = environment[CredentialHelper.StorageAccountVariable];
            string storageAccountKey = environment[CredentialHelper.StorageAccountKeyVariable];

            // Create a container
            try
            {
                vmPowershellCmdlets.RunPSScript("Get-AzureStorageContainer -Name " + destContainer);
            }
            catch
            {
                // Create a container.
                vmPowershellCmdlets.RunPSScript("New-AzureStorageContainer -Name " + destContainer);
            }

            // Make SAS Uri for the source blob.
            string srcSasUri = Utilities.GenerateSasUri(CredentialHelper.CredentialBlobUriFormat, storageAccount, storageAccountKey, srcContainer, srcBlob);

            vmPowershellCmdlets.RunPSScript(string.Format("Start-AzureStorageBlobCopy -SrcUri \"{0}\" -DestContainer {1} -DestBlob {2} -Force", srcSasUri, destContainer, destBlob));

            for (int i = 0; i < 60; i++)
            {
                var result = vmPowershellCmdlets.CheckCopyBlobStatus(destContainer, destBlob);
                if (result.Status.ToString().Equals("Success"))
                {
                    break;
                }
                else
                {
                    System.Threading.Thread.Sleep(10 * 1000);
                }
            }
        }