internal override void InternalExecute() { if (String.IsNullOrEmpty(pathToConsoleRunner)) { throw new FileNotFoundException("Could not automatically find mstest.exe. Please specify it manually using PathToConsoleRunner"); } BuildArgs(); IExecutable executable = _executable.ExecutablePath(pathToConsoleRunner).UseArgumentBuilder(_argumentBuilder); if (!String.IsNullOrEmpty(workingDirectory)) { executable = executable.InWorkingDirectory(workingDirectory); } //don't throw any errors //.WithMessageProcessor() int returnCode = executable.Execute(); //if it returned non-zero then just exit (as a test failed) if (returnCode != 0 && base.OnError == OnError.Fail) { BuildFile.SetErrorState(); Defaults.Logger.WriteError("ERROR", "MSTest returned non-zero error code"); } }
private void ExeSample() { Task.Run.ILMerge(x => x.ExecutableLocatedAt("").AddSource("").AddSource("").OutputTo("")); var response = Task.Run.Executable(exe => exe.ExecutablePath(@"c:\temp\myapp.exe").SucceedOnNonZeroErrorCodes()); if (response == 3 || response == 7) { BuildFile.SetErrorState(); Defaults.Logger.WriteError("MYAPP", "myapp.exe returned an error code of " + response); } }
private void HandleTimeout(IProcessWrapper process) { Defaults.Logger.WriteDebugMessage("TIMEOUT!"); process.Kill(); Thread.Sleep(1000); //wait one second so that the process has time to exit if (OnError == OnError.Fail) { //exit code should only be set if we want the application to fail on error BuildFile.SetErrorState(); //set our ExitCode to non-zero so consumers know we errored } }
internal int Execute(string prefix) { Defaults.Logger.Write(prefix, Path + _argumentBuilder.Build()); int exitCode = 0; using (IProcessWrapper process = CreateProcess()) { try { process.Start(); process.BeginOutputAndErrorReadLine(); if (!process.WaitForExit(_timeoutInMiliSeconds)) { HandleTimeout(process); } // if( _noErrorMessageWhenExitCodeZero && process.ExitCode == 0) // { // _output.Append( _error ); // _error.Clear(); // } _messageProcessor.Display(prefix, _output.ToString(), _error.ToString(), process.ExitCode); exitCode = process.ExitCode; //if we are supposed to fail on errors //and there was an error //and the calling code has decided not to deal with the error code (by setting SucceedOnNonZeroErrorCodes //then set the environment exit code if (OnError == OnError.Fail && exitCode != 0 && _succeedOnNonZeroErrorCodes == false) { BuildFile.SetErrorState(); throw new ApplicationException("Executable returned an error code of " + exitCode); } } catch (Exception e) { if (OnError == OnError.Fail) { throw; } Debug.Write(prefix, "An error occurred running a process but FailOnError was set to false. Error: " + e); } } this.ExitCode = exitCode; return(exitCode); }
public void Execute() { try { if (!DoesDatabaseAlreadyExist()) { CreateDatabase(); } UpdateDatabase(); } catch (Exception ex) { BuildFile.SetErrorState(); Defaults.Logger.Write("ERROR", ex.ToString()); } }
internal override void InternalExecute() { Defaults.Logger.Write("FTP", String.Format("Uploading {0} to ftp://{1}/{2}/{3}", _localFilePath, _serverName, _remoteFilePath, Path.GetFileName(_localFilePath))); var request = (FtpWebRequest)WebRequest.Create(String.Format("ftp://{0}/{1}/{2}", _serverName, _remoteFilePath, Path.GetFileName(_localFilePath))); request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential(_username, _password); request.UseBinary = true; if (_timeout.TotalMilliseconds > 0) { request.ReadWriteTimeout = (int)_timeout.TotalMilliseconds; request.Timeout = (int)_timeout.TotalMilliseconds; } request.KeepAlive = false; byte[] fileContents = new byte[0]; using (var s = new FileStream(_localFilePath, FileMode.Open, FileAccess.Read)) { Array.Resize(ref fileContents, (int)(s.Length)); s.Read(fileContents, 0, (int)s.Length); } using (var requestStream = request.GetRequestStream()) { requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); } using (var response = (FtpWebResponse)request.GetResponse()) { if (response.StatusCode != FtpStatusCode.ClosingData) { BuildFile.SetErrorState(); } Defaults.Logger.Write("FTP", "Upload File Complete, status {0}", response.StatusDescription); response.Close(); } }
internal override void InternalExecute() { if (String.IsNullOrEmpty(_pathToConsoleRunner)) { _pathToConsoleRunner = _fileSystemHelper.Find("nunit-console.exe"); if (_pathToConsoleRunner == null) { throw new FileNotFoundException("Could not automatically find nunit-console.exe. Please specify it manually using NunitRunner.PathToNunitConsoleRunner"); } } var executable = _executable.ExecutablePath(_pathToConsoleRunner); BuildArgs(); executable = executable.UseArgumentBuilder(_argumentBuilder); executable = executable.SucceedOnNonZeroErrorCodes(); //var executable = executablePath.SucceedOnNonZeroErrorCodes(); //if (OnError == OnError.Fail) // executable = executable.FailOnError; //else if (OnError == OnError.Continue) // executable = executable.ContinueOnError; if (!String.IsNullOrEmpty(_workingDirectory)) { executable = executable.InWorkingDirectory(_workingDirectory); } //don't throw an errors var returnCode = executable.WithMessageProcessor(new NunitMessageProcessor()).Execute(); //if it returned non-zero then just exit (as a test failed) if (returnCode != 0 && base.OnError == OnError.Fail) { BuildFile.SetErrorState(); Defaults.Logger.WriteError("ERROR", "Nunit returned non-zero error code"); } }