public async STT.Task <IEnumerable <SAVM.Result> > CreateAndExecuteAsync(SAVM.Task task, CancellationToken ct) { // create the TaskEntity task = await CreateAsync(task, ct); // execute the TaskEntity. Authorization is null, because there can't be any subtasks on a CreateAndExecute. var resultList = await ExecuteAsync(task.Id, ct); return(resultList); }
public async STT.Task <SAVM.Task> UpdateAsync(Guid id, SAVM.Task task, CancellationToken ct) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) { throw new ForbiddenException(); } var taskToUpdate = await _context.Tasks.SingleOrDefaultAsync(v => v.Id == id, ct); if (taskToUpdate == null) { throw new EntityNotFoundException <SAVM.Task>(); } var vmListCount = task.VmList != null ? task.VmList.Count : 0; if (vmListCount > 0) { if (task.VmMask != "") { throw new InvalidOperationException("A Task cannot have BOTH a VmMask and a VmList!"); } // convert the list of vm guids into a comma separated string and save it in VmMask var vmIdString = ""; foreach (var vmId in task.VmList) { vmIdString = vmIdString + vmId + ","; } task.VmMask = vmIdString.Remove(vmIdString.Count() - 1); } task.CreatedBy = taskToUpdate.CreatedBy; task.DateCreated = taskToUpdate.DateCreated; task.DateModified = DateTime.UtcNow; task.ModifiedBy = _user.GetId(); _mapper.Map(task, taskToUpdate); _context.Tasks.Update(taskToUpdate); await _context.SaveChangesAsync(ct); var updatedTask = _mapper.Map(taskToUpdate, task); updatedTask.VmList = null; _engineHub.Clients.All.SendAsync(EngineMethods.TaskUpdated, updatedTask); return(updatedTask); }
public async STT.Task <SAVM.Task> CreateAsync(SAVM.Task task, CancellationToken ct) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) { throw new ForbiddenException(); } var vmListCount = task.VmList != null ? task.VmList.Count : 0; if (vmListCount > 0) { if (task.VmMask != "") { throw new InvalidOperationException("A Task cannot have BOTH a VmMask and a VmList!"); } // convert the list of vm guids into a comma separated string and save it in VmMask var vmIdString = ""; foreach (var vmId in task.VmList) { vmIdString = vmIdString + vmId + ","; } task.VmMask = vmIdString.Remove(vmIdString.Count() - 1); } if (task.ActionParameters.Keys.Any(key => key == "Moid")) { task.ActionParameters["Moid"] = "{moid}"; } task.DateCreated = DateTime.UtcNow; task.CreatedBy = _user.GetId(); task.UserId = _user.GetId(); task.Iterations = task.Iterations > 0 ? task.Iterations : 1; task.CurrentIteration = 0; var taskEntity = _mapper.Map <TaskEntity>(task); _context.Tasks.Add(taskEntity); await _context.SaveChangesAsync(ct); task = await GetAsync(taskEntity.Id, ct); _engineHub.Clients.All.SendAsync(EngineMethods.TaskCreated, task); return(task); }
public async STT.Task <IActionResult> Update([FromRoute] Guid id, [FromBody] SAVM.Task task, CancellationToken ct) { var updatedTask = await _TaskService.UpdateAsync(id, task, ct); return(Ok(updatedTask)); }
public async STT.Task <IActionResult> CreateAndExecute([FromBody] SAVM.Task task, CancellationToken ct) { var resultList = await _TaskService.CreateAndExecuteAsync(task, ct); return(Ok(resultList)); }
public async STT.Task <IActionResult> Create([FromBody] SAVM.Task task, CancellationToken ct) { var createdTask = await _TaskService.CreateAsync(task, ct); return(CreatedAtAction(nameof(this.Get), new { id = createdTask.Id }, createdTask)); }