private void addPackageBranch(Tree tree, ParsedPackageDependencyPair parsedPackageDependencyPair) { var branch = new Branch(); if (parsedPackageDependencyPair.NeededPackage != null) { Branch.Append(branch, parsedPackageDependencyPair.NeededPackage); } Branch.Append(branch, parsedPackageDependencyPair.MainPackage); Tree.Append(tree, branch); }
private void handleMainAndNeededPackagesAreInDifferentBranches (Tree tree, Branch branchMainPackage, Branch branchNeededPackage, ParsedPackageDependencyPair parsedPackageDependencyPair) { if (Tree.GetIndex(tree, branchNeededPackage) > Tree.GetIndex(tree, branchMainPackage)) { Tree.Remove(tree, branchNeededPackage); Tree.Insert(tree, branchNeededPackage); } }
public static Branch GetBranch(Tree tree, string package) { foreach (var branch in tree._branches) { if (Branch.IsInBranch(branch, package)) { return branch; } } return null; }
public string GetInstallListFromDependencies(string[] packageDependencyPairs) { var parsedPackageDependencyPair = new ParsedPackageDependencyPair(); var packageDependencyTree = new Tree(); for (int i = 0; i < packageDependencyPairs.Length; i++) { parsedPackageDependencyPair = Parse.ParsePackageDependencPair(packageDependencyPairs[i]); storeParsedPackageDependencyPair(packageDependencyTree, parsedPackageDependencyPair); } return Tree.ExtractTreeDelimitedList(packageDependencyTree); }
public static string ExtractTreeDelimitedList(Tree tree) { string result = ""; //foreach (var branch in _branches) foreach (var branch in tree._branches) { result += Branch.ExtractBranchDelimitedList(branch, TREE_LIST_DELIMITER) + TREE_LIST_DELIMITER; } if (result.Length > TREE_LIST_DELIMITER.Length) { result = result.Substring(0, result.Length - 2); } return result; }
private void handleMainPackageIsInTree(Tree tree, Branch branchMainPackage, Branch branchNeededPackage, ParsedPackageDependencyPair parsedPackageDependencyPair) { if (parsedPackageDependencyPair.NeededPackage == null) { return; } if (branchNeededPackage == null) { Branch.Insert(branchMainPackage, parsedPackageDependencyPair.NeededPackage); } else if (branchMainPackage == branchNeededPackage) { checkForDependencyCycle(branchMainPackage, parsedPackageDependencyPair); } else { handleMainAndNeededPackagesAreInDifferentBranches(tree,branchMainPackage, branchNeededPackage, parsedPackageDependencyPair); } }
private void handleMainPackageIsNotInTree(Tree tree, Branch branchMainPackage, Branch branchNeededPackage, ParsedPackageDependencyPair parsedPackageDependencyPair) { if (parsedPackageDependencyPair.NeededPackage == null || branchNeededPackage == null) { addPackageBranch(tree, parsedPackageDependencyPair); } else { Branch.Append(branchNeededPackage, parsedPackageDependencyPair.MainPackage); } }
private void storeParsedPackageDependencyPair (Tree tree, ParsedPackageDependencyPair parsedPackageDependencyPair) { Branch branchMainPackage = Tree.GetBranch(tree, parsedPackageDependencyPair.MainPackage); Branch branchNeededPackage = parsedPackageDependencyPair.NeededPackage == null ? null : Tree.GetBranch(tree, parsedPackageDependencyPair.NeededPackage); if (branchMainPackage != null) { handleMainPackageIsInTree(tree, branchMainPackage, branchNeededPackage, parsedPackageDependencyPair); } else { handleMainPackageIsNotInTree(tree, branchMainPackage, branchNeededPackage, parsedPackageDependencyPair); } }
public static void Remove(Tree tree, Branch branch) { tree._branches.Remove(branch); }
public static void Insert(Tree tree, Branch branch) { tree._branches.Insert(0, branch); }
public static int GetIndex(Tree tree, Branch branch) { return tree._branches.IndexOf(branch); }
public static void Append(Tree tree, Branch branch) { tree._branches.Add(branch); }