public Automation UpdateAutomationFile(string id, AutomationViewModel request)
        {
            Guid entityId           = new Guid(id);
            var  existingAutomation = _repo.GetOne(entityId);

            if (existingAutomation == null)
            {
                throw new EntityDoesNotExistException($"Automation with id {id} could not be found");
            }

            string fileId = existingAutomation.FileId.ToString();

            if (string.IsNullOrEmpty(request.DriveId))
            {
                var fileToUpdate = _storageFileRepository.GetOne(existingAutomation.FileId.Value);
                request.DriveId = fileToUpdate.StorageDriveId.ToString();
            }

            var file = _fileManager.GetFileFolder(fileId, request.DriveId, "Files");

            if (file == null)
            {
                throw new EntityDoesNotExistException($"Automation file with id {fileId} could not be found or does not exist");
            }

            var response = AddAutomation(request);

            return(response);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] CreateJobViewModel request)
        {
            if (request == null)
            {
                ModelState.AddModelError("Save", "No data passed");
                return(BadRequest(ModelState));
            }

            Guid entityId = Guid.NewGuid();

            if (request.Id == null || !request.Id.HasValue || request.Id.Equals(Guid.Empty))
            {
                request.Id = entityId;
            }
            try
            {
                Job        job        = request.Map(request); //assign request to job entity
                Automation automation = automationRepo.GetOne(job.AutomationId ?? Guid.Empty);

                if (automation == null) //no automation was found
                {
                    ModelState.AddModelError("Save", "No automation was found for the specified automation id");
                    return(NotFound(ModelState));
                }
                AutomationVersion automationVersion = automationVersionRepo.Find(null, q => q.AutomationId == automation.Id).Items?.FirstOrDefault();

                job.AutomationVersion   = automationVersion.VersionNumber;
                job.AutomationVersionId = automationVersion.Id;

                foreach (var parameter in request.JobParameters ?? Enumerable.Empty <JobParameter>())
                {
                    parameter.JobId     = entityId;
                    parameter.CreatedBy = applicationUser?.UserName;
                    parameter.CreatedOn = DateTime.UtcNow;
                    parameter.Id        = Guid.NewGuid();
                    jobParameterRepo.Add(parameter);
                }

                //send SignalR notification to all connected clients
                await _hub.Clients.All.SendAsync("botnewjobnotification", request.AgentId.ToString());

                await _hub.Clients.All.SendAsync("sendjobnotification", "New Job added.");

                await _hub.Clients.All.SendAsync("broadcastnewjobs", Tuple.Create(request.Id, request.AgentId, request.AutomationId));

                await webhookPublisher.PublishAsync("Jobs.NewJobCreated", job.Id.ToString()).ConfigureAwait(false);


                return(await base.PostEntity(job));
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }
Exemplo n.º 3
0
        public AutomationExecutionViewModel GetExecutionView(AutomationExecutionViewModel executionView)
        {
            executionView.AgentName      = agentRepo.GetOne(executionView.AgentID)?.Name;
            executionView.AutomationName = automationRepo.GetOne(executionView.AutomationID)?.Name;

            return(executionView);
        }
Exemplo n.º 4
0
        public JobViewModel GetJobView(JobViewModel jobView)
        {
            jobView.AgentName      = agentRepo.GetOne(jobView.AgentId ?? Guid.Empty)?.Name;
            jobView.AutomationName = automationRepo.GetOne(jobView.AutomationId ?? Guid.Empty)?.Name;
            jobView.JobParameters  = GetJobParameters(jobView.Id ?? Guid.Empty);

            return(jobView);
        }
Exemplo n.º 5
0
        public ScheduleViewModel GetScheduleViewModel(ScheduleViewModel scheduleView)
        {
            scheduleView.AgentName          = agentRepository.GetOne(scheduleView.AgentId ?? Guid.Empty)?.Name;
            scheduleView.AutomationName     = automationRepository.GetOne(scheduleView.AutomationId ?? Guid.Empty)?.Name;
            scheduleView.ScheduleParameters = GetScheduleParameters(scheduleView.Id ?? Guid.Empty);

            return(scheduleView);
        }
Exemplo n.º 6
0
        public Job UpdateJob(string jobId, CreateJobViewModel request, ApplicationUser applicationUser)
        {
            Guid entityId = new Guid(jobId);

            var existingJob = _repo.GetOne(entityId);

            if (existingJob == null)
            {
                throw new EntityDoesNotExistException("Unable to find a job for the specified id");
            }

            Automation automation = _automationRepo.GetOne(existingJob.AutomationId ?? Guid.Empty);

            if (automation == null) //no automation was found
            {
                throw new EntityDoesNotExistException("No automation was found for the specified automation id");
            }

            AutomationVersion automationVersion = _automationVersionRepo.Find(null, q => q.AutomationId == automation.Id).Items?.FirstOrDefault();

            existingJob.AutomationVersion   = automationVersion.VersionNumber;
            existingJob.AutomationVersionId = automationVersion.Id;

            existingJob.AgentId                = request.AgentId;
            existingJob.AgentGroupId           = request.AgentGroupId;
            existingJob.StartTime              = request.StartTime;
            existingJob.EndTime                = request.EndTime;
            existingJob.ExecutionTimeInMinutes = (existingJob.EndTime.Value - existingJob.StartTime).Value.TotalMinutes;
            existingJob.DequeueTime            = request.DequeueTime;
            existingJob.AutomationId           = request.AutomationId;
            existingJob.JobStatus              = request.JobStatus;
            existingJob.Message                = request.Message;
            existingJob.IsSuccessful           = request.IsSuccessful;

            UpdateJobParameters(request.JobParameters, existingJob.Id);

            if (request.EndTime != null)
            {
                UpdateAutomationAverages(existingJob.Id);
            }

            return(existingJob);
        }
Exemplo n.º 7
0
        public Automation UpdateAutomationFile(string id, AutomationViewModel request)
        {
            Guid entityId           = new Guid(id);
            var  existingAutomation = _repo.GetOne(entityId);

            if (existingAutomation == null)
            {
                throw new EntityDoesNotExistException($"Automation with id {id} could not be found");
            }

            string fileId = existingAutomation.FileId.ToString();
            var    file   = _fileManager.GetFileFolder(fileId, request.DriveName);

            if (file == null)
            {
                throw new EntityDoesNotExistException($"Automation file with id {fileId} could not be found");
            }

            var response = AddAutomation(request);

            return(response);
        }
Exemplo n.º 8
0
        public bool DeleteAutomation(Guid automationId)
        {
            var automation = repo.GetOne(automationId);

            //remove automation version entity associated with automation
            var  automationVersion   = automationVersionRepository.Find(null, q => q.AutomationId == automationId).Items?.FirstOrDefault();
            Guid automationVersionId = (Guid)automationVersion.Id;

            automationVersionRepository.SoftDelete(automationVersionId);

            bool isDeleted = false;

            if (automation != null)
            {
                //remove binary object entity associated with automation
                binaryObjectRepository.SoftDelete(automation.BinaryObjectId);
                repo.SoftDelete(automation.Id.Value);

                isDeleted = true;
            }

            return(isDeleted);
        }