public ActionResultDTO DeleteImageClassification(int imageClassificationId) { var imageClassification = GetImageClassification(imageClassificationId); if (imageClassification == null) { return new ActionResultDTO { ErrorMessage = "Image Classification Not Found", Id = 0 } } ; _uow.ImageClassificationRepository.Delete(imageClassificationId); _uow.Save(); var images = _uow.ImageRepository.Get(x => x.ClassificationId == imageClassificationId); var imageService = new ImageServices(); foreach (var image in images) { image.ClassificationId = -1; imageService.UpdateImage(image); } var actionResult = new ActionResultDTO(); actionResult.Success = true; actionResult.Id = imageClassification.Id; return(actionResult); }
public ImageProfileEntity GetModelMatch(string model, string environment) { if (string.IsNullOrEmpty(model)) { return(null); } var profiles = _uow.ImageProfileRepository.Get( x => !string.IsNullOrEmpty(x.ModelMatch) && !x.ModelMatchType.Equals("Disabled")); if (!profiles.Any()) { return(null); } model = model.ToLower(); var environmentProfiles = new List <ImageProfileEntity>(); foreach (var profile in profiles) { var image = new ImageServices().GetImage(profile.ImageId); if (image.Environment.Equals(environment)) { environmentProfiles.Add(profile); } } //done in seperate loops to match most specific first foreach (var profile in environmentProfiles) { if (profile.ModelMatchType.Equals("Equals") && model.Equals(profile.ModelMatch)) { return(profile); } } foreach (var profile in environmentProfiles) { if (profile.ModelMatchType.Equals("Starts With") && model.StartsWith(profile.ModelMatch)) { return(profile); } } foreach (var profile in environmentProfiles) { if (profile.ModelMatchType.Equals("Ends With") && model.EndsWith(profile.ModelMatch)) { return(profile); } } foreach (var profile in environmentProfiles) { if (profile.ModelMatchType.Equals("Contains") && model.Contains(profile.ModelMatch)) { return(profile); } } return(null); }
public string UpdateGuid(int profileId) { var imageProfile = new ImageProfileServices().ReadProfile(profileId); var imageServices = new ImageServices(); var image = imageServices.GetImage(imageProfile.ImageId); var guid = Guid.NewGuid().ToString(); image.LastUploadGuid = guid; imageServices.UpdateImage(image); return(guid); }
public string ImageProfileList(int imageId) { var imageServices = new ImageServices(); var selectedImage = imageServices.GetImage(imageId); if (selectedImage.Environment == "winpe") { var imageProfileList = new WinPEProfileList { ImageProfiles = new List <WinPEProfile>() }; var profileCounter = 0; foreach (var imageProfile in imageServices.SearchProfiles(Convert.ToInt32(imageId)).OrderBy(x => x.Name) ) { profileCounter++; var winpeProfile = new WinPEProfile(); winpeProfile.ProfileId = imageProfile.Id.ToString(); winpeProfile.ProfileName = imageProfile.Name; imageProfileList.ImageProfiles.Add(winpeProfile); if (profileCounter == 1) { imageProfileList.FirstProfileId = imageProfile.Id.ToString(); } } imageProfileList.Count = profileCounter.ToString(); return(JsonConvert.SerializeObject(imageProfileList)); } else { var imageProfileList = new ImageProfileList { ImageProfiles = new List <string>() }; var profileCounter = 0; foreach (var imageProfile in imageServices.SearchProfiles(Convert.ToInt32(imageId))) { profileCounter++; imageProfileList.ImageProfiles.Add(imageProfile.Id + " " + imageProfile.Name); if (profileCounter == 1) { imageProfileList.FirstProfileId = imageProfile.Id.ToString(); } } imageProfileList.Count = profileCounter.ToString(); return(JsonConvert.SerializeObject(imageProfileList)); } }
public string CheckModelMatch(string environment, string systemModel) { var modelTask = new ModelTaskDTO(); //Check for model match var modelMatchProfile = new ImageProfileServices().GetModelMatch(systemModel, environment); if (modelMatchProfile != null) { var image = new ImageServices().GetImage(modelMatchProfile.ImageId); if (image != null) { modelTask.imageName = image.Name; } modelTask.imageProfileId = modelMatchProfile.Id.ToString(); modelTask.imageProfileName = modelMatchProfile.Name; return(JsonConvert.SerializeObject(modelTask)); } return(JsonConvert.SerializeObject(new ModelTaskDTO())); }
public string AddImageWinPEEnv(string imageName) { var image = new ImageEntity { Name = imageName, Environment = "winpe", Type = "File", Enabled = 1, IsVisible = 1, Os = "", Description = "", ClassificationId = -1 }; var result = new ImageServices().AddImage(image); if (result.Success) { result.Id = image.Id; } return(JsonConvert.SerializeObject(result)); }
public string AddImage(string imageName) { var image = new ImageEntity { Name = imageName, Environment = "linux", Type = "Block", Enabled = 1, IsVisible = 1, Os = "", Description = "", ClassificationId = -1 }; var result = new ImageServices().AddImage(image); if (result.Success) { result.ErrorMessage = image.Id.ToString(); } return(JsonConvert.SerializeObject(result)); }
public ImageProfileServices() { _uow = new UnitOfWork(); _imageServices = new ImageServices(); }
public string ImageList(string environment, string computerId, string task, int userId = 0) { var images = new ImageServices().GetOnDemandImageList(task, userId); if (images.Count == 0) { var imageList = new ImageList { Images = new List <string>() }; imageList.Images.Add(-1 + " " + "No_Images_Found"); return(JsonConvert.SerializeObject(imageList)); } if (computerId == "false") { computerId = "0"; } var filteredImages = new ComputerImageClassificationServices().FilterForOnDemandList(Convert.ToInt32(computerId), images); if (environment == "winpe") { filteredImages = filteredImages.Where(x => x.Environment == "winpe").ToList(); var imageList = new List <WinPEImageList>(); foreach (var image in filteredImages) { var winpeImage = new WinPEImageList(); winpeImage.ImageId = image.Id.ToString(); winpeImage.ImageName = image.Name; imageList.Add(winpeImage); } return(JsonConvert.SerializeObject(imageList)); } else { var imageList = new ImageList { Images = new List <string>() }; if (images.Count == 0) { imageList.Images.Add(-1 + " " + "No_Images_Found"); return(JsonConvert.SerializeObject(imageList)); } if (environment == "macOS") { filteredImages = filteredImages.Where(x => x.Environment == "macOS").ToList(); } else if (environment == "linux") { filteredImages = filteredImages.Where(x => x.Environment != "macOS" && x.Environment != "winpe").ToList(); } foreach (var image in filteredImages) { imageList.Images.Add(image.Id + " " + image.Name); } if (imageList.Images.Count == 0) { imageList.Images.Add(-1 + " " + "No_Images_Found"); } return(JsonConvert.SerializeObject(imageList)); } }
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)); }