public async Task <IActionResult> Dequeue(string agentId, string queueId) { try { var response = await manager.Dequeue(agentId, queueId); if (response == null) { ModelState.AddModelError("Dequeue", "No item to dequeue from list of queue items."); return(BadRequest(ModelState)); } //send SignalR notification to all connected clients await _hub.Clients.All.SendAsync("sendnotification", "Queue item dequeued."); QueueItemViewModel queueItemViewModel = new QueueItemViewModel(); queueItemViewModel = queueItemViewModel.Map(response); string id = response.Id.ToString(); queueItemViewModel = manager.GetQueueItemView(queueItemViewModel, id); await webhookPublisher.PublishAsync("QueueItems.QueueItemUpdated", queueItemViewModel.Id.ToString(), queueItemViewModel.Name).ConfigureAwait(false); return(Ok(queueItemViewModel)); } catch (Exception ex) { ModelState.AddModelError("Dequeue", ex.Message); return(BadRequest(ModelState)); } }
public async Task <IActionResult> View(string id) { try { var entity = repository.GetOne(new Guid(id)); if (entity == null) { throw new EntityDoesNotExistException("QueueItem does not exist or you do not have authorized access."); } _manager.UpdateItemsStates(entity.QueueId.ToString()); IActionResult actionResult = await base.GetEntity <QueueItemViewModel>(id); OkObjectResult okResult = actionResult as OkObjectResult; if (okResult != null) { QueueItemViewModel view = okResult.Value as QueueItemViewModel; var queueItem = repository.GetOne(Guid.Parse(id)); view = _manager.GetQueueItemView(queueItem); } return(actionResult); } catch (Exception ex) { return(ex.GetActionResult()); } }
public QueueItemViewModel UpdateAttachedFiles(QueueItem queueItem, UpdateQueueItemViewModel request) { if (queueItem == null) { throw new EntityDoesNotExistException("Queue item could not be found or does not exist"); } queueItem.DataJson = request.DataJson; queueItem.Event = request.Event; queueItem.ExpireOnUTC = request.ExpireOnUTC; queueItem.PostponeUntilUTC = request.PostponeUntilUTC; queueItem.Name = request.Name; queueItem.QueueId = request.QueueId.Value; queueItem.Source = request.Source; queueItem.Type = request.Type; queueItem.State = request.State; if (queueItem.State == "New") { queueItem.StateMessage = null; queueItem.RetryCount = 0; } //if files don't exist in file manager: add file entity, upload file, and add email attachment attachment entity var attachments = _queueItemAttachmentRepository.Find(null, q => q.QueueItemId == queueItem.Id)?.Items; string hash = string.Empty; IFormFile[] filesArray = CheckFiles(request.Files, hash, attachments, request.DriveName); var queueItemAttachments = new List <QueueItemAttachment>(); if (filesArray.Length > 0) { queueItemAttachments = AddNewAttachments(queueItem, filesArray, request.DriveName); } _repo.Update(queueItem); //attach new files QueueItemViewModel response = new QueueItemViewModel(); response = response.Map(queueItem); foreach (var attachment in attachments) { queueItemAttachments.Add(attachment); } response.Attachments = queueItemAttachments; return(response); }
public async Task <IActionResult> UpdateFiles(string id, [FromForm] UpdateQueueItemViewModel request) { var queueItem = repository.GetOne(Guid.Parse(id)); if (queueItem == null) { return(NotFound()); } queueItem.DataJson = request.DataJson; queueItem.Event = request.Event; queueItem.ExpireOnUTC = request.ExpireOnUTC; queueItem.PostponeUntilUTC = request.PostponeUntilUTC; queueItem.Name = request.Name; queueItem.QueueId = (Guid)request.QueueId; queueItem.Source = request.Source; queueItem.Type = request.Type; queueItem.State = request.State; if (queueItem.State == "New") { queueItem.StateMessage = null; queueItem.RetryCount = 0; } await webhookPublisher.PublishAsync("QueueItems.QueueItemUpdated", queueItem.Id.ToString(), queueItem.Name).ConfigureAwait(false); //attach new files var binaryObjects = manager.UpdateAttachedFiles(request, queueItem); foreach (var binaryObject in binaryObjects) { await webhookPublisher.PublishAsync("Files.NewFileCreated", binaryObject.Id.ToString(), binaryObject.Name).ConfigureAwait(false); } QueueItemViewModel response = new QueueItemViewModel(); response = response.Map(queueItem); var binaryObjectIds = new List <Guid?>(); foreach (var binaryObject in binaryObjects) { binaryObjectIds.Add(binaryObject.Id); } response.BinaryObjectIds = binaryObjectIds; return(Ok(response)); }
public QueueItemViewModel GetQueueItemView(QueueItem queueItem) { QueueItemViewModel queueItemViewModel = new QueueItemViewModel(); queueItemViewModel = queueItemViewModel.Map(queueItem); var attachmentsList = _queueItemAttachmentRepository.Find(null, q => q.QueueItemId == queueItem.Id)?.Items; if (attachmentsList != null) { queueItemViewModel.Attachments = attachmentsList; } else { queueItemViewModel.Attachments = null; } return(queueItemViewModel); }
public QueueItemViewModel GetQueueItemView(QueueItemViewModel queueItemView, string id) { var attachmentsList = queueItemAttachmentRepository.Find(null, q => q.QueueItemId == Guid.Parse(id))?.Items; if (attachmentsList != null) { List <Guid?> binaryObjectIds = new List <Guid?>(); foreach (var item in attachmentsList) { binaryObjectIds.Add(item.BinaryObjectId); } queueItemView.BinaryObjectIds = binaryObjectIds; } else { queueItemView.BinaryObjectIds = null; } return(queueItemView); }
public async Task <IActionResult> View(string id) { try { IActionResult actionResult = await base.GetEntity <QueueItemViewModel>(id); OkObjectResult okResult = actionResult as OkObjectResult; if (okResult != null) { QueueItemViewModel view = okResult.Value as QueueItemViewModel; view = manager.GetQueueItemView(view, id); } return(actionResult); } catch (Exception ex) { return(ex.GetActionResult()); } }
public async Task <IActionResult> View(string id) { try { IActionResult actionResult = await base.GetEntity <QueueItemViewModel>(id); OkObjectResult okResult = actionResult as OkObjectResult; if (okResult != null) { QueueItemViewModel view = okResult.Value as QueueItemViewModel; var queueItem = repository.GetOne(Guid.Parse(id)); view = _manager.GetQueueItemView(queueItem); } return(actionResult); } catch (Exception ex) { return(ex.GetActionResult()); } }
public async Task <IActionResult> Enqueue([FromBody] QueueItem request) { try { if (organizationSettingManager.HasDisallowedExecution()) { return(StatusCode(StatusCodes.Status405MethodNotAllowed, "Organization is set to DisallowExecution")); } var response = await manager.Enqueue(request); //check if a queue arrival schedule exists for this queue Schedule existingSchedule = scheduleRepo.Find(0, 1).Items?.Where(s => s.QueueId == response.QueueId)?.FirstOrDefault(); if (existingSchedule != null && existingSchedule.IsDisabled == false && existingSchedule.StartingType.ToLower().Equals("queuearrival")) { Schedule schedule = new Schedule(); schedule.AgentId = existingSchedule.AgentId; schedule.CRONExpression = ""; schedule.LastExecution = DateTime.UtcNow; schedule.NextExecution = DateTime.UtcNow; schedule.IsDisabled = false; schedule.ProjectId = null; schedule.StartingType = "QueueArrival"; schedule.Status = "New"; schedule.ExpiryDate = DateTime.UtcNow.AddDays(1); schedule.StartDate = DateTime.UtcNow; schedule.AutomationId = existingSchedule.AutomationId; var jsonScheduleObj = System.Text.Json.JsonSerializer.Serialize(schedule); //call GetScheduleParameters() var jobId = BackgroundJob.Enqueue(() => hubManager.ExecuteJob(jsonScheduleObj, Enumerable.Empty <ParametersViewModel>())); } QueueItem queueItem = new QueueItem() { CreatedBy = applicationUser.Name, CreatedOn = DateTime.UtcNow, DataJson = response.DataJson, Event = response.Event, ExpireOnUTC = response.ExpireOnUTC, IsLocked = response.IsLocked, JsonType = response.JsonType, Name = response.Name, PostponeUntilUTC = response.PostponeUntilUTC, Priority = response.Priority, QueueId = response.QueueId, RetryCount = response.RetryCount, Source = response.Source, State = response.State, StateMessage = response.StateMessage, Type = response.Type, PayloadSizeInBytes = 0 }; //create queue item IActionResult actionResult = await base.PostEntity(queueItem); await webhookPublisher.PublishAsync("QueueItems.NewQueueItemCreated", response.Id.ToString(), response.Name).ConfigureAwait(false); //send SignalR notification to all connected clients await _hub.Clients.All.SendAsync("sendnotification", "New queue item added."); QueueItemViewModel queueItemViewModel = new QueueItemViewModel(); queueItemViewModel = queueItemViewModel.Map(queueItem); string id = response.Id.ToString(); queueItemViewModel = manager.GetQueueItemView(queueItemViewModel, id); return(Ok(queueItemViewModel)); } catch (Exception ex) { ModelState.AddModelError("Enqueue", ex.Message); return(BadRequest(ModelState)); } }