private Task SaveDllsAsync(CreateDistributedTaskDefinitionDTO body, Guid taskDefinitionGuid) { var taskDefinitionDirectoryPath = _pathsProvider.GetTaskDefinitionDirectoryPath(taskDefinitionGuid); var saveMainDllFileTask = _fileStorage.SaveFileAsync(taskDefinitionDirectoryPath, body.MainDll); var saveAdditionalDllsTask = _fileStorage.SaveFilesAsync(taskDefinitionDirectoryPath, body.AdditionalDlls); return(Task.WhenAll(saveMainDllFileTask, saveAdditionalDllsTask)); }
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; } }