示例#1
0
        /// <summary>
        /// Check if the current configuration is a workflow endpoint
        /// </summary>
        /// <returns></returns>
        private bool IsWorkflowConfigurationType(System.Management.Automation.PowerShell ps)
        {
            // Get the AssemblyName
            ps.AddScript(string.Format(CultureInfo.InvariantCulture, getAssemblyNameDataFormat, CodeGeneration.EscapeSingleQuotedStringContent(Name)));
            Collection<PSObject> psObjectCollection = ps.Invoke(new object[] { Name }) as Collection<PSObject>;
            if (psObjectCollection == null || psObjectCollection.Count != 1)
            {
                Dbg.Assert(false, "This should never happen. ps.Invoke always return a Collection<PSObject>");
            }

            if (psObjectCollection[0] == null)
            {
                // Not workflow endpoint, no assembly name
                return false;
            }

            string assemblyNameOfCurrentConfiguration = psObjectCollection[0].BaseObject.ToString();
            return assemblyNameOfCurrentConfiguration.Equals(ConfigurationDataFromXML.WORKFLOWCOREASSEMBLY, StringComparison.OrdinalIgnoreCase);
        }
        private void SetupPowerShellModules(System.Management.Automation.PowerShell powershell)
        {
            powershell.AddScript("$error.clear()");
            powershell.AddScript(string.Format("Write-Debug \"current directory: {0}\"", AppDomain.CurrentDomain.BaseDirectory));
            powershell.AddScript(string.Format("Write-Debug \"current executing assembly: {0}\"", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)));
            powershell.AddScript(string.Format("cd \"{0}\"", AppDomain.CurrentDomain.BaseDirectory));

            foreach (string moduleName in modules)
            {
                powershell.AddScript(string.Format("Import-Module \"{0}\"", moduleName.AsAbsoluteLocation()));
            }

            powershell.AddScript(
                string.Format("set-location \"{0}\"", AppDomain.CurrentDomain.BaseDirectory));
            powershell.AddScript(string.Format(@"$TestOutputRoot='{0}'", AppDomain.CurrentDomain.BaseDirectory));
            powershell.AddScript("$VerbosePreference='Continue'");
            powershell.AddScript("$DebugPreference='Continue'");
            powershell.AddScript("$ErrorActionPreference='Stop'");
            powershell.AddScript("Write-Debug \"AZURE_TEST_MODE = $($env:AZURE_TEST_MODE)\"");
            powershell.AddScript("Write-Debug \"TEST_HTTPMOCK_OUTPUT =  $($env:TEST_HTTPMOCK_OUTPUT)\"");
        }
        private void SetupPowerShellModules(System.Management.Automation.PowerShell powershell)
        {
            powershell.AddScript(string.Format("cd \"{0}\"", Environment.CurrentDirectory));

            foreach (string moduleName in modules)
            {
                powershell.AddScript(string.Format("Import-Module \".\\{0}\"", moduleName));
            }

            powershell.AddScript("$VerbosePreference='Continue'");
            powershell.AddScript("$DebugPreference='Continue'");
            powershell.AddScript("$ErrorActionPreference='Stop'");
            powershell.AddScript("Write-Debug \"AZURE_TEST_MODE = $env:AZURE_TEST_MODE\"");
            powershell.AddScript("Write-Debug \"TEST_HTTPMOCK_OUTPUT = $env:TEST_HTTPMOCK_OUTPUT\"");
        }
        private void SetupPowerShellModules(System.Management.Automation.PowerShell powershell)
        {
            powershell.AddScript(string.Format("Write-Debug \"current directory: {0}\"", Directory.GetCurrentDirectory()));
            powershell.AddScript(string.Format("Write-Debug \"current executing assembly: {0}\"", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)));
            powershell.AddScript(string.Format("cd \"{0}\"", Directory.GetCurrentDirectory()));

            foreach (string moduleName in modules)
            {
                powershell.AddScript(string.Format("Import-Module \".\\{0}\"", moduleName));
            }

            powershell.AddScript("$VerbosePreference='Continue'");
            powershell.AddScript("$DebugPreference='Continue'");
            powershell.AddScript("$ErrorActionPreference='Stop'");
            powershell.AddScript("Write-Debug \"AZURE_TEST_MODE = $($env:AZURE_TEST_MODE)\"");
            powershell.AddScript("Write-Debug \"TEST_HTTPMOCK_OUTPUT =  $($env:TEST_HTTPMOCK_OUTPUT)\"");
        }
        private void SetupPowerShellModules(System.Management.Automation.PowerShell powershell)
        {
            powershell.AddScript("$error.clear()");
            powershell.AddScript(string.Format("cd \"{0}\"", AppDomain.CurrentDomain.BaseDirectory));

            foreach (string moduleName in modules)
            {
                powershell.AddScript(string.Format("Import-Module \"{0}\"",
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, moduleName)));
            }

            powershell.AddScript(
                string.Format(@"set-location {0}", AppDomain.CurrentDomain.BaseDirectory));
            powershell.AddScript(string.Format(@"$TestOutputRoot='{0}'", AppDomain.CurrentDomain.BaseDirectory));
            powershell.AddScript("$VerbosePreference='Continue'");
            powershell.AddScript("$DebugPreference='Continue'");
            powershell.AddScript("$ErrorActionPreference='Stop'");
            powershell.AddScript("Write-Debug \"AZURE_TEST_MODE = $env:AZURE_TEST_MODE\"");
            powershell.AddScript("Write-Debug \"TEST_HTTPMOCK_OUTPUT = $env:TEST_HTTPMOCK_OUTPUT\"");
        }
        public void SetupPowerShellEnvironment(System.Management.Automation.PowerShell powerShell, string credentials, string profile)
        {
            powerShell.RemoveCredentials();
            string profileFile = Path.Combine(this.downloadDirectoryPath, profile);

            if (File.Exists(profileFile))
            {
                string dest = Path.Combine(AzurePowerShell.ProfileDirectory, profile);
                powerShell.AddScript(string.Format("Copy-Item -Path '{0}' -Destination '{1}' -Force", profileFile, dest));
                powerShell.AddScript("[Microsoft.WindowsAzure.Commands.Utilities.Common.AzureProfile]::Instance.Load()");
            }
            else
            {
                string credentialFile = Path.Combine(this.downloadDirectoryPath, credentials);
                Assert.IsTrue(File.Exists(credentialFile), string.Format("Did not download file {0}", credentialFile));
                Console.WriteLine("Using default.PublishSettings for setting up credentials");
                powerShell.ImportCredentials(credentialFile);
            }

            foreach (string key in this.environment.Keys) powerShell.AddEnvironmentVariable(key, environment[key]);
            foreach (string key in this.PowerShellVariables.Keys) powerShell.SetVariable(key, PowerShellVariables[key]);
        }
        private void SetupPowerShellModules(System.Management.Automation.PowerShell powershell, IEnumerable<string> setupScripts)
        {
            powershell.AddScript("$error.clear()");
            powershell.AddScript(string.Format("cd \"{0}\"", AppDomain.CurrentDomain.BaseDirectory));
            if (setupScripts != null)
            {
                foreach(var script in setupScripts)
                {
                    powershell.AddScript(script);
                }
            }

            foreach (string moduleName in modules)
            {
                powershell.AddScript(string.Format("Import-Module \"{0}\"", moduleName.AsAbsoluteLocation()));
            }

            powershell.AddScript(
                string.Format("set-location \"{0}\"", AppDomain.CurrentDomain.BaseDirectory));
            powershell.AddScript(string.Format(@"$TestOutputRoot='{0}'", AppDomain.CurrentDomain.BaseDirectory));
            powershell.AddScript("$VerbosePreference='Continue'");
            powershell.AddScript("$DebugPreference='Continue'");
            powershell.AddScript("$ErrorActionPreference='Stop'");
            powershell.AddScript("Write-Debug \"AZURE_TEST_MODE = $($env:AZURE_TEST_MODE)\"");
            powershell.AddScript("Write-Debug \"TEST_HTTPMOCK_OUTPUT =  $($env:TEST_HTTPMOCK_OUTPUT)\"");
        }
        private Collection<PSObject> ExecuteShellTest(
            System.Management.Automation.PowerShell powershell,
            IEnumerable<string> setupScripts,
            IEnumerable<string> scripts)
        {
            SetupPowerShellModules(powershell, setupScripts);

            Collection<PSObject> output = null;

            foreach (var script in scripts)
            {
                if (TracingInterceptor != null)
                {
                    TracingInterceptor.Information(script);
                }
                powershell.AddScript(script);
            }
            try
            {
                powershell.Runspace.Events.Subscribers.Clear();
                powershell.Streams.Error.Clear();
                output = powershell.Invoke();

                if (powershell.Streams.Error.Count > 0)
                {
                    var sb = new StringBuilder();

                    sb.AppendLine("Test failed due to a non-empty error stream, check the error stream in the test log for more details.");
                    sb.AppendLine(string.Format("{0} total Errors", powershell.Streams.Error.Count));
                    foreach (var error in powershell.Streams.Error)
                    {
                        sb.AppendLine(error.Exception.ToString());
                    }

                    throw new RuntimeException(sb.ToString());
                }

                return output;
            }
            catch (Exception psException)
            {
                powershell.LogPowerShellException(psException, TracingInterceptor);
                throw;
            }
            finally
            {
                powershell.LogPowerShellResults(output, TracingInterceptor);
                powershell.Streams.Error.Clear();
            }
        }
示例#9
0
        private void RemoveFunctionPSCopyFileToRemoteSession(System.Management.Automation.PowerShell ps)
        {
            if ((ps == null) || !ValidRemoteSessionForScripting(ps.Runspace)) { return; }

            string remoteScript = @"
                Microsoft.PowerShell.Management\Remove-Item function:PSCopyToSessionHelper -ea SilentlyContinue -Force
                Microsoft.PowerShell.Management\Remove-Item function:PSCopyRemoteUtils -ea SilentlyContinue -Force
            ";
            ps.AddScript(remoteScript);
            SafeInvokeCommand.Invoke(ps, this, null, false);
        }
示例#10
0
        private void InitilizeFunctionsPSCopyFileToRemoteSession(System.Management.Automation.PowerShell ps)
        {
            if ((ps == null) || !ValidRemoteSessionForScripting(ps.Runspace)) { return; }

            ps.AddScript(CopyFileRemoteUtils.AllCopyToRemoteScripts);
            SafeInvokeCommand.Invoke(ps, this, null, false);
        }