Exemple #1
0
        /// <summary>
        ///     Build web application project
        /// </summary>
        /// <param name="appPhysicalPath"></param>
        /// <param name="projectName"></param>
        public virtual void Build(string appPhysicalPath, string projectName)
        {
            if (!_fileSystem.DirectoryExists(appPhysicalPath))
            {
                throw new Exception(string.Format("Application directory '{0}' does not exist.", appPhysicalPath));
            }

            if (string.IsNullOrEmpty(Path.GetExtension(projectName)))
            {
                projectName = projectName + ".csproj";
            }

            var projectFilePath = Path.Combine(appPhysicalPath, projectName);

            if (!_fileSystem.FileExists(projectFilePath))
            {
                throw new Exception(string.Format("Application project file '{0}' does not exist.", projectFilePath));
            }

            var psi = new ProcessStartInfo
            {
                FileName               = GetMsBuildPath(_fileSystem, _environmentSystem),
                Arguments              = string.Format("\"{0}\"", projectFilePath),
                WorkingDirectory       = appPhysicalPath,
                RedirectStandardOutput = true,
                UseShellExecute        = false,
                CreateNoWindow         = true
            };

            var msbuild = new Process {
                StartInfo = psi
            };

            if (!_processRunner.Start(msbuild))
            {
                throw new Exception(string.Format("Failed to start msbuild to build a project '{0}' at '{1}'", projectName, appPhysicalPath));
            }

            var output = _processRunner.GetProcessOutput(msbuild);

            if (!_processRunner.WaitForExit(msbuild, 10000))
            {
                _processRunner.Stop(msbuild);
            }

            var exitCode = _processRunner.GetProcessExitCode(msbuild);

            if (exitCode != 0)
            {
                throw new Exception(string.Format("There were some errors while trying to build a project '{0}' at '{1}': {2}",
                                                  projectName, appPhysicalPath, output));
            }
        }
        private void RunFirewallCommand(string command)
        {
            var startInfo = new ProcessStartInfo("netsh.exe", command)
            {
                CreateNoWindow = true, UseShellExecute = false
            };
            var firewall = new Process {
                StartInfo = startInfo
            };

            ProcessRunner.Start(firewall);

            ProcessRunner.WaitForExit(firewall, 60000);
        }
Exemple #3
0
        public void Run()
        {
            if (_filesystem.Path.IsPathRooted(ExecutablePath))
            {
                throw new NoRelativePathException(ExecutablePath);
            }
            _runner.Start(new ProcessStartInfo
            {
                FileName         = ExecutablePath,
                Arguments        = Arguments,
                WorkingDirectory = WorkingDirectory
            });

            _runner.WaitForExit();
            if (!AllowedToFail && _runner.ExitCode != 0)
            {
                throw new ProcessFailedException();
            }
        }