コード例 #1
0
        /// <summary>
        /// Runs cygpath with the specified arguments and returns the result
        /// as a <see cref="string" />.
        /// </summary>
        /// <param name="args">The arguments to pass to cygpath.</param>
        /// <returns>
        /// The result of running cygpath with the specified arguments.
        /// </returns>
        private string RunCygpathString(Argument[] args)
        {
            MemoryStream ms = new MemoryStream();

            ExecTask execTask = GetTask(ms);

            execTask.Arguments.AddRange(args);

            try {
                execTask.Execute();
                ms.Position = 0;
                StreamReader sr     = new StreamReader(ms);
                string       output = sr.ReadLine();
                sr.Close();
                return(output);
            } catch (Exception ex) {
                ms.Position = 0;
                StreamReader sr     = new StreamReader(ms);
                string       output = sr.ReadToEnd();
                sr.Close();

                if (output.Length != 0)
                {
                    throw new BuildException(output, ex);
                }
                else
                {
                    throw;
                }
            }
        }
コード例 #2
0
ファイル: ExecTaskTests.cs プロジェクト: rosaliafx/Rosalia
        public void Execute_EchoTask_ShouldSucceed()
        {
            var echoTask = new ExecTask
            {
                ToolPath = "cmd.exe",
                Arguments = string.Format("/c echo {0}", "Hello, Rosalia!")
            };

            echoTask.Execute().AssertSuccess();
        }
コード例 #3
0
        /// <summary>
        /// Factory method to return a new instance of ExecTask
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        private ExecTask GetTask(Stream stream)
        {
            ExecTask execTask = new ExecTask();

            execTask.Parent      = Project;
            execTask.Project     = Project;
            execTask.FileName    = "cygpath";
            execTask.Threshold   = Level.None;
            execTask.ErrorWriter = execTask.OutputWriter = new StreamWriter(stream);
            return(execTask);
        }
コード例 #4
0
ファイル: ExecTaskTests.cs プロジェクト: rosaliafx/Rosalia
        public void Execute_EchoTask_ShouldLogMessage()
        {
            var echoTask = new ExecTask
            {
                ToolPath = "cmd.exe",
                Arguments = string.Format("/c echo {0}", "Hello, Rosalia!")
            };

            echoTask.Execute()
                .AssertSuccess()
                .Log.AssertHasMessage(MessageLevel.Info, "Hello, Rosalia!");
        }
コード例 #5
0
        /// <summary>
        /// Executes the task.
        /// </summary>
        protected override void ExecuteTask()
        {
            if (!this.DoxygenBinary.Exists)
            {
                this.Log(Level.Error, "Doxygen cannot be found.");
                return;
            }

            String baseFolder = this.CreateBaseDir();
            DocSet docSet     = this.CreateDocSet();
            IEnumerable <Framework> frameworks = this.CreateFrameworks(docSet);

            foreach (var f in frameworks)
            {
                if (f.source != DocumentOrigin.Doxygen)
                {
                    continue;
                }

                String configuration;
                if (docSet != null)
                {
                    configuration = Path.Combine(baseFolder, docSet.Name, f.name, "doxygen.cfg");
                }
                else
                {
                    configuration = Path.Combine(baseFolder, f.name, "doxygen.cfg");
                }

                if (File.Exists(configuration))
                {
                    continue;
                }

                this.Log(Level.Info, "Generating Doxygen files for '{0}'...", f.name);

                ExportConfiguration(configuration);

                ExecTask execTask = new ExecTask();
                execTask.Project              = this.Project;
                execTask.FailOnError          = true;
                execTask.FileName             = this.DoxygenBinary.ToString();
                execTask.CommandLineArguments = Path.GetFileName(configuration);
                execTask.WorkingDirectory     = new DirectoryInfo(Path.GetDirectoryName(configuration));

                execTask.Execute();

                GenerateDescriptor(baseFolder, f);
            }
        }
コード例 #6
0
        public void TestDefaultExitCode()
        {
            this.PrepareTestEnvironment();
            ExecTask task = this.CreateTaskWithProject();

            if (PlatformHelper.IsUnix)
            {
                task.FileName = "bash";
                task.Arguments.Add(new Argument("-c"));
            }
            else
            {
                task.FileName = @"cmd.exe";
                task.Arguments.Add(new Argument("/c"));
            }
            task.Arguments.Add(new Argument("exit"));
            task.Arguments.Add(new Argument(0.ToString(CultureInfo.InvariantCulture)));
            task.Execute();
        }
コード例 #7
0
        public void TestExpectedExitCode()
        {
            this.PrepareTestEnvironment();
            List <int> exitCodes = new List <int>();

            exitCodes.Add(byte.MaxValue);
            exitCodes.Add(byte.MinValue);
            exitCodes.Add(sbyte.MaxValue);

            // Bash supports only exit codes from 0  to 255
            if (PlatformHelper.IsWindows)
            {
                exitCodes.Add(sbyte.MinValue);
                exitCodes.Add(short.MaxValue);
                exitCodes.Add(short.MinValue);
                exitCodes.Add(ushort.MaxValue);
                exitCodes.Add(ushort.MinValue);
                exitCodes.Add(int.MaxValue);
                exitCodes.Add(int.MinValue);
            }

            foreach (int exitCode in exitCodes)
            {
                ExecTask task = this.CreateTaskWithProject();
                if (PlatformHelper.IsUnix)
                {
                    task.FileName = "bash";
                    task.Arguments.Add(new Argument("-c"));
                    task.Arguments.Add(new Argument("\"exit " + exitCode.ToString(CultureInfo.InvariantCulture) + "\""));
                }
                else
                {
                    task.FileName = @"cmd.exe";
                    task.Arguments.Add(new Argument("/c"));
                    task.Arguments.Add(new Argument("exit"));
                    task.Arguments.Add(new Argument(exitCode.ToString(CultureInfo.InvariantCulture)));
                }

                task.ExpectedExitCode = exitCode;
                task.Execute();
            }
        }
コード例 #8
0
        /// <summary>
        /// Runs pkg-config with the specified arguments and returns a
        /// <see cref="bool" /> based on the exit code.
        /// </summary>
        /// <param name="args">The arguments to pass to pkg-config.</param>
        /// <returns>
        /// <see langword="true" /> if pkg-config exited with exit code 0;
        /// otherwise, <see langword="false" />
        /// </returns>
        private bool RunPkgConfigBool(Argument[] args)
        {
            MemoryStream ms = new MemoryStream();

            ExecTask execTask = GetTask(ms);

            execTask.Arguments.AddRange(args);

            try {
                execTask.Execute();
                return(true);
            } catch (Exception) {
                if (execTask.ExitCode == ExternalProgramBase.UnknownExitCode)
                {
                    // process could not be started or did not exit in time
                    throw;
                }
                return(false);
            }
        }
コード例 #9
0
        /// <summary>
        /// Creates the task with a project.
        /// </summary>
        /// <returns>
        /// The task with a project.
        /// </returns>
        protected ExecTask CreateTaskWithProject()
        {
            // Create buildfile
            XmlDocument  buildFile   = new XmlDocument();
            XmlElement   element     = buildFile.CreateElement("project");
            XmlAttribute projectName = buildFile.CreateAttribute("name");

            projectName.Value = this.TestProjectName;
            element.Attributes.Append(projectName);
            buildFile.AppendChild(element);
            string buildFileName = Path.GetFullPath(this.BuildFileName);

            buildFile.Save(buildFileName);

            // Create project
            Project project = new Project(buildFileName, Level.Debug, 0);

            // create task
            ExecTask task = new ExecTask();

            task.Project = project;
            task.Parent  = project;
            return(task);
        }
コード例 #10
0
        public void TestUnexpectedExitCode()
        {
            this.PrepareTestEnvironment();
            // Dictonary with test data. Key: produced exit code, value: expected exit code
            Dictionary <int, int> exitCodes = new Dictionary <int, int>();

            exitCodes.Add(byte.MaxValue, byte.MinValue);

            // Bash supports only exit codes from 0  to 255
            if (PlatformHelper.IsWindows)
            {
                exitCodes.Add(sbyte.MaxValue, sbyte.MinValue);
                exitCodes.Add(short.MaxValue, short.MinValue);
                exitCodes.Add(ushort.MaxValue, ushort.MinValue);
                exitCodes.Add(int.MaxValue, int.MinValue);
            }

            foreach (KeyValuePair <int, int> exitCode in exitCodes)
            {
                ExecTask task = this.CreateTaskWithProject();
                if (PlatformHelper.IsUnix)
                {
                    task.FileName = "bash";
                    task.Arguments.Add(new Argument("-c"));
                    task.Arguments.Add(new Argument("\"exit " + exitCode.Key.ToString(CultureInfo.InvariantCulture) + "\""));
                }
                else
                {
                    task.FileName = @"cmd.exe";
                    task.Arguments.Add(new Argument("/c"));
                    task.Arguments.Add(new Argument("exit"));
                    task.Arguments.Add(new Argument(exitCode.Key.ToString(CultureInfo.InvariantCulture)));
                }

                task.ExpectedExitCode = exitCode.Value;
                BuildException currentBuildException = null;
                try
                {
                    task.Execute();
                }
                catch (BuildException ex)
                {
                    currentBuildException = ex;
                }

                Assert.IsNotNull(currentBuildException);
            }

            foreach (KeyValuePair <int, int> exitCode in exitCodes)
            {
                ExecTask task = this.CreateTaskWithProject();
                if (PlatformHelper.IsUnix)
                {
                    task.FileName = "bash";
                    task.Arguments.Add(new Argument("-c"));
                }
                else
                {
                    task.FileName = @"cmd.exe";
                    task.Arguments.Add(new Argument("/c"));
                }
                task.Arguments.Add(new Argument("exit"));
                task.Arguments.Add(new Argument(exitCode.Value.ToString(CultureInfo.InvariantCulture)));
                task.ExpectedExitCode = exitCode.Key;
                BuildException currentBuildException = null;
                try
                {
                    task.Execute();
                }
                catch (BuildException ex)
                {
                    currentBuildException = ex;
                }

                Assert.IsNotNull(currentBuildException);
            }
        }
コード例 #11
0
        private void runTaskButton_Click(object sender, RoutedEventArgs e)
        {
            Tasks.Task task;
            string     taskName = tasksBox.Text;

            switch (taskName)
            {
            case "Benchmark":
                try
                {
                    task = new BenchmarkTask(labelBox.Text, productBox.Text, parametersBox.Text, int.Parse(loopsBox.Text), ComputerWindow.SelectedComputers(), parseOSList);
                }
                catch (FormatException)
                {
                    MessageBox.Show("ERROR", "Loops is not a number!");
                    return;
                }

                break;

            case "Boot":
                task = new BootTask(ComputerWindow.SelectedComputers(), parseOSList);
                break;

            case "Reboot":
                task = new RebootTask(ComputerWindow.SelectedComputers(), parseOSList);
                break;

            case "Shutdown":
                task = new ShutdownTask(ComputerWindow.SelectedComputers(), parseOSList);
                break;

            case "Exec":
                task = new ExecTask(commandTextBox.Text, ComputerWindow.SelectedComputers(), parseOSList);
                break;

            case "Winupdate":
                task = new WinUpdateTask(ComputerWindow.SelectedComputers(), parseOSList);
                break;

            case "Update":
                task = new UpdateTask(ComputerWindow.SelectedComputers(), parseOSList);
                break;

            case "Valeta/Dandia":
                try
                {
                    task = new BatTask(zipBox.Text, outputPathcBox.Text, int.Parse(countBox.Text), modeBox.Text, (BatTask.BatType)batTypeBox.SelectedIndex, nocopyBox.IsChecked.Value, ComputerWindow.SelectedComputers(), parseOSList);
                }
                catch (FormatException)
                {
                    MessageBox.Show("ERROR", "Test count is not a number!");
                    return;
                }
                break;

            default:
                return;
            }

            List <Tuple <string, object> > parameters = task.GetJackParameters();


            PowerShell psinstance = PowerShell.Create();

            psinstance.Streams.Verbose.DataAdded  += jackInformationEventHandler;
            psinstance.Streams.Progress.DataAdded += jackProgressEventHandler;
            psinstance.Streams.Debug.DataAdded    += jackDebugEventHandler;
            psinstance.Streams.Error.DataAdded    += jackErrorEventHandler;

            //scriptInvoker.Invoke("Set-ExecutionPolicy Unrestricted Process");
            psinstance.AddCommand("Set-ExecutionPolicy");
            psinstance.AddParameter("-ExecutionPolicy", "Bypass");
            psinstance.AddCommand(SCRIPT_PATH);
            foreach (var param in parameters)
            {
                psinstance.AddParameter(param.Item1, param.Item2);
            }
            var results = psinstance.BeginInvoke();

            /*foreach (PSObject result in results)
             * {
             *  AppendOutputText(result.ToString());
             *  Console.WriteLine(result.ToString());
             * }*/
            ListBoxItem item = new ListBoxItem();

            item.Content = task.ToString();
            taskHistoryBox.Items.Add(task);
        }