Esempio n. 1
0
        public override TaskCommandResult Execute()
        {
            TaskCommandResult finalResult = null;
            var output = new StringBuilder();

            foreach (string path in arguments)
            {
                try
                {
                    ProcessPath(path, output);
                }
                catch (Exception ex)
                {
                    finalResult = new TaskCommandResult(1, null, ex.Message);
                    break;
                }
            }

            if (finalResult == null)
            {
                string stdout = output.ToString();
                finalResult = new TaskCommandResult(0, stdout, null);
            }

            return finalResult;
        }
Esempio n. 2
0
        override protected TaskCommandResult Invoke()
        {
            TaskCommandResult finalResult = null;
            var output = new StringBuilder();

            foreach (string path in this.CommandArgs.Arguments)
            {
                try
                {
                    ProcessPath(path, output);
                }
                catch (Exception ex)
                {
                    log.Error("ProcessPath Exception: {0}", ex.ToString());
                    finalResult = new TaskCommandResult(1, null, ex.Message);
                    break;
                }
            }

            if (finalResult == null)
            {
                string stdout = output.ToString();
                finalResult = new TaskCommandResult(0, stdout, null);
            }

            return(finalResult);
        }
Esempio n. 3
0
        public override TaskCommandResult Execute()
        {
            TaskCommandResult finalResult = null;
            var output = new StringBuilder();

            foreach (string path in arguments)
            {
                try
                {
                    ProcessPath(path, output);
                }
                catch (Exception ex)
                {
                    finalResult = new TaskCommandResult(1, null, ex.Message);
                    break;
                }
            }

            if (finalResult == null)
            {
                string stdout = output.ToString();
                finalResult = new TaskCommandResult(0, stdout, null);
            }

            return(finalResult);
        }
Esempio n. 4
0
        private async Task <IJobResult> DoRunAsync()
        {
            bool shouldImpersonate = !request.Privileged;

            var commandFactory = new TaskCommandFactory(container, shouldImpersonate, request.Rlimits);
            var credential     = container.GetCredential();
            var results        = new List <TaskCommandResult>();

            foreach (TaskCommandDTO cmd in commands)
            {
                if (cts.IsCancellationRequested)
                {
                    break;
                }

                TaskCommand taskCommand = commandFactory.Create(cmd.Command, cmd.Args);

                try
                {
                    var processCommand = taskCommand as ProcessCommand;
                    if (runningAsync && processCommand != null)
                    {
                        // NB: ProcessCommands take care of their own impersonation
                        processCommand.StatusAvailable += processCommand_StatusAvailable;
                        try
                        {
                            TaskCommandResult result = await processCommand.ExecuteAsync();

                            results.Add(result);
                        }
                        finally
                        {
                            processCommand.StatusAvailable -= processCommand_StatusAvailable;
                        }
                    }
                    else
                    {
                        using (Impersonator.GetContext(credential, shouldImpersonate))
                        {
                            results.Add(taskCommand.Execute());
                        }
                    }
                }
                catch (Exception ex)
                {
                    results.Add(new TaskCommandResult(1, null, ex.Message));
                    break;
                }
            }

            return(FlattenResults(results));
        }
Esempio n. 5
0
        public IJobResult Run()
        {
            bool shouldImpersonate = !request.Privileged;

            var commandFactory = new TaskCommandFactory(container, shouldImpersonate, request.Rlimits);
            var credential     = container.GetCredential();
            var results        = new List <TaskCommandResult>();

            foreach (TaskCommandDTO cmd in commands)
            {
                if (cts.IsCancellationRequested)
                {
                    break;
                }

                TaskCommand taskCommand = commandFactory.Create(cmd.Command, cmd.Args);
                try
                {
                    TaskCommandResult result = null;

                    if (taskCommand is ProcessCommand)
                    {
                        // NB: ProcessCommands take care of their own impersonation
                        result = taskCommand.Execute();
                    }
                    else
                    {
                        using (Impersonator.GetContext(credential, shouldImpersonate))
                        {
                            result = taskCommand.Execute();
                        }
                    }

                    results.Add(result);
                }
                catch (Exception ex)
                {
                    log.TraceException("Error running command", ex);
                    results.Add(new TaskCommandResult(1, null, ex.Message));
                    break;
                }
            }

            return(FlattenResults(results));
        }