public static List <string> PrintEditionTarget(EditionTarget editionTarget, int padding = 0) { List <string> lines = new List <string>(); lines.Add($"-> Name: {editionTarget.PlannedEdition.EditionName}, Availability: {editionTarget.PlannedEdition.AvailabilityType}"); if (editionTarget.NonDestructiveTargets.Count > 0) { lines.Add(" Non Destructive Edition Upgrade Targets:"); foreach (var ed in editionTarget.NonDestructiveTargets) { lines.AddRange(PrintEditionTarget(ed, padding + 1)); } } if (editionTarget.DestructiveTargets.Count > 0) { lines.Add(" Destructive Edition Upgrade Targets:"); foreach (var ed in editionTarget.DestructiveTargets) { lines.AddRange(PrintEditionTarget(ed, padding + 1)); } } for (int j = 0; j < lines.Count; j++) { for (int i = 0; i < padding; i++) { lines[j] = " " + lines[j]; } } return(lines); }
private static EditionTarget BuildTarget( PlannedEdition edition, List <PlannedEdition> availableEditionsByDowngrading, List <EditionMappingXML.Edition> virtualWindowsEditions, List <EditionMappingXML.Edition> possibleEditionUpgrades, List <PlannedEdition>?availableEditionsByDowngradingInPriority, ref List <string> editionsAdded ) { EditionTarget target = new EditionTarget() { PlannedEdition = edition }; editionsAdded.Add(edition.EditionName); // // Handle edition downgrades that can be done using the current edition // We do these first because they potentially can be used for other downgrades, so they should be done first // if (availableEditionsByDowngradingInPriority != null) { foreach (var element in Constants.EditionDowngradeDict) { string editionThatCanBePackageSwapped = element.Key; foreach (var destinationEditionAfterPackageSwap in element.Value) { // // Is the currently examined edition from the dictionary is possible to get with the current UUP set? // if (availableEditionsByDowngradingInPriority.Any(x => x.EditionName.Equals(destinationEditionAfterPackageSwap, StringComparison.InvariantCultureIgnoreCase))) { // // If the edition we want to target is one edition that can be used for package swapping // if (edition.EditionName.Equals(editionThatCanBePackageSwapped, StringComparison.InvariantCultureIgnoreCase)) { // // If we have not added this edition already // if (!editionsAdded.Any(x => x.Equals(destinationEditionAfterPackageSwap, StringComparison.InvariantCultureIgnoreCase))) { // // Get the edition that can be targeted using package swap // var planedition = availableEditionsByDowngradingInPriority.First(x => x.EditionName.Equals(destinationEditionAfterPackageSwap, StringComparison.InvariantCultureIgnoreCase)); // // Remove it from the list of editions that can be targeted, as we are targeting it here so it doesn't get picked up again // availableEditionsByDowngradingInPriority.Remove(planedition); // // Add the edition // target.DestructiveTargets.Add(BuildTarget(planedition, availableEditionsByDowngrading, virtualWindowsEditions, possibleEditionUpgrades, availableEditionsByDowngradingInPriority, ref editionsAdded)); } } } } } } // // Handle editions that can be obtained by upgrading to a virtual edition // Loop through all editions we can upgrade to with the current examined edition // foreach (var ed in virtualWindowsEditions.Where(x => x.ParentEdition.Equals(edition.EditionName, StringComparison.InvariantCultureIgnoreCase))) { // // Verify that we have not added this edition already // if (editionsAdded.Any(x => x.Equals(ed.Name, StringComparison.InvariantCultureIgnoreCase))) { continue; } editionsAdded.Add(ed.Name); PlannedEdition plannedEdition = new PlannedEdition() { AvailabilityType = AvailabilityType.VirtualEdition, EditionName = ed.Name }; target.NonDestructiveTargets.Add(BuildTarget(plannedEdition, availableEditionsByDowngrading, virtualWindowsEditions, possibleEditionUpgrades, null, ref editionsAdded)); } // // Sort editions by name // target.NonDestructiveTargets = target.NonDestructiveTargets.OrderBy(x => x.PlannedEdition.EditionName).ToList(); // // Handle editions that we can upgrade to using a full upgrade process // foreach (var ed in possibleEditionUpgrades.Where(x => x.ParentEdition.Equals(edition.EditionName, StringComparison.InvariantCultureIgnoreCase))) { // // Verify that we have not added this edition already // if (editionsAdded.Any(x => x.Equals(ed.Name, StringComparison.InvariantCultureIgnoreCase))) { continue; } editionsAdded.Add(ed.Name); PlannedEdition plannedEdition = new PlannedEdition() { AvailabilityType = AvailabilityType.EditionUpgrade, EditionName = ed.Name }; target.DestructiveTargets.Add(BuildTarget(plannedEdition, availableEditionsByDowngrading, virtualWindowsEditions, possibleEditionUpgrades, null, ref editionsAdded)); } // // Handle editions that can be obtained by doing a package swap // var CoreEditionsToBeHacked = availableEditionsByDowngrading.Where(x => x.EditionName.StartsWith("core", StringComparison.InvariantCultureIgnoreCase) && !(x.EditionName.EndsWith("n", StringComparison.InvariantCultureIgnoreCase) || x.EditionName.EndsWith("neval", StringComparison.InvariantCultureIgnoreCase))); var CoreEditionsWithNoMediaTechnologiesToBeHacked = availableEditionsByDowngrading.Where(x => x.EditionName.StartsWith("core", StringComparison.InvariantCultureIgnoreCase) && (x.EditionName.EndsWith("n", StringComparison.InvariantCultureIgnoreCase) || x.EditionName.EndsWith("neval", StringComparison.InvariantCultureIgnoreCase))); var ProfessionalEditionsToBeHacked = availableEditionsByDowngrading.Where(x => !x.EditionName.StartsWith("core", StringComparison.InvariantCultureIgnoreCase) && !(x.EditionName.EndsWith("n", StringComparison.InvariantCultureIgnoreCase) || x.EditionName.EndsWith("neval", StringComparison.InvariantCultureIgnoreCase))); var ProfessionalEditionsWithNoMediaTechnologiesToBeHacked = availableEditionsByDowngrading.Where(x => !x.EditionName.StartsWith("core", StringComparison.InvariantCultureIgnoreCase) && (x.EditionName.EndsWith("n", StringComparison.InvariantCultureIgnoreCase) || x.EditionName.EndsWith("neval", StringComparison.InvariantCultureIgnoreCase))); if (edition.EditionName.Equals("professional", StringComparison.InvariantCultureIgnoreCase)) { foreach (var ed in ProfessionalEditionsToBeHacked) { // // Verify that we have not added this edition already // if (editionsAdded.Any(x => x.Equals(ed.EditionName, StringComparison.InvariantCultureIgnoreCase))) { continue; } editionsAdded.Add(ed.EditionName); target.DestructiveTargets.Add(BuildTarget(ed, availableEditionsByDowngrading, virtualWindowsEditions, possibleEditionUpgrades, null, ref editionsAdded)); } } else if (edition.EditionName.Equals("professionaln", StringComparison.InvariantCultureIgnoreCase)) { foreach (var ed in ProfessionalEditionsWithNoMediaTechnologiesToBeHacked) { // // Verify that we have not added this edition already // if (editionsAdded.Any(x => x.Equals(ed.EditionName, StringComparison.InvariantCultureIgnoreCase))) { continue; } editionsAdded.Add(ed.EditionName); target.DestructiveTargets.Add(BuildTarget(ed, availableEditionsByDowngrading, virtualWindowsEditions, possibleEditionUpgrades, null, ref editionsAdded)); } } else if (edition.EditionName.Equals("core", StringComparison.InvariantCultureIgnoreCase)) { foreach (var ed in CoreEditionsToBeHacked) { // // Verify that we have not added this edition already // if (editionsAdded.Any(x => x.Equals(ed.EditionName, StringComparison.InvariantCultureIgnoreCase))) { continue; } editionsAdded.Add(ed.EditionName); target.DestructiveTargets.Add(BuildTarget(ed, availableEditionsByDowngrading, virtualWindowsEditions, possibleEditionUpgrades, null, ref editionsAdded)); } } else if (edition.EditionName.Equals("coren", StringComparison.InvariantCultureIgnoreCase)) { foreach (var ed in CoreEditionsWithNoMediaTechnologiesToBeHacked) { // // Verify that we have not added this edition already // if (editionsAdded.Any(x => x.Equals(ed.EditionName, StringComparison.InvariantCultureIgnoreCase))) { continue; } editionsAdded.Add(ed.EditionName); target.DestructiveTargets.Add(BuildTarget(ed, availableEditionsByDowngrading, virtualWindowsEditions, possibleEditionUpgrades, null, ref editionsAdded)); } } target.DestructiveTargets = target.DestructiveTargets.OrderBy(x => x.PlannedEdition.EditionName).ToList(); return(target); }