public RepositoryTreeDetailModel BrowseBlob(string name, string path, out string referenceName)
        {
            if (path == null)
            {
                path = String.Empty;
            }

            var commit = GetCommitByName(name, out referenceName);

            if (commit == null)
            {
                return(null);
            }

            var entry = commit[path];

            if (entry == null)
            {
                return(null);
            }

            var model = new RepositoryTreeDetailModel
            {
                Name          = entry.Name,
                IsTree        = false,
                IsLink        = false,
                CommitDate    = commit.Author.When.LocalDateTime,
                CommitMessage = commit.Message,
                Author        = commit.Author.Name,
                TreeName      = referenceName ?? name,
                Path          = path,
            };

            using (var memoryStream = new MemoryStream())
            {
                ((Blob)entry.Target).GetContentStream().CopyTo(memoryStream);
                model.Data = memoryStream.ToArray();
            }

            model.Text       = FileDisplayHandler.GetText(model.Data);
            model.Encoding   = FileDisplayHandler.GetEncoding(model.Data);
            model.IsText     = model.Text != null;
            model.IsMarkdown = model.IsText && Path.GetExtension(path).Equals(".md", StringComparison.OrdinalIgnoreCase);
            model.TextBrush  = FileDisplayHandler.GetBrush(path);

            // try to render as text file if the extension matches
            if (model.TextBrush != FileDisplayHandler.NoBrush && model.IsText == false)
            {
                model.IsText   = true;
                model.Encoding = Encoding.Default;
                model.Text     = new StreamReader(new MemoryStream(model.Data), model.Encoding, true).ReadToEnd();
            }

            //blobs can be images even when they are text files.(like svg, but it's not in out MIME table yet)
            model.IsImage = FileDisplayHandler.IsImage(path);

            return(model);
        }
Example #2
0
        public RepositoryTreeDetailModel BrowseBlob(string name, string path, out string referenceName)
        {
            if (path == null)
            {
                path = String.Empty;
            }

            var commit = GetCommitByName(name, out referenceName);

            if (commit == null)
            {
                return(null);
            }

            var entry = commit[path];

            if (entry == null)
            {
                return(null);
            }

            var model = new RepositoryTreeDetailModel
            {
                Name          = entry.Name,
                IsTree        = false,
                IsLink        = false,
                CommitDate    = commit.Author.When.LocalDateTime,
                CommitMessage = commit.Message,
                Author        = commit.Author.Name,
                TreeName      = referenceName ?? name,
                Path          = path,
            };

            using (var memoryStream = new MemoryStream())
            {
                ((Blob)entry.Target).GetContentStream().CopyTo(memoryStream);
                model.Data = memoryStream.ToArray();
            }

            model.Text       = FileDisplayHandler.GetText(model.Data);
            model.Encoding   = FileDisplayHandler.GetEncoding(model.Data);
            model.IsText     = model.Text != null;
            model.IsMarkdown = model.IsText && Path.GetExtension(path).Equals(".md", StringComparison.OrdinalIgnoreCase);
            if (model.IsText)
            {
                model.TextBrush = FileDisplayHandler.GetBrush(path);
            }
            else
            {
                model.IsImage = FileDisplayHandler.IsImage(path);
            }

            return(model);
        }
 private RepositoryTreeDetailModel CreateRepositoryDetailModel(TreeEntry entry, Commit ancestor, string treeName)
 {
     return(new RepositoryTreeDetailModel
     {
         Name = entry.Name,
         CommitDate = ancestor != null ? ancestor.Author.When.LocalDateTime : default(DateTime?),
         CommitMessage = ancestor != null ? ancestor.MessageShort : String.Empty,
         Author = ancestor != null ? ancestor.Author.Name : String.Empty,
         IsTree = entry.TargetType == TreeEntryTargetType.Tree,
         TreeName = treeName,
         Path = entry.Path.Replace('\\', '/'),
         IsImage = FileDisplayHandler.IsImage(entry.Name),
     });
 }
Example #4
0
        public RepositoryTreeDetailModel BrowseBlob(string name, string path, out string referenceName)
        {
            if (path == null)
            {
                path = String.Empty;
            }

            var commit = GetCommitByName(name, out referenceName);

            if (commit == null)
            {
                return(null);
            }

            var entry = commit[path];

            if (entry == null)
            {
                return(null);
            }

            var model = new RepositoryTreeDetailModel
            {
                Name          = entry.Name,
                IsTree        = false,
                CommitDate    = commit.Author.When.LocalDateTime,
                CommitMessage = commit.Message,
                Author        = commit.Author.Name,
                TreeName      = referenceName ?? name,
                Path          = path,
                Data          = ((Blob)entry.Target).Content,
            };

            model.Text     = FileDisplayHandler.GetText(model.Data);
            model.Encoding = FileDisplayHandler.GetEncoding(model.Data);
            model.IsText   = model.Text != null;
            if (model.IsText)
            {
                model.TextBrush = FileDisplayHandler.GetBrush(path);
            }
            else
            {
                model.IsImage = FileDisplayHandler.IsImage(path);
            }

            return(model);
        }
        private RepositoryTreeDetailModel CreateRepositoryDetailModel(TreeEntry entry, Commit ancestor, string treeName)
        {
            var maximumMessageLength = 50; //FIXME Propbably in appSettings?
            var originMessage        = ancestor != null ? ancestor.Message : String.Empty;
            var commitMessage        = !String.IsNullOrEmpty(originMessage)
                ? RepositoryCommitModelHelpers.MakeCommitMessage(originMessage, maximumMessageLength).ShortTitle : String.Empty;

            return(new RepositoryTreeDetailModel
            {
                Name = entry.Name,
                CommitDate = ancestor != null ? ancestor.Author.When.LocalDateTime : default(DateTime?),
                CommitMessage = commitMessage,
                Author = ancestor != null ? ancestor.Author.Name : String.Empty,
                IsTree = entry.TargetType == TreeEntryTargetType.Tree,
                IsLink = entry.TargetType == TreeEntryTargetType.GitLink,
                TreeName = treeName,
                Path = entry.Path.Replace('\\', '/'),
                IsImage = FileDisplayHandler.IsImage(entry.Name),
            });
        }