Exemple #1
0
 public async Task <GruntTasking> StartTask(Grunt grunt, GruntTask task, GruntCommand command)
 {
     return(await _context.CreateGruntTasking(new GruntTasking
     {
         GruntTaskId = task.Id,
         GruntId = grunt.Id,
         Type = task.TaskingType,
         Status = GruntTaskingStatus.Uninitialized,
         GruntCommandId = command.Id,
         GruntCommand = command
     }, _grunthub));
 }
Exemple #2
0
        // POST: /grunttasking/create
        public async Task <IActionResult> Create(GruntTasking tasking)
        {
            try
            {
                CovenantUser currentUser = await _context.GetCurrentUser(_userManager, HttpContext.User);

                tasking.Grunt = await _context.GetGrunt(tasking.GruntId);

                tasking.GruntTask = await _context.GetGruntTask(tasking.GruntTaskId);

                GruntCommand createdCommand = await _context.CreateGruntCommand(new GruntCommand
                {
                    Command         = GetCommand(tasking),
                    CommandTime     = DateTime.UtcNow,
                    CommandOutputId = 0,
                    CommandOutput   = new CommandOutput(),
                    User            = currentUser,
                    GruntId         = tasking.Grunt.Id,
                    Grunt           = tasking.Grunt
                }, _grunthub);

                tasking.GruntCommand   = createdCommand;
                tasking.GruntCommandId = createdCommand.Id;

                GruntTasking created = await _context.CreateGruntTasking(tasking);

                return(RedirectToAction(nameof(Interact), new { id = created.Id }));
            }
            catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
Exemple #3
0
        // POST: /grunttasking/create
        public async Task <IActionResult> Create(GruntTasking tasking)
        {
            try
            {
                CovenantUser currentUser = await _context.GetCurrentUser(_userManager, HttpContext.User);

                tasking.Grunt = await _context.GetGrunt(tasking.GruntId);

                tasking.GruntTask = await _context.GetGruntTask(tasking.GruntTaskId);

                tasking.Type = tasking.GruntTask.TaskingType;
                for (int i = 0; i < Math.Min(tasking.Parameters.Count, tasking.GruntTask.Options.Count); i++)
                {
                    if (tasking.Parameters[i] == null)
                    {
                        tasking.Parameters[i] = "";
                        tasking.GruntTask.Options[i].Value = "";
                    }
                    else
                    {
                        tasking.GruntTask.Options[i].Value = tasking.Parameters[i];
                    }
                }
                for (int i = tasking.Parameters.Count; i < tasking.GruntTask.Options.Count; i++)
                {
                    tasking.GruntTask.Options[i].Value = "";
                }
                GruntCommand createdCommand = await _context.CreateGruntCommand(new GruntCommand
                {
                    Command         = GetCommand(tasking),
                    CommandTime     = DateTime.UtcNow,
                    CommandOutputId = 0,
                    CommandOutput   = new CommandOutput(),
                    User            = currentUser,
                    GruntId         = tasking.Grunt.Id,
                    Grunt           = tasking.Grunt
                }, _grunthub, _eventhub);

                tasking.GruntCommand   = createdCommand;
                tasking.GruntCommandId = createdCommand.Id;

                GruntTasking created = await _context.CreateGruntTasking(tasking, _grunthub);

                return(RedirectToAction(nameof(Interact), new { id = created.Id }));
            }
            catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
        public async Task <ActionResult <GruntTasking> > CreateGruntTasking([FromBody] GruntTasking gruntTasking)
        {
            try
            {
                GruntTasking tasking = await _context.CreateGruntTasking(_userManager, HttpContext.User, gruntTasking, _grunthub);

                return(CreatedAtRoute(nameof(GetGruntTasking), new { tid = tasking.Id }, tasking));
            }
            catch (ControllerNotFoundException e)
            {
                return(NotFound(e.Message));
            }
            catch (ControllerBadRequestException e)
            {
                return(BadRequest(e.Message));
            }
        }