public ActionResult Tree(string id, string encodedName, string encodedPath) { ViewBag.ID = id; if (!String.IsNullOrEmpty(id)) { using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, id))) { var name = PathEncoder.Decode(encodedName); var path = PathEncoder.Decode(encodedPath); string referenceName; var files = browser.BrowseTree(name, path, out referenceName); PopulateBranchesData(browser, referenceName); PopulateAddressBarData(name, path); var model = new RepositoryTreeModel(); model.Name = id; model.Branch = name; model.Path = path; model.Files = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name); return(View(model)); } } return(View()); }
public ActionResult Tree(Guid id, string encodedName, string encodedPath) { bool includeDetails = Request.IsAjaxRequest(); var name = PathEncoder.Decode(encodedName); var path = PathEncoder.Decode(encodedPath); var repo = RepositoryRepository.GetRepository(id); var repositoryDetailModel = ConvertRepositoryModel(repo, User); ViewBag.ID = id; ViewBag.Name = repo.Name; ViewBag.GitUrl = GitUrl(repo.Name); using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name))) { string referenceName; var files = browser.BrowseTree(name, path, out referenceName, includeDetails).ToList(); var readme = files.FirstOrDefault(x => x.Name.Equals("readme.md", StringComparison.OrdinalIgnoreCase)); 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 = repo.Name, Branch = name ?? referenceName, Path = path, Readme = readmeTxt, Logo = new RepositoryLogoDetailModel(repo.Logo), Files = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name) }; 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 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)); } } }
public ActionResult Detail(Guid id) { var mater = ConvertRepositoryModel(RepositoryRepository.GetRepository(id), User); if (mater != null) { mater.IsCurrentUserAdministrator = RepositoryPermissionService.HasPermission(User.Id(), mater.Id, RepositoryAccessLevel.Administer); SetGitUrls(mater); } ViewBag.ID = id; ViewBag.Name = mater.Name; ViewBag.GitUrl = mater.GitUrl; //using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, model.Name))) //{ // string defaultReferenceName; // browser.BrowseTree(null, null, out defaultReferenceName); // RouteData.Values.Add("encodedName", defaultReferenceName); //} bool includeDetails = Request.IsAjaxRequest(); var name = PathEncoder.Decode(null); var path = PathEncoder.Decode(null); var repo = RepositoryRepository.GetRepository(id); var repositoryDetailModel = ConvertRepositoryModel(repo, User); using (var browser = new RepositoryBrowser(Path.Combine(UserConfiguration.Current.Repositories, repo.Name))) { string referenceName; var files = browser.BrowseTree(name, path, out referenceName, includeDetails).ToList(); PopulateBranchesData(browser, referenceName); var readme = files.FirstOrDefault(x => x.Name.Equals("readme.md", StringComparison.OrdinalIgnoreCase)); 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 = repo.Name, Branch = name ?? referenceName, Path = path, Readme = readmeTxt, Logo = new RepositoryLogoDetailModel(repo.Logo), Files = files.OrderByDescending(i => i.IsTree).ThenBy(i => i.Name) }; if (includeDetails) { return(Json(model, JsonRequestBehavior.AllowGet)); } else { PopulateBranchesData(browser, referenceName); PopulateAddressBarData(path); return(View(model)); } } }