public ServiceImageSchemaFE(DtoImageSchemaRequest schemaRequest) { string schema = null; //Only To display the main image specs file when not using a profile. if (schemaRequest.image != null) { schema = new FilesystemServices().ReadSchemaFile(schemaRequest.image.Name); } if (schemaRequest.imageProfile != null) { if (!string.IsNullOrEmpty(schemaRequest.imageProfile.CustomSchema) && schemaRequest.imageProfile.CustomSchema != "{}" && schemaRequest.schemaType == "deploy") { schema = schemaRequest.imageProfile.CustomSchema; } else if (!string.IsNullOrEmpty(schemaRequest.imageProfile.CustomUploadSchema) && schemaRequest.imageProfile.CustomSchema != "{}" && schemaRequest.schemaType == "upload") { schema = schemaRequest.imageProfile.CustomUploadSchema; } else { schema = new FilesystemServices().ReadSchemaFile(schemaRequest.imageProfile.Image.Name); } } if (!string.IsNullOrEmpty(schema)) { _imageSchema = JsonConvert.DeserializeObject <DtoImageSchemaGridView>(schema); } }
public DtoApiStringResponse GetDefaultBootFilePath(string type, int id) { var result = new FilesystemServices().GetDefaultBootMenuPath(type, id); return(new DtoApiStringResponse() { Value = result }); }
public DtoActionResult Delete(int imageId) { var u = GetImage(imageId); if (u == null) { return new DtoActionResult { ErrorMessage = "Image Not Found", Id = 0 } } ; if (u.Protected) { return(new DtoActionResult { ErrorMessage = "This Image Is Protected And Cannot Be Deleted", Id = u.Id }); } _uow.ImageRepository.Delete(imageId); _uow.Save(); var actionResult = new DtoActionResult(); actionResult.Success = true; actionResult.Id = u.Id; //Check if image name is empty or null, return if so or something will be deleted that shouldn't be if (string.IsNullOrEmpty(u.Name)) { return(actionResult); } var computers = _uow.ComputerRepository.Get(x => x.ImageId == imageId); var computerService = new ServiceComputer(); 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 ServiceGroup(); foreach (var group in groups) { group.ImageId = -1; group.ImageProfileId = -1; groupService.UpdateGroup(group); } var delDirectoryResult = new FilesystemServices().DeleteImageFolders(u.Name); return(actionResult); }
public DtoActionResult DeleteModule(int moduleId) { var u = GetModule(moduleId); if (u == null) { return new DtoActionResult { ErrorMessage = "Module Not Found", Id = 0 } } ; var isActiveModule = new ServiceModule().IsModuleActive(moduleId, EnumModule.ModuleType.Software); if (!string.IsNullOrEmpty(isActiveModule)) { return new DtoActionResult() { ErrorMessage = isActiveModule, Id = 0 } } ; if (string.IsNullOrEmpty(u.Guid)) { return new DtoActionResult() { ErrorMessage = "Unknown Guid", Id = 0 } } ; _uow.ModuleRepository.DeleteRange(x => x.Guid == u.Guid); //_uow.SoftwareModuleRepository.Delete(moduleId); _uow.Save(); var actionResult = new DtoActionResult(); var deleteDirectoryResult = new FilesystemServices().DeleteModuleDirectory(u.Guid); if (deleteDirectoryResult) { actionResult.Success = true; actionResult.Id = u.Id; } else { actionResult.Success = false; actionResult.ErrorMessage = "Module Has Been Deleted But File System Cleanup Has Failed. You Must Manually Delete Folder " + u.Guid; } return(actionResult); }
public int GenerateProcessArguments(DtoMulticastArgs mArgs) { var guid = ConfigurationManager.AppSettings["ComServerUniqueId"]; _thisComServer = new ServiceClientComServer().GetServerByGuid(guid); if (_thisComServer == null) { log.Error($"Com Server With Guid {guid} Not Found"); return(0); } var schemaCounter = -1; var multicastHdCounter = 0; string processArguments = null; foreach (var hd in mArgs.schema.HardDrives) { schemaCounter++; if (!hd.Active) { continue; } multicastHdCounter++; var x = 0; foreach (var part in mArgs.schema.HardDrives[schemaCounter].Partitions) { if (!part.Active) { continue; } string imageFile = null; foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "winpe", "xfs" }) { imageFile = new FilesystemServices().GetMulticastFileNameWithFullPath(mArgs.ImageName, schemaCounter.ToString(), part.Number, ext, _thisComServer.LocalStoragePath); if (!string.IsNullOrEmpty(imageFile)) { break; } //Look for lvm if (part.VolumeGroup == null) { continue; } if (part.VolumeGroup.LogicalVolumes == null) { continue; } foreach (var lv in part.VolumeGroup.LogicalVolumes.Where(lv => lv.Active)) { imageFile = new FilesystemServices().GetMulticastLVMFileNameWithFullPath(mArgs.ImageName, schemaCounter.ToString(), lv.VolumeGroup, lv.Name, ext, _thisComServer.LocalStoragePath); } } if (string.IsNullOrEmpty(imageFile)) { continue; } if (mArgs.Environment == "winpe" && mArgs.schema.HardDrives[schemaCounter].Table.ToLower() == "gpt") { if (part.Type.ToLower() == "system" || part.Type.ToLower() == "recovery" || part.Type.ToLower() == "reserved") { continue; } } if (mArgs.Environment == "winpe" && mArgs.schema.HardDrives[schemaCounter].Table.ToLower() == "mbr") { if (part.Number == mArgs.schema.HardDrives[schemaCounter].Boot && mArgs.schema.HardDrives[schemaCounter].Partitions.Length > 1) { continue; } } x++; var minReceivers = ""; if (!string.IsNullOrEmpty(mArgs.clientCount)) { minReceivers = " --min-receivers " + mArgs.clientCount; } var isUnix = Environment.OSVersion.ToString().Contains("Unix"); string compAlg; var stdout = ""; switch (Path.GetExtension(imageFile)) { case ".lz4": compAlg = isUnix ? "lz4 -d " : "lz4.exe\" -d "; stdout = " - "; break; case ".gz": if (isUnix) { compAlg = "gzip -c -d "; stdout = ""; } else { compAlg = "7za.exe\" x "; stdout = " -so "; } break; case ".uncp": compAlg = "none"; break; case ".wim": compAlg = "none"; break; default: return(0); } if (isUnix) { string prefix = null; if (multicastHdCounter == 1) { prefix = x == 1 ? " -c \"" : " ; "; } else { prefix = " ; "; } if (compAlg == "none" || _thisComServer.DecompressImageOn == "client") { processArguments += prefix + "cat " + "\"" + imageFile + "\"" + " | udp-sender" + " --portbase " + mArgs.Port + minReceivers + " " + " --ttl 32 --interface " + _thisComServer.MulticastInterfaceIp + " --mcast-rdv-address " + _thisComServer.MulticastInterfaceIp + mArgs.ExtraArgs; } else { processArguments += prefix + compAlg + "\"" + imageFile + "\"" + stdout + " | udp-sender" + " --portbase " + mArgs.Port + minReceivers + " " + " --ttl 32 --interface " + _thisComServer.MulticastInterfaceIp + " --mcast-rdv-address " + _thisComServer.MulticastInterfaceIp + mArgs.ExtraArgs; } } else { var appPath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "private" + Path.DirectorySeparatorChar + "apps" + Path.DirectorySeparatorChar; string prefix = null; if (multicastHdCounter == 1) { prefix = x == 1 ? " /c \"" : " & "; } else { prefix = " & "; } if (compAlg == "none" || _thisComServer.DecompressImageOn == "client") { processArguments += prefix + "\"" + appPath + "udp-sender.exe" + "\"" + " --file " + "\"" + imageFile + "\"" + " --portbase " + mArgs.Port + minReceivers + " " + " --ttl 32 --interface " + _thisComServer.MulticastInterfaceIp + " --mcast-rdv-address " + _thisComServer.MulticastInterfaceIp + mArgs.ExtraArgs; } else { processArguments += prefix + "\"" + appPath + compAlg + "\"" + imageFile + "\"" + stdout + " | " + "\"" + appPath + "udp-sender.exe" + "\"" + " --portbase " + mArgs.Port + minReceivers + " " + " --ttl 32 --interface " + _thisComServer.MulticastInterfaceIp + " --mcast-rdv-address " + _thisComServer.MulticastInterfaceIp + mArgs.ExtraArgs; } } } } processArguments += "\""; return(StartMulticastSender(processArguments, mArgs.groupName)); }
public List <string> GetComServerLogs(int id) { return(FilesystemServices.GetComServerLogs(id)); }
public List <string> GetLogs() { return(FilesystemServices.GetLogs()); }
public List <string> GetScripts(string type) { return(FilesystemServices.GetScripts(type)); }
public IEnumerable <string> GetKernels() { return(FilesystemServices.GetKernels()); }
public IEnumerable <string> GetBootImages() { return(FilesystemServices.GetBootImages()); }
public int GenerateProcessArguments(MulticastArgsDTO mArgs) { var schemaCounter = -1; var multicastHdCounter = 0; string processArguments = null; foreach (var hd in mArgs.schema.HardDrives) { schemaCounter++; if (!hd.Active) { continue; } multicastHdCounter++; var x = 0; foreach (var part in mArgs.schema.HardDrives[schemaCounter].Partitions) { if (!part.Active) { continue; } string imageFile = null; foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "winpe", "xfs" }) { imageFile = new FilesystemServices().GetFileNameWithFullPath(mArgs.ImageName, schemaCounter.ToString(), part.Number, ext); if (!string.IsNullOrEmpty(imageFile)) { break; } //Look for lvm if (part.VolumeGroup == null) { continue; } if (part.VolumeGroup.LogicalVolumes == null) { continue; } foreach (var lv in part.VolumeGroup.LogicalVolumes.Where(lv => lv.Active)) { imageFile = new FilesystemServices().GetLVMFileNameWithFullPath(mArgs.ImageName, schemaCounter.ToString(), lv.VolumeGroup, lv.Name, ext); } } if (string.IsNullOrEmpty(imageFile)) { continue; } if (mArgs.Environment == "winpe" && mArgs.schema.HardDrives[schemaCounter].Table.ToLower() == "gpt") { if (part.Type.ToLower() == "system" || part.Type.ToLower() == "recovery" || part.Type.ToLower() == "reserved") { continue; } } if (mArgs.Environment == "winpe" && mArgs.schema.HardDrives[schemaCounter].Table.ToLower() == "mbr") { if (part.Number == mArgs.schema.HardDrives[schemaCounter].Boot && mArgs.schema.HardDrives[schemaCounter].Partitions.Length > 1) { continue; } } x++; var minReceivers = ""; if (!string.IsNullOrEmpty(mArgs.clientCount)) { minReceivers = " --min-receivers " + mArgs.clientCount; } var isUnix = Environment.OSVersion.ToString().Contains("Unix"); string compAlg; var stdout = ""; switch (Path.GetExtension(imageFile)) { case ".lz4": compAlg = isUnix ? "lz4 -d " : "lz4.exe\" -d "; stdout = " - "; break; case ".gz": compAlg = isUnix ? "gzip -c -d " : "gzip.exe\" -c -d "; stdout = ""; break; case ".uncp": compAlg = "none"; break; case ".wim": compAlg = "none"; break; default: return(0); } if (isUnix) { string prefix = null; if (multicastHdCounter == 1) { prefix = x == 1 ? " -c \"" : " ; "; } else { prefix = " ; "; } if (compAlg == "none" || SettingServices.GetSettingValue(SettingStrings.MulticastDecompression) == "client") { processArguments += prefix + "cat " + "\"" + imageFile + "\"" + " | udp-sender" + " --portbase " + mArgs.Port + minReceivers + " " + " --ttl 32 " + mArgs.ExtraArgs; } else { processArguments += prefix + compAlg + "\"" + imageFile + "\"" + stdout + " | udp-sender" + " --portbase " + mArgs.Port + minReceivers + " " + " --ttl 32 " + mArgs.ExtraArgs; } } else { var appPath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "private" + Path.DirectorySeparatorChar + "apps" + Path.DirectorySeparatorChar; string prefix = null; if (multicastHdCounter == 1) { //Relative to the multicast server being called var primaryDp = new DistributionPointServices().GetPrimaryDistributionPoint(); if (primaryDp == null) { return(0); } if (primaryDp.Location == "Local") { prefix = x == 1 ? " /c \"" : " & "; } else //Remote { if (x == 1) { prefix = " /c \"net use \\\\" + primaryDp.Server + "\\" + primaryDp.ShareName + " /user:"******" " + new EncryptionServices().DecryptText(primaryDp.RoPassword) + " & "; } else { prefix = " & "; } } } else { prefix = " & "; } if (compAlg == "none" || SettingServices.GetSettingValue(SettingStrings.MulticastDecompression) == "client") { processArguments += prefix + "\"" + appPath + "udp-sender.exe" + "\"" + " --file " + "\"" + imageFile + "\"" + " --portbase " + mArgs.Port + minReceivers + " " + " --ttl 32 " + mArgs.ExtraArgs; } else { processArguments += prefix + "\"" + appPath + compAlg + "\"" + imageFile + "\"" + stdout + " | " + "\"" + appPath + "udp-sender.exe" + "\"" + " --portbase " + mArgs.Port + minReceivers + " " + " --ttl 32 " + mArgs.ExtraArgs; } } } } var pDp = new DistributionPointServices().GetPrimaryDistributionPoint(); if (pDp == null) { return(0); } if (pDp.Location == "Remote") { processArguments += " & net use /delete \\\\" + pDp.Server + "\\" + pDp.ShareName; } processArguments += "\""; return(StartMulticastSender(processArguments, mArgs.groupName)); }