Пример #1
0
        public void SendTaskErrorEmail(EntityActiveImagingTask task, string error)
        {
            //Mail not enabled
            if (ServiceSetting.GetSettingValue(SettingStrings.SmtpEnabled) == "0")
            {
                return;
            }
            var computer = new ServiceComputer().GetComputer(task.ComputerId);

            foreach (
                var user in
                _userServices.GetAll().Where(x => !string.IsNullOrEmpty(x.Email)))
            {
                var rights = new ServiceUser().GetUserRights(user.Id).Select(right => right.Right).ToList();
                if (rights.Any(right => right == AuthorizationStrings.EmailImagingTaskFailed))
                {
                    if (task.UserId == user.Id)
                    {
                        if (computer == null)
                        {
                            computer      = new EntityComputer();
                            computer.Name = "Unknown Computer";
                        }
                        var mail = new MailServices
                        {
                            MailTo  = user.Email,
                            Body    = computer.Name + " Image Task Has Failed. " + error,
                            Subject = "Task Failed"
                        };
                        mail.Send();
                    }
                }
            }
        }
Пример #2
0
 public EntityActiveImagingTask GetNextComputerInQueue(EntityActiveImagingTask activeTask)
 {
     return
         (_uow.ActiveImagingTaskRepository.Get(
              x => x.Status == EnumTaskStatus.ImagingStatus.InImagingQueue && x.Type == activeTask.Type && x.ComServerId == activeTask.ComServerId,
              q => q.OrderBy(t => t.QueuePosition)).FirstOrDefault());
 }
Пример #3
0
 public int GetCurrentQueue(EntityActiveImagingTask activeTask)
 {
     return
         (Convert.ToInt32(
              _uow.ActiveImagingTaskRepository.Count(
                  x => x.Status == EnumTaskStatus.ImagingStatus.Imaging && x.Type == activeTask.Type && x.ComServerId == activeTask.ComServerId)));
 }
Пример #4
0
        private bool CreateComputerTasks()
        {
            var error                     = false;
            var activeTaskIds             = new List <int>();
            var activeImagingTaskServices = new ServiceActiveImagingTask();

            foreach (var computer in _computers)
            {
                if (_computerServices.IsComputerActive(computer.Id))
                {
                    return(false);
                }
                var activeTask = new EntityActiveImagingTask
                {
                    Type           = "multicast",
                    ComputerId     = computer.Id,
                    Direction      = "deploy",
                    MulticastId    = _multicastSession.Id,
                    UserId         = _userId,
                    ImageProfileId = _imageProfile.Id
                };

                if (activeImagingTaskServices.AddActiveImagingTask(activeTask))
                {
                    activeTaskIds.Add(activeTask.Id);
                }
                else
                {
                    error = true;
                    break;
                }
            }
            if (error)
            {
                foreach (var taskId in activeTaskIds)
                {
                    activeImagingTaskServices.DeleteActiveImagingTask(taskId);
                }

                return(false);
            }
            return(true);
        }
Пример #5
0
 public bool AddActiveImagingTask(EntityActiveImagingTask activeImagingTask)
 {
     _uow.ActiveImagingTaskRepository.Insert(activeImagingTask);
     _uow.Save();
     return(true);
 }
Пример #6
0
 public bool UpdateActiveImagingTask(EntityActiveImagingTask activeImagingTask)
 {
     _uow.ActiveImagingTaskRepository.Update(activeImagingTask, activeImagingTask.Id);
     _uow.Save();
     return(true);
 }
Пример #7
0
 public string GetQueuePosition(EntityActiveImagingTask task)
 {
     return
         (_uow.ActiveImagingTaskRepository.Count(
              x => x.Status == EnumTaskStatus.ImagingStatus.InImagingQueue && x.QueuePosition < task.QueuePosition));
 }
Пример #8
0
        public string Start()
        {
            if (_computer == null)
            {
                return("The Computer Does Not Exist");
            }

            if (_group != null)
            {
                //unicast started via group, use that groups assigned image
                _imageProfile = new ServiceImageProfile().ReadProfile(_group.ImageProfileId);
                if (_imageProfile == null)
                {
                    return("The Image Profile Doesn't Exist");
                }
            }
            else
            {
                _imageProfile = new ServiceComputer().GetEffectiveImage(_computer.Id);
            }

            if (_imageProfile == null)
            {
                return("No Image Has Been Selected");
            }

            if (_imageProfile.Image == null)
            {
                return("The Image Does Not Exist");
            }

            if (new ServiceComputer().IsComputerActive(_computer.Id))
            {
                return("This Computer Is Already Part Of An Active Task");
            }

            _activeTask = new EntityActiveImagingTask
            {
                ComputerId     = _computer.Id,
                Direction      = _direction,
                UserId         = _userId,
                ImageProfileId = _imageProfile.Id
            };

            _activeTask.Type = _direction;

            var activeImagingTaskServices = new ServiceActiveImagingTask();

            if (!activeImagingTaskServices.AddActiveImagingTask(_activeTask))
            {
                return("Could Not Create The Database Entry For This Task");
            }

            if (!new TaskBootMenu().RunAllServers(_computer, _imageProfile))
            {
                activeImagingTaskServices.DeleteActiveImagingTask(_activeTask.Id);
                return("Could Not Create PXE Boot File");
            }

            _activeTask.Arguments = new CreateTaskArguments(_computer, _imageProfile, _direction).Execute();
            if (!activeImagingTaskServices.UpdateActiveImagingTask(_activeTask))
            {
                activeImagingTaskServices.DeleteActiveImagingTask(_activeTask.Id);
                return("Could Not Create Task Arguments");
            }

            new ServiceComputer().Wakeup(_computer.Id);

            var auditLog = new EntityAuditLog();

            switch (_direction)
            {
            case "deploy":
                auditLog.AuditType = EnumAuditEntry.AuditType.Deploy;
                break;

            default:
                auditLog.AuditType = EnumAuditEntry.AuditType.Upload;
                break;
            }

            auditLog.ObjectId = _computer.Id;
            var user = new ServiceUser().GetUser(_userId);

            if (user != null)
            {
                auditLog.UserName = user.Name;
            }
            auditLog.ObjectName = _computer.Name;
            auditLog.UserId     = _userId;
            auditLog.ObjectType = "Computer";
            auditLog.ObjectJson = JsonConvert.SerializeObject(_activeTask);
            new ServiceAuditLog().AddAuditLog(auditLog);

            auditLog.ObjectId   = _imageProfile.ImageId;
            auditLog.ObjectName = _imageProfile.Image.Name;
            auditLog.ObjectType = "Image";
            new ServiceAuditLog().AddAuditLog(auditLog);

            return("Successfully Started Task For " + _computer.Name);
        }