Esempio n. 1
0
        public async Task <IActionResult> PostRelationshipAsync(int bookId, [FromBody] Review review)
        {
            review.BookId = bookId;
            var result = await _reviewService.CreateAsync(review);

            return(Ok(result));
        }
Esempio n. 2
0
        public async Task <IActionResult> PostRelationshipAsync(int authorId, [FromBody] Book book)
        {
            book.AuthorId = authorId;
            var result = await _bookService.CreateAsync(book);

            return(Ok(result));
        }
        public async Task <IHttpActionResult> PostAsync([FromBody] ResourceRequest request)
        {
            var resourceResponse = await _resourceService.CreateAsync(request.Name);

            var result = _mapper.Map <ResourceResponse>(resourceResponse);

            return(Ok(result));
        }
Esempio n. 4
0
        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> Index([FromBody] Dictionary <string, object> data)
        {
            var message      = data["message"] as string;
            var user         = _userService.GetCurrentUser().Result;
            var notification = new Notification()
            {
                User    = user,
                Message = message
            };

            notification = await _notificationService.CreateAsync(notification);

            await _hubContext.Clients.User(user.ExternalId).SendAsync("Notification", notification.Id);

            return(NoContent());
        }
Esempio n. 6
0
        public async Task <IActionResult> AssignNextAsync([FromBody] AssignNextSubtaskDTO body)
        {
            if (!Guid.TryParse(body.DistributedNodeId, out var distributedNodeId))
            {
                return(BadRequest()); // TODO: specify the reason
            }
            var distributedNode = await _distributedNodeResourceService.GetAsync(distributedNodeId);

            if (distributedNode == null)
            {
                return(NotFound()); // TODO: specify the reason
            }
            var nextSubtask = await _getNextSubtaskToComputeService.GetNextSubtaskAsync();

            if (nextSubtask == null)
            {
                return(NotFound()); // TODO: specify the reason
            }
            var subtaskInProgress = new SubtaskInProgress
            {
                Node    = distributedNode,
                Status  = SubtaskInProgressStatus.Executing,
                Subtask = nextSubtask
            };

            var createdSubtaskInProgress = await _subtaskInProgressResourceService.CreateAsync(subtaskInProgress);

            nextSubtask.Status = SubtaskStatus.Executing;
            _dbContext.Subtasks.Update(nextSubtask);
            await _dbContext.SaveChangesAsync();

            var distributedTaskDefinition = await GetSubtasksDistributedTaskDefinition(nextSubtask);

            var response = new AssignNextSubtaskResultDTO()
            {
                CompiledTaskDefinitionURL =
                    _pathsProvider.GetCompiledTaskDefinitionWebPath(distributedTaskDefinition.DefinitionGuid),
                SubtaskId           = nextSubtask.StringId,
                ProblemPluginInfo   = distributedTaskDefinition.ProblemPluginInfo,
                SubtaskInProgressId = createdSubtaskInProgress.StringId
            };

            return(Created($"/subtasks-in-progress/{createdSubtaskInProgress.Id}", response));
        }
Esempio n. 7
0
        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));
        }
 public Task CreateAsync([FromBody] ResourceDto createResource)
 {
     return(_resourceService.CreateAsync(createResource));
 }
Esempio n. 9
0
 public async Task <IActionResult> Put([FromBody] ResourceDto resource)
 {
     return(Success(await _resourceService.CreateAsync(resource)));
 }