public async Task <IActionResult> PostAsync([FromForm] CreateDistributedTaskDefinitionDTO body) { var taskDefinitionGuid = Guid.NewGuid(); var mainDllName = body.MainDll.FileName; ProblemPluginInfo problemPluginInfo; await SaveDllsAsync(body, taskDefinitionGuid); try { problemPluginInfo = AnalyzeAssembly(taskDefinitionGuid, mainDllName); } catch (InvalidAssemblyException exception) { DeleteSavedDlls(taskDefinitionGuid); return(Error(new Error(StatusCodes.Status400BadRequest, exception.Message, exception.InnerException?.Message))); } catch (Exception exception) { DeleteSavedDlls(taskDefinitionGuid); _logger.LogWarning(exception, "Exception occurred when analyzing the assembly"); return(Error(new Error(StatusCodes.Status500InternalServerError, "Internal Server Error when analyzing the assembly"))); } // TODO: handle packager errors and display them to the user var packagerLogs = await PackAssemblyAsync(taskDefinitionGuid, mainDllName); var distributedTaskDefinition = new DistributedTaskDefinition { Name = body.Name, Description = body.Description ?? "", DefinitionGuid = taskDefinitionGuid, ProblemPluginInfo = problemPluginInfo, MainDllName = mainDllName, PackagerLogs = packagerLogs }; try { var createdTaskDefinition = await _taskDefinitionResourceService.CreateAsync(distributedTaskDefinition); HttpContext.Response.StatusCode = StatusCodes.Status201Created; return(await _jsonApiResponseFactory.CreateResponseAsync(HttpContext.Response, createdTaskDefinition)); } catch { DeleteSavedDlls(taskDefinitionGuid); DeletePackagerResults(taskDefinitionGuid); throw; } }
public async Task <IActionResult> PostAsync([FromForm] CreateDistributedTaskDTO body) { var distributedTask = new DistributedTask { DistributedTaskDefinitionId = body.DistributedTaskDefinitionId, Priority = body.Priority, Name = body.Name, Description = body.Description ?? "", InputData = new byte[body.InputData.Length], TrustLevelToComplete = body.TrustLevelToComplete, }; var memoryStream = new MemoryStream(distributedTask.InputData); await body.InputData.CopyToAsync(memoryStream); var createdDistributedTask = await _distributedTaskResourceService.CreateAsync(distributedTask); HttpContext.Response.StatusCode = StatusCodes.Status201Created; return(await _jsonApiResponseFactory.CreateResponseAsync(HttpContext.Response, createdDistributedTask)); }