Beispiel #1
0
        public static void OnEditPriority(this JobQueueJob jqj, JobQueuePriority Priority)
        {
            if (!jqj.CanEditPriority())
                throw new InvalidOperationException("Editing job priority for this queue is denied");

            jqj.Priority = Priority;
        }
        public virtual ActionResult AddJob(int id, int JobId, string Comment, int? SLAExpiresMinutes, JobQueuePriority Priority)
        {
            DateTime? SLAExpires = (SLAExpiresMinutes.HasValue && SLAExpiresMinutes.Value > 0) ? DateTime.Now.AddMinutes(SLAExpiresMinutes.Value) : (DateTime?)null;

            var jobQueueToken = JobQueueService.GetQueue(id);
            if (jobQueueToken == null)
                throw new ArgumentException("Invalid Job Queue Id", "id");

            var job = Database.Jobs.Include("JobQueues").FirstOrDefault(j => j.Id == JobId);
            if (job == null)
                throw new ArgumentException("Invalid Job Id", "JobId");

            if (!job.CanAddQueue(jobQueueToken.JobQueue))
                throw new InvalidOperationException("Adding job to queue is Denied");

            var jobQueueJob = job.OnAddQueue(Database, jobQueueToken.JobQueue, CurrentUser, Comment, SLAExpires, Priority);
            Database.SaveChanges();

            return Redirect(string.Format("{0}#jobDetailTab-Queues", Url.Action(MVC.Job.Show(job.Id))));
        }
Beispiel #3
0
        public static JobQueueJob OnAddQueue(this Job j, DiscoDataContext Database, JobQueue jq, User Technician, string Comment, DateTime? SLAExpires, JobQueuePriority Priority)
        {
            if (!j.CanAddQueue(jq))
                throw new InvalidOperationException("Adding job to queue is denied");

            if (SLAExpires.HasValue && SLAExpires.Value < DateTime.Now)
                throw new ArgumentException("The SLA Date must be greater than the current time", "SLAExpires");

            var jqj = new JobQueueJob()
            {
                JobQueueId = jq.Id,
                JobId = j.Id,
                AddedDate = DateTime.Now,
                AddedUserId = Technician.UserId,
                AddedComment = string.IsNullOrWhiteSpace(Comment) ? null : Comment.Trim(),
                SLAExpiresDate = SLAExpires,
                Priority = Priority
            };

            Database.JobQueueJobs.Add(jqj);
            return jqj;
        }