public List <ImageWithDate> FilterClassifications(int groupId, List <ImageWithDate> listImages)
        {
            var filteredImageList    = new List <ImageWithDate>();
            var imageClassifications = new GroupServices().GetGroupImageClassifications(groupId);

            if (imageClassifications == null)
            {
                return(listImages);
            }
            if (imageClassifications.Count == 0)
            {
                return(listImages);
            }
            foreach (var image in listImages)
            {
                if (image.ClassificationId == -1)
                {
                    //Image has no classification, add it
                    filteredImageList.Add(image);
                    continue;
                }

                foreach (var classification in imageClassifications)
                {
                    if (image.ClassificationId == classification.ImageClassificationId)
                    {
                        filteredImageList.Add(image);
                        break;
                    }
                }
            }

            return(filteredImageList);
        }
        public ActionResultDTO AddMembership(List <GroupMembershipEntity> groupMemberships)
        {
            var group        = new GroupEntity();
            var actionResult = new ActionResultDTO();

            foreach (var membership in groupMemberships.Where(membership => !_uow.GroupMembershipRepository.Exists(
                                                                  g => g.ComputerId == membership.ComputerId && g.GroupId == membership.GroupId)))
            {
                _uow.GroupMembershipRepository.Insert(membership);
                group = new GroupServices().GetGroup(membership.GroupId);
            }
            _uow.Save();
            actionResult.Success = true;

            if (group.SetDefaultProperties == 1)
            {
                var groupProperty = new GroupServices().GetGroupProperty(group.Id);
                new GroupPropertyServices().UpdateComputerProperties(groupProperty);
            }

            if (group.SetDefaultBootMenu == 1)
            {
                var groupBootMenu = new GroupServices().GetGroupBootMenu(group.Id);
                new GroupBootMenuServices().UpdateGroupMemberBootMenus(groupBootMenu);
            }

            return(actionResult);
        }
        public ActionResultDTO DeleteProfile(int profileId)
        {
            var profile = ReadProfile(profileId);

            if (profile == null)
            {
                return new ActionResultDTO {
                           ErrorMessage = "Image Profile Was Not Found", Id = 0
                }
            }
            ;
            _uow.ImageProfileRepository.Delete(profileId);

            _uow.Save();
            var computers       = _uow.ComputerRepository.Get(x => x.ImageProfileId == profileId);
            var computerService = new ComputerServices();

            foreach (var computer in computers)
            {
                computer.ImageProfileId = -1;

                computerService.UpdateComputer(computer);
            }

            var groups       = _uow.GroupRepository.Get(x => x.ImageProfileId == profileId);
            var groupService = new GroupServices();

            foreach (var group in groups)
            {
                group.ImageProfileId = -1;
                groupService.UpdateGroup(group);
            }

            var groupProperties      = _uow.GroupPropertyRepository.Get(x => x.ImageProfileId == profileId);
            var groupPropertyService = new GroupPropertyServices();

            foreach (var groupProperty in groupProperties)
            {
                groupProperty.ImageProfileId = -1;
                groupPropertyService.UpdateGroupProperty(groupProperty);
            }

            var actionResult = new ActionResultDTO();

            actionResult.Success = true;
            actionResult.Id      = profile.Id;

            return(actionResult);
        }
Example #4
0
        public void AddComputerToSmartGroups(ComputerEntity computer)
        {
            var groups = new GroupServices().SearchGroups();

            foreach (var group in groups.Where(x => x.Type == "smart"))
            {
                var computers =
                    SearchComputersByName(group.SmartCriteria, int.MaxValue, group.SmartType).Where(x => x.Name == computer.Name);
                var memberships =
                    computers.Select(comp => new GroupMembershipEntity {
                    GroupId = @group.Id, ComputerId = comp.Id
                })
                    .ToList();
                new GroupMembershipServices().AddMembership(memberships);
            }
        }
        public ActionResultDTO AddClassifications(List <GroupImageClassificationEntity> listOfClassifications)
        {
            foreach (var classification in listOfClassifications)
            {
                _uow.GroupImageClassificationRepository.Insert(classification);
            }

            _uow.Save();
            var actionResult = new ActionResultDTO();

            actionResult.Success = true;

            var firstClass = listOfClassifications.FirstOrDefault();

            if (firstClass != null)
            {
                var groupProperties = new GroupServices().GetGroupProperty(firstClass.GroupId);
                if (groupProperties == null)
                {
                    return(actionResult);
                }

                if (Convert.ToBoolean(groupProperties.ImageClassificationsEnabled))
                {
                    foreach (var computer in new GroupServices().GetGroupMembersWithImages(groupProperties.GroupId))
                    {
                        var computerImageClassifications = new List <ComputerImageClassificationEntity>();
                        if (new ComputerServices().DeleteComputerImageClassifications(computer.Id))
                        {
                            foreach (var imageClass in listOfClassifications)
                            {
                                computerImageClassifications.Add(
                                    new ComputerImageClassificationEntity
                                {
                                    ComputerId            = computer.Id,
                                    ImageClassificationId = imageClass.ImageClassificationId
                                });
                            }
                        }
                        new ComputerImageClassificationServices().AddClassifications(computerImageClassifications);
                    }
                }
            }

            return(actionResult);
        }
Example #6
0
        public string CheckIn(string taskId)
        {
            var checkIn          = new CheckIn();
            var computerServices = new ComputerServices();

            var task = new ActiveImagingTaskServices().GetTask(Convert.ToInt32(taskId));

            if (task == null)
            {
                checkIn.Result  = "false";
                checkIn.Message = "Could Not Find Task With Id" + taskId;
                return(JsonConvert.SerializeObject(checkIn));
            }

            var computer = computerServices.GetComputer(task.ComputerId);

            if (computer == null)
            {
                checkIn.Result  = "false";
                checkIn.Message = "The Computer Assigned To This Task Was Not Found";
                return(JsonConvert.SerializeObject(checkIn));
            }

            var imageDistributionPoint = new GetImageServer(computer, task.Type).Run();

            task.Status = "1";
            task.DpId   = imageDistributionPoint;

            ImageEntity image = null;

            if (task.Type == "multicast")
            {
                var mcTask = new ActiveMulticastSessionServices().Get(task.MulticastId);
                var group  = new GroupServices().GetGroupByName(mcTask.Name);
                image = new ImageServices().GetImage(group.ImageId);
            }
            else
            {
                image = new ImageServices().GetImage(computer.ImageId);
            }
            if (image.Protected == 1 && task.Type.Contains("upload"))
            {
                checkIn.Result  = "false";
                checkIn.Message = "This Image Is Protected";
                return(JsonConvert.SerializeObject(checkIn));
            }

            if (new ActiveImagingTaskServices().UpdateActiveImagingTask(task))
            {
                checkIn.Result = "true";

                if (image != null)
                {
                    if (image.Environment == "")
                    {
                        image.Environment = "linux";
                    }
                    checkIn.ImageEnvironment = image.Environment;
                }

                if (image.Environment == "winpe")
                {
                    checkIn.TaskArguments = task.Arguments + "dp_id=\"" +
                                            imageDistributionPoint + "\"\r\n";
                }
                else
                {
                    checkIn.TaskArguments = task.Arguments + " dp_id=\"" +
                                            imageDistributionPoint + "\"";
                }
                return(JsonConvert.SerializeObject(checkIn));
            }
            checkIn.Result  = "false";
            checkIn.Message = "Could Not Update Task Status";
            return(JsonConvert.SerializeObject(checkIn));
        }
        public void UpdateComputerProperties(GroupPropertyEntity groupProperty)
        {
            if (groupProperty == null)
            {
                return;
            }
            var groupImageClassifications = new List <GroupImageClassificationEntity>();

            if (Convert.ToBoolean(groupProperty.ImageClassificationsEnabled))
            {
                groupImageClassifications =
                    new GroupServices().GetGroupImageClassifications(groupProperty.GroupId);
            }
            foreach (var computer in new GroupServices().GetGroupMembersWithImages(groupProperty.GroupId))
            {
                if (Convert.ToBoolean(groupProperty.ImageEnabled))
                {
                    computer.ImageId = groupProperty.ImageId;
                }
                if (Convert.ToBoolean(groupProperty.ImageProfileEnabled))
                {
                    computer.ImageProfileId = groupProperty.ImageProfileId;
                }
                if (Convert.ToBoolean(groupProperty.DescriptionEnabled))
                {
                    computer.Description = groupProperty.Description;
                }
                if (Convert.ToBoolean(groupProperty.SiteEnabled))
                {
                    computer.SiteId = groupProperty.SiteId;
                }
                if (Convert.ToBoolean(groupProperty.BuildingEnabled))
                {
                    computer.BuildingId = groupProperty.BuildingId;
                }
                if (Convert.ToBoolean(groupProperty.RoomEnabled))
                {
                    computer.RoomId = groupProperty.RoomId;
                }
                if (Convert.ToBoolean(groupProperty.CustomAttribute1Enabled))
                {
                    computer.CustomAttribute1 = groupProperty.CustomAttribute1;
                }
                if (Convert.ToBoolean(groupProperty.CustomAttribute2Enabled))
                {
                    computer.CustomAttribute2 = groupProperty.CustomAttribute2;
                }
                if (Convert.ToBoolean(groupProperty.CustomAttribute3Enabled))
                {
                    computer.CustomAttribute3 = groupProperty.CustomAttribute3;
                }
                if (Convert.ToBoolean(groupProperty.CustomAttribute4Enabled))
                {
                    computer.CustomAttribute4 = groupProperty.CustomAttribute4;
                }
                if (Convert.ToBoolean(groupProperty.CustomAttribute5Enabled))
                {
                    computer.CustomAttribute5 = groupProperty.CustomAttribute5;
                }
                if (Convert.ToBoolean(groupProperty.ProxyEnabledEnabled))
                {
                    computer.ProxyReservation = groupProperty.ProxyEnabled;
                }
                if (Convert.ToBoolean(groupProperty.ClusterGroupEnabled))
                {
                    computer.ClusterGroupId = groupProperty.ClusterGroupId;
                }
                if (Convert.ToBoolean(groupProperty.AlternateServerIpEnabled))
                {
                    computer.AlternateServerIpId = groupProperty.AlternateServerIpId;
                }
                if (Convert.ToBoolean(groupProperty.ImageClassificationsEnabled))
                {
                    var computerImageClassifications = new List <ComputerImageClassificationEntity>();
                    if (new ComputerServices().DeleteComputerImageClassifications(computer.Id))
                    {
                        foreach (var imageClass in groupImageClassifications)
                        {
                            computerImageClassifications.Add(
                                new ComputerImageClassificationEntity
                            {
                                ComputerId            = computer.Id,
                                ImageClassificationId = imageClass.ImageClassificationId
                            });
                        }
                    }
                    new ComputerImageClassificationServices().AddClassifications(computerImageClassifications);
                }

                var computerServices = new ComputerServices();
                computerServices.UpdateComputer(computer);
                if (Convert.ToBoolean(groupProperty.TftpServerEnabled) ||
                    Convert.ToBoolean(groupProperty.BootFileEnabled))
                {
                    var proxyServices = new ComputerProxyReservationServices();
                    var computerProxy = computerServices.GetComputerProxyReservation(computer.Id);
                    if (computerProxy == null)
                    {
                        computerProxy            = new ComputerProxyReservationEntity();
                        computerProxy.ComputerId = computer.Id;
                    }
                    if (Convert.ToBoolean(groupProperty.TftpServerEnabled))
                    {
                        computerProxy.NextServer = groupProperty.TftpServer;
                    }
                    if (Convert.ToBoolean(groupProperty.BootFileEnabled))
                    {
                        computerProxy.BootFile = groupProperty.BootFile;
                    }
                    proxyServices.UpdateComputerProxyReservation(computerProxy);
                }
            }
        }
Example #8
0
        public ActionResultDTO DeleteImage(int imageId)
        {
            var image = GetImage(imageId);

            if (image == null)
            {
                return new ActionResultDTO {
                           ErrorMessage = "Image Not Found", Id = 0
                }
            }
            ;
            var result = new ActionResultDTO();

            if (Convert.ToBoolean(image.Protected))
            {
                result.ErrorMessage = "This Image Is Protected And Cannot Be Deleted";

                return(result);
            }

            _uow.ImageRepository.Delete(image.Id);
            _uow.Save();
            result.Id = imageId;
            //Check if image name is empty or null, return if so or something will be deleted that shouldn't be
            if (string.IsNullOrEmpty(image.Name))
            {
                return(result);
            }

            var computers       = _uow.ComputerRepository.Get(x => x.ImageId == imageId);
            var computerService = new ComputerServices();

            foreach (var computer in computers)
            {
                computer.ImageId        = -1;
                computer.ImageProfileId = -1;
                computerService.UpdateComputer(computer);
            }

            var groups       = _uow.GroupRepository.Get(x => x.ImageId == imageId);
            var groupService = new GroupServices();

            foreach (var group in groups)
            {
                group.ImageId        = -1;
                group.ImageProfileId = -1;
                groupService.UpdateGroup(group);
            }

            var groupProperties      = _uow.GroupPropertyRepository.Get(x => x.ImageId == imageId);
            var groupPropertyService = new GroupPropertyServices();

            foreach (var groupProperty in groupProperties)
            {
                groupProperty.ImageId        = -1;
                groupProperty.ImageProfileId = -1;
                groupPropertyService.UpdateGroupProperty(groupProperty);
            }

            var delDirectoryResult = new FilesystemServices().DeleteImageFolders(image.Name);

            result.Success = delDirectoryResult;

            return(result);
        }
Example #9
0
        public ActionResultDTO DeleteClusterGroup(int clusterGroupId)
        {
            var clusterGroup = GetClusterGroup(clusterGroupId);

            if (clusterGroup == null)
            {
                return new ActionResultDTO {
                           ErrorMessage = "Cluster Group Not Found", Id = 0
                }
            }
            ;
            _uow.ClusterGroupRepository.Delete(clusterGroupId);
            _uow.Save();

            var sites       = _uow.SiteRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var siteService = new SiteServices();

            foreach (var site in sites)
            {
                site.ClusterGroupId = -1;

                siteService.UpdateSite(site);
            }

            var buildings       = _uow.BuildingRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var buildingService = new BuildingServices();

            foreach (var building in buildings)
            {
                building.ClusterGroupId = -1;
                buildingService.UpdateBuilding(building);
            }

            var rooms       = _uow.RoomRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var roomService = new RoomServices();

            foreach (var room in rooms)
            {
                room.ClusterGroupId = -1;
                roomService.UpdateRoom(room);
            }

            var computers       = _uow.ComputerRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var computerService = new ComputerServices();

            foreach (var computer in computers)
            {
                computer.ClusterGroupId = -1;
                computerService.UpdateComputer(computer);
            }

            var groups       = _uow.GroupRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var groupService = new GroupServices();

            foreach (var group in groups)
            {
                group.ClusterGroupId = -1;
                groupService.UpdateGroup(group);
            }

            var groupProperties      = _uow.GroupPropertyRepository.Get(x => x.ClusterGroupId == clusterGroupId);
            var groupPropertyService = new GroupPropertyServices();

            foreach (var groupProperty in groupProperties)
            {
                groupProperty.ClusterGroupId = -1;
                groupPropertyService.UpdateGroupProperty(groupProperty);
            }

            var actionResult = new ActionResultDTO();

            actionResult.Success = true;
            actionResult.Id      = clusterGroup.Id;
            return(actionResult);
        }