private AbstractTreeNode GetTreeNode(Tree source, string path) { if (String.IsNullOrEmpty(path)) { return(source); } var dirs = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); AbstractTreeNode currentTree = source; foreach (var item in dirs) { if (currentTree.IsTree) { var result = ((Tree)currentTree).Children.FirstOrDefault(i => ((AbstractTreeNode)i).Name == item); if (result == null) { return(null); } else { currentTree = (AbstractTreeNode)result; } } } return(currentTree); }
public static int GetLongestPathLenghtDFS( AbstractTreeNode<int> tree, Dictionary<string, int> paths, List<int> path) { if (tree.GetChildCount() == 0) { string key = string.Join(", ", path); if (!paths.ContainsKey(key)) { paths.Add(key, path.Count); } path.RemoveAt(path.Count - 1); return 0; } int maxPath = 0; foreach (var node in tree) { path.Add(node.Value); maxPath = Math.Max(maxPath, GetLongestPathLenghtDFS(node, paths, path)); } path.RemoveAt(path.Count - 1); return maxPath + 1; }
public IEnumerable <RepositoryTreeDetailModel> Browse(string name, string path, out string branchName) { branchName = null; if (!EnsureRepository()) { return(null); } var result = new List <RepositoryTreeDetailModel>(); Tree source = null; Branch branch = null; Commit commit = null; if (TryGetBranch(name, out branch)) { if (branch == null) { return(result); } branchName = branch.Name; source = (branch.Target as Commit).Tree; } else if (TryGetCommit(name, out commit)) { source = commit.Tree; } else { return(null); } AbstractTreeNode treeNode = GetTreeNode(source, path); if (treeNode == null) { return(null); } if (treeNode.IsTree) { foreach (AbstractTreeNode item in ((Tree)treeNode).Children) { result.Add(ConvertToRepositoryDetailModel(item, GetLastCommit(item, branch, commit), name, branch)); } } else if (treeNode as Leaf != null) { var model = ConvertToRepositoryDetailModel(treeNode, GetLastCommit(treeNode, branch, commit), name, branch); model.Data = ((Leaf)treeNode).RawData; result.Add(model); } return(result); }
private Commit GetLastCommit(AbstractTreeNode item, Branch branch, Commit commit) { if (branch != null) { return(item.GetLastCommit(branch)); } else if (commit != null) { return(item.GetLastCommitBefore(commit)); } return(null); }
private RepositoryTreeDetailModel ConvertToRepositoryDetailModel(AbstractTreeNode item, Commit lastCommit, string treeName, Branch branch) { return(new RepositoryTreeDetailModel { Name = item.Name, IsTree = item.IsTree, CommitDate = lastCommit != null ? new DateTime?(lastCommit.AuthorDate.LocalDateTime) : null, CommitMessage = lastCommit != null ? lastCommit.Message : null, Author = lastCommit != null ? lastCommit.Author.Name : null, Tree = String.IsNullOrEmpty(treeName) ? branch.Name : treeName, Path = item.Path, Hash = item.Hash, }); }
public static List<AbstractTreeNode<int>> GetMiddleNodes(AbstractTreeNode<int> tree) { List<AbstractTreeNode<int>> leafs = new List<AbstractTreeNode<int>>(); foreach (AbstractTreeNode<int> node in tree) { if (node.GetChildCount() > 0) { leafs.Add(node); leafs.AddRange(GetMiddleNodes(node)); } } return leafs; }
public bool CheckTreeNodesExists(AbstractTreeNode parentNode) { throw new NotImplementedException(); }
public List <AbstractTreeNode> GetTreeNodes(AbstractTreeNode parentNode) { throw new NotImplementedException(); }