Beispiel #1
0
        public ActionResult Blob(string id, string name, string path)
        {
            ViewBag.ID = id;
            if (!String.IsNullOrEmpty(id))
            {
                using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id)))
                {
                    string referenceName;
                    var    model = browser.BrowseBlob(name, path, out referenceName);
                    PopulateBranchesData(browser, referenceName);
                    PopulateAddressBarData(name, path);

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

                    return(View(model));
                }
            }
            return(View());
        }
        private string FillFileData(Leaf leaf)
        {
            var result = FileDisplayHandler.GetText(leaf.RawData);

            if (result != null)
            {
                return(result);
            }
            if (FileDisplayHandler.GetBrush(leaf.Name) != "plain")
            {
                return(ASCIIEncoding.ASCII.GetString(leaf.RawData));
            }
            return(null);
        }
Beispiel #3
0
        private ActionResult DisplayFiles(IEnumerable <RepositoryTreeDetailModel> files, string path, string id, bool returnAsBinary)
        {
            if (files != null)
            {
                var model = new RepositoryTreeModel();
                model.Name   = id;
                model.IsTree = !(files.Count() == 1 && !files.First().IsTree&& files.First().Path == path);
                if (model.IsTree)
                {
                    model.Files = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name);
                }
                else
                {
                    model.File = files.First();
                    if (!returnAsBinary)
                    {
                        model.Text       = FileDisplayHandler.GetText(model.File.Data);
                        model.IsTextFile = model.Text != null;

                        if (model.IsTextFile)
                        {
                            model.TextBrush = FileDisplayHandler.GetBrush(model.File.Name);
                        }

                        if (!model.IsTextFile)
                        {
                            model.IsImage = FileDisplayHandler.IsImage(model.File.Name);
                        }
                    }

                    if (!model.IsImage && !model.IsTextFile)
                    {
                        using (var stream = new MemoryStream(model.File.Data))
                        {
                            return(File(stream, "application/octet-stream", model.File.Name));
                        }
                    }
                }

                return(View(model));
            }

            return(View());
        }