Пример #1
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));
        }
Пример #2
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));
        }
Пример #3
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);
        }
Пример #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);
        }