public ExecutableResults Run(string arguments) { using (Process process = new Process()) { process.StartInfo.FileName = _executablePath; if (!System.IO.File.Exists(_executablePath)) { throw new TestFailedException("Unable to find file to execute:" + _executablePath); } process.StartInfo.Arguments = arguments; process.StartInfo.WorkingDirectory = this.WorkingDirectory; AstoriaTestLog.TraceLine("Commandline tool arguments:" + arguments); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.Start(); ReadToEndDelegate readToEnd = new ReadToEndDelegate(process.StandardOutput.ReadToEnd); IAsyncResult readToEndResult = readToEnd.BeginInvoke(null, null); try { process.WaitForExit(_millisecondsToWait); } catch (System.ComponentModel.Win32Exception win32Exception) { throw new TestFailedException( String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}", _executablePath, _millisecondsToWait / 1000, System.Environment.NewLine, win32Exception.Message)); } catch (System.SystemException systemException) { throw new TestFailedException( String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}", _executablePath, _millisecondsToWait / 1000, System.Environment.NewLine, systemException.Message)); } string output = readToEnd.EndInvoke(readToEndResult); ExecutableResults result = new ExecutableResults(process.ExitCode, output); return(result); } }
/// <summary> /// Runs the specifed application with the given arguments on the Machine /// for this service. /// </summary> /// <param name="appString">Application to run.</param> /// <param name="argString">Argument to application.</param> private void RunProcess(string appString, string argString) { if (ShouldWorkaroundDueToVistaUAC()) { Process[] processes = Process.GetProcessesByName("Commander.Server"); if (processes.Length > 0) { ProcessHelper.UseCommander(Environment.MachineName, delegate(Commander.RemoteServer remoteServer) { Commander.RemoteExecutableResults results = remoteServer.ExecuteScript(argString); if (results.ExitCode != 0) { throw new TestFailedException("Unable to run create website script:\n" + results.Output); } AstoriaTestLog.TraceLine(results.Output); }); } else { throw new TestFailedException("Expected a RemoteServer program called Commander.Server.exe to be running"); } } else if (ProcessHelper.IsLocalMachine(this.MachineName)) { // Run locally. ProcessStartInfo processStart = new ProcessStartInfo(appString, argString); processStart.UseShellExecute = false; processStart.CreateNoWindow = true; AstoriaTestLog.WriteLineIgnore(appString); AstoriaTestLog.WriteLineIgnore(argString); using (Process process = Process.Start(processStart)) { if (process != null) { const int timeoutMilliseconds = 20 * 1000; process.WaitForExit(timeoutMilliseconds); } } } }
private bool ShouldWorkaroundDueToVistaUAC() { if (AstoriaTestProperties.Host == Host.LocalIIS) { AstoriaTestLog.TraceLine("Host=LocalIIS"); if (!ProcessHelper.IsVistaOrLater()) { AstoriaTestLog.TraceLine("IsVista=False"); return(false); } AstoriaTestLog.TraceLine("IsVista=True"); WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent(); WindowsPrincipal principle = new WindowsPrincipal(currentIdentity); SecurityIdentifier sidAdmin = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null); if (!principle.IsInRole(sidAdmin)) { AstoriaTestLog.TraceLine("IsAdmin=False"); return(true); } AstoriaTestLog.TraceLine("IsAdmin=true"); } return(false); }
public void VerifyService() { // for call logging, we need the directory to exist, and the service doesn't necessarily have permission to create it // TODO: find some better, common place to put this for IIS, WebServiceHost, etc. Right now this is the best spot #if !ClientSKUFramework IOUtil.EnsureEmptyDirectoryExists(Path.Combine(DestinationFolder, CallOrder.APICallLog.DirectoryName)); #endif const int retryCount = 10; const int sleepTime = 6000; AstoriaTestLog.WriteLineIgnore("Verifying web service: " + this.ServiceUri); HttpWebRequest request = null; HttpWebResponse response = null; WebException webException = null; for (int count = 0; count < retryCount; count++) { try { request = (HttpWebRequest)HttpWebRequest.Create(this.ServiceUri + "/$metadata"); request.UseDefaultCredentials = true; response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream())) reader.ReadToEnd(); if (response.StatusCode == HttpStatusCode.OK) { AstoriaTestLog.WriteLineIgnore("Service verified."); return; } else { // can this happen without throwing? AstoriaTestLog.WriteLine("\tUnexpected status code: " + response.StatusCode); } } catch (Exception e) { string indent = "\t"; while (e != null) { if (e is WebException) { webException = e as WebException; } AstoriaTestLog.WriteLine(indent + e.GetType().Name + ": " + e.Message); indent += "\t"; e = e.InnerException; } } Thread.Sleep(sleepTime); } if (webException != null) { AstoriaTestLog.TraceLine("Web exception:"); AstoriaTestLog.TraceLine(webException.ToString()); if (webException.Response != null) { string exceptionPayload; using (StreamReader reader = new StreamReader(webException.Response.GetResponseStream())) exceptionPayload = reader.ReadToEnd(); AstoriaTestLog.TraceLine("Exception Payload:"); AstoriaTestLog.TraceLine(exceptionPayload); } } AstoriaTestLog.FailAndThrow("Service could not be verified."); }