public PathViewModel(RepositoryNavigationRequest request, AbstractTreeNode node)
        {
            Elements = new List<Element>();

            CurrentItem = new Element(
                new RepositoryNavigationRequest(request) { Path = node.Path },
                request.Treeish,
                node);

            var currentNode = node;

            while (currentNode.Parent != null)
            {
                currentNode = currentNode.Parent;
                if (currentNode.Parent != null)
                {
                    Elements.Add(
                        new Element(new RepositoryNavigationRequest(request) { Path = currentNode.Path },
                        request.Treeish,
                        currentNode));
                }
            }

            Elements = new List<Element>(Elements.Reverse());
            Root = new Element(request, request.Treeish, currentNode);
            IsRootEqualToCurrentItem = (currentNode == node);
        }
 public Element(RepositoryNavigationRequest request, string treeish, AbstractTreeNode node)
 {
     Text = !String.IsNullOrEmpty(node.Name) ? node.Name : request.RepositoryName;
     RepositoryName = request.RepositoryName;
     Path = node.Path;
     Treeish = treeish;
     RepositoryLocation = request.RepositoryLocation;
 }
        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 TreeNodeViewModel(Repository repository, RepositoryNavigationRequest request, AbstractTreeNode node)
     : base(request)
 {
     Node = node;
 }
        private static AbstractTreeNode GetNode(AbstractTreeNode parentNode, IEnumerable<string> parts)
        {
            if (parts.Any())
            {
                if (parentNode.IsTree)
                {
                    var name = parts.First();
                    var treeNode = (Tree)parentNode;
                    parentNode = treeNode.Trees.SingleOrDefault(x => x.Name == name);
                    if(parentNode == null)
                        parentNode = treeNode.Leaves.SingleOrDefault(x => x.Name == name);
                    if(parentNode == null)
                        throw new InvalidOperationException("Unable to determine path.");

                    return GetNode(parentNode, parts.Skip(1));
                }
                else
                {
                    throw new InvalidOperationException("Unable to determine path.");
                }
            }

            return parentNode;
        }
 private static GitSourceObject CreateGitSourceObject(string tree, AbstractTreeNode node)
 {
     if (node.IsTree)
     {
         var treeNode = (Tree)node;
         return new GitSourceDirectory
         {
             Name = treeNode.Name,
             IsDirectory = true,
             CommitId = treeNode.GetLastCommit().Hash,
             TreeId = tree,
             Path = node.Path,
             DateTime = treeNode.GetLastCommit().CommitDate.DateTime,
             Message = treeNode.GetLastCommit().Message,
             Children = treeNode.Trees.Select(x => CreateGitSourceObject(tree, x))
                 .Union(treeNode.Leaves.Select(x => CreateGitSourceObject(tree, x)))
         };
     }
     else
     {
         var leafNode = (Leaf)node;
         return new GitSourceFile
         {
             Name = node.Name,
             IsDirectory = false,
             CommitId = leafNode.GetLastCommit().Hash,
             TreeId = tree,
             Path = node.Path,
             DateTime = node.GetLastCommit().CommitDate.DateTime,
             Message = node.GetLastCommit().Message,
             Content = leafNode.RawData
         };
     }
 }