public string MulticastCheckout(string portBase) { string result = null; var activeMulticastSessionServices = new ActiveMulticastSessionServices(); var mcTask = activeMulticastSessionServices.GetFromPort(Convert.ToInt32(portBase)); if (mcTask != null) { var prsRunning = true; if (Environment.OSVersion.ToString().Contains("Unix")) { try { var prs = Process.GetProcessById(Convert.ToInt32(mcTask.Pid)); if (prs.HasExited) { prsRunning = false; } } catch { prsRunning = false; } } else { try { Process.GetProcessById(Convert.ToInt32(mcTask.Pid)); } catch { prsRunning = false; } } if (!prsRunning) { if (activeMulticastSessionServices.Delete(mcTask.Id).Success) { result = "Success"; activeMulticastSessionServices.SendMulticastCompletedEmail(mcTask); } } else { result = "Cannot Close Session, It Is Still In Progress"; } } else { result = "Session Is Already Closed"; } return(result); }
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 string OnDemandCheckIn(string mac, int objectId, string task, string userId, string computerId) { var checkIn = new CheckIn(); var computerServices = new ComputerServices(); if (userId != null) //on demand { //Check permissions if (task.Contains("deploy")) { if ( !new AuthorizationServices(Convert.ToInt32(userId), AuthorizationStrings.ImageDeployTask) .IsAuthorized()) { checkIn.Result = "false"; checkIn.Message = "This User Is Not Authorized To Deploy Images"; return(JsonConvert.SerializeObject(checkIn)); } } if (task.Contains("upload")) { if ( !new AuthorizationServices(Convert.ToInt32(userId), AuthorizationStrings.ImageUploadTask) .IsAuthorized()) { checkIn.Result = "false"; checkIn.Message = "This User Is Not Authorized To Upload Images"; return(JsonConvert.SerializeObject(checkIn)); } } if (task.Contains("multicast")) { if ( !new AuthorizationServices(Convert.ToInt32(userId), AuthorizationStrings.ImageMulticastTask) .IsAuthorized()) { checkIn.Result = "false"; checkIn.Message = "This User Is Not Authorized To Multicast Images"; return(JsonConvert.SerializeObject(checkIn)); } } } ComputerEntity computer = null; if (computerId != "false") { computer = computerServices.GetComputer(Convert.ToInt32(computerId)); } ImageProfileWithImage imageProfile; var arguments = ""; if (task == "deploy" || task == "upload" || task == "clobber" || task == "ondupload" || task == "onddeploy" || task == "unregupload" || task == "unregdeploy" || task == "modelmatchdeploy") { imageProfile = new ImageProfileServices().ReadProfile(objectId); arguments = new CreateTaskArguments(computer, imageProfile, task).Execute(); } else //Multicast { var multicast = new ActiveMulticastSessionServices().GetFromPort(objectId); imageProfile = new ImageProfileServices().ReadProfile(multicast.ImageProfileId); arguments = new CreateTaskArguments(computer, imageProfile, task).Execute(objectId.ToString()); } var imageDistributionPoint = new GetImageServer(computer, task).Run(); if (imageProfile.Image.Protected == 1 && (task == "upload" || task == "ondupload" || task == "unregupload")) { checkIn.Result = "false"; checkIn.Message = "This Image Is Protected"; return(JsonConvert.SerializeObject(checkIn)); } if (imageProfile.Image.Environment == "") { imageProfile.Image.Environment = "linux"; } checkIn.ImageEnvironment = imageProfile.Image.Environment; if (imageProfile.Image.Environment == "winpe") { arguments += "dp_id=\"" + imageDistributionPoint + "\"\r\n"; } else { arguments += " dp_id=\"" + imageDistributionPoint + "\""; } var activeTask = new ActiveImagingTaskEntity(); activeTask.Direction = task; activeTask.UserId = Convert.ToInt32(userId); activeTask.Type = task; activeTask.DpId = imageDistributionPoint; activeTask.Status = "1"; if (computer == null) { //Create Task for an unregistered on demand computer var rnd = new Random(DateTime.Now.Millisecond); var newComputerId = rnd.Next(-200000, -100000); if (imageProfile.Image.Environment == "winpe") { arguments += "computer_id=" + newComputerId + "\r\n"; } else { arguments += " computer_id=" + newComputerId; } activeTask.ComputerId = newComputerId; activeTask.Arguments = mac; } else { //Create Task for a registered on demand computer activeTask.ComputerId = computer.Id; activeTask.Arguments = arguments; } new ActiveImagingTaskServices().AddActiveImagingTask(activeTask); var auditLog = new AuditLogEntity(); switch (task) { case "ondupload": case "unregupload": case "upload": auditLog.AuditType = AuditEntry.Type.OndUpload; break; default: auditLog.AuditType = AuditEntry.Type.OndDeploy; break; } try { auditLog.ObjectId = activeTask.ComputerId; var user = new UserServices().GetUser(activeTask.UserId); if (user != null) { auditLog.UserName = user.Name; } auditLog.ObjectName = computer != null ? computer.Name : mac; auditLog.Ip = ""; auditLog.UserId = activeTask.UserId; auditLog.ObjectType = "Computer"; auditLog.ObjectJson = JsonConvert.SerializeObject(activeTask); new AuditLogServices().AddAuditLog(auditLog); auditLog.ObjectId = imageProfile.ImageId; auditLog.ObjectName = imageProfile.Image.Name; auditLog.ObjectType = "Image"; new AuditLogServices().AddAuditLog(auditLog); } catch { //Do Nothing } checkIn.Result = "true"; checkIn.TaskArguments = arguments; checkIn.TaskId = activeTask.Id.ToString(); return(JsonConvert.SerializeObject(checkIn)); }