public ActionResult Tree(string id, string encodedName, string encodedPath) { bool includeDetails = Request.IsAjaxRequest(); if (String.IsNullOrEmpty(id)) return View(); ViewBag.ID = id; var name = PathEncoder.Decode(encodedName); var path = PathEncoder.Decode(encodedPath); using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id))) { string referenceName; var files = browser.BrowseTree(name, path, out referenceName, includeDetails); var readme = files.Where(x => x.Path.Equals("readme.md", StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); string readmeTxt = string.Empty; if (readme != null) { string refereceName; var blob = browser.BrowseBlob(name, readme.Path, out refereceName); readmeTxt = blob.Text; } var model = new RepositoryTreeModel { Name = id, Branch = name, Path = path, Files = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name), Readme = readmeTxt }; if (includeDetails) { return Json(model, JsonRequestBehavior.AllowGet); } else { PopulateBranchesData(browser, referenceName); PopulateAddressBarData(path); return View(model); } } }
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(); }
public ActionResult Tree(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 files = browser.BrowseTree(name, path, out referenceName); PopulateBranchesData(browser, referenceName); PopulateAddressBarData(name, path); var model = new RepositoryTreeModel(); model.Name = id; //model.IsTree = true; model.Files = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name); return View(model); } } return View(); }
public ActionResult Tree(string id, string encodedName, string encodedPath) { bool includeDetails = Request.IsAjaxRequest(); if (String.IsNullOrEmpty(id)) return View(); ViewBag.ID = id; var name = PathEncoder.Decode(encodedName); var path = PathEncoder.Decode(encodedPath); using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id))) { string referenceName; var files = browser.BrowseTree(name, path, out referenceName, includeDetails); var model = new RepositoryTreeModel { Name = id, Branch = name, Path = path, Files = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name), }; if (includeDetails) { return Json(model, JsonRequestBehavior.AllowGet); } else { PopulateBranchesData(browser, referenceName); PopulateAddressBarData(name, path); return View(model); } } }