Beispiel #1
0
 public static bool AddActiveImagingTask(Models.ActiveImagingTask activeImagingTask)
 {
     using (var uow = new DAL.UnitOfWork())
     {
         uow.ActiveImagingTaskRepository.Insert(activeImagingTask);
         return(uow.Save());
     }
 }
Beispiel #2
0
 public static bool UpdateActiveImagingTask(Models.ActiveImagingTask activeImagingTask)
 {
     using (var uow = new DAL.UnitOfWork())
     {
         uow.ActiveImagingTaskRepository.Update(activeImagingTask, activeImagingTask.Id);
         return(uow.Save());
     }
 }
Beispiel #3
0
        public string Start()
        {
            if (_computer == null)
                return "The Computer Does Not Exist";

            _imageProfile = ImageProfile.ReadProfile(_computer.ImageProfileId);
            if (_imageProfile == null) return "The Image Profile Does Not Exist";

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

            if (_direction == "push" || _direction == "permanent_push")
            {
                var validation = Image.CheckApprovalAndChecksum(_imageProfile.Image,_userId);
                if (!validation.IsValid) return validation.Message;
            }

            var dp = BLL.DistributionPoint.GetPrimaryDistributionPoint();
            if (dp == null) return "Could Not Find A Primary Distribution Point";

            if (ActiveImagingTask.IsComputerActive(_computer.Id))
                return "This Computer Is Already Part Of An Active Task";

            _activeTask = new Models.ActiveImagingTask
            {
                ComputerId = _computer.Id,
                Direction = _direction,
                UserId = _userId
            };

            _activeTask.Type = _direction == "permanent_push" ? "permanent_push" : "unicast";

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

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

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

            Utility.WakeUp(_computer.Mac);

            return "Successfully Started Task For " + _computer.Name;
        }
Beispiel #4
0
        private bool CreateComputerTasks()
        {
            var error         = false;
            var activeTaskIds = new List <int>();

            foreach (var computer in _computers)
            {
                if (ActiveImagingTask.IsComputerActive(computer.Id))
                {
                    return(false);
                }
                var activeTask = new Models.ActiveImagingTask
                {
                    Type        = "multicast",
                    ComputerId  = computer.Id,
                    Direction   = "push",
                    MulticastId = _multicastSession.Id,
                    UserId      = _userId
                };

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

                return(false);
            }
            return(true);
        }
Beispiel #5
0
 public static void SendTaskErrorEmail(Models.ActiveImagingTask task, string error)
 {
     //Mail not enabled
     if (Settings.SmtpEnabled == "0")
     {
         return;
     }
     task.Computer = BLL.Computer.GetComputer(task.ComputerId);
     foreach (var user in BLL.User.SearchUsers("").Where(x => x.NotifyError == 1 && !string.IsNullOrEmpty(x.Email)))
     {
         if (task.UserId == user.Id)
         {
             var mail = new Helpers.Mail
             {
                 MailTo  = user.Email,
                 Body    = task.Computer.Name + " Image Task Has Failed. " + error,
                 Subject = "Task Failed"
             };
             mail.Send();
         }
     }
 }
Beispiel #6
0
        private bool CreateComputerTasks()
        {
            var error = false;
            var activeTaskIds = new List<int>();
            foreach (var computer in _computers)
            {
                if (ActiveImagingTask.IsComputerActive(computer.Id)) return false;
                var activeTask = new Models.ActiveImagingTask
                {
                    Type = "multicast",
                    ComputerId = computer.Id,
                    Direction = "push",
                    MulticastId = _multicastSession.Id,
                    UserId = _userId

                };

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

                return false;
            }
            return true;
        }
Beispiel #7
0
        public string Start()
        {
            if (_computer == null)
            {
                return("The Computer Does Not Exist");
            }

            _imageProfile = ImageProfile.ReadProfile(_computer.ImageProfileId);
            if (_imageProfile == null)
            {
                return("The Image Profile Does Not Exist");
            }

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

            if (_direction == "push" || _direction == "permanent_push")
            {
                var validation = Image.CheckApprovalAndChecksum(_imageProfile.Image, _userId);
                if (!validation.IsValid)
                {
                    return(validation.Message);
                }
            }

            var dp = BLL.DistributionPoint.GetPrimaryDistributionPoint();

            if (dp == null)
            {
                return("Could Not Find A Primary Distribution Point");
            }

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

            _activeTask = new Models.ActiveImagingTask
            {
                ComputerId = _computer.Id,
                Direction  = _direction,
                UserId     = _userId
            };

            _activeTask.Type = _direction == "permanent_push" ? "permanent_push" : "unicast";

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

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

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

            Utility.WakeUp(_computer.Mac);

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