Ejemplo n.º 1
0
        public ActionResult ViewTree(string repo, string @object, string path)
        {
            var resourceInfo = this.FileManager.GetResourceInfo(repo);

            if (resourceInfo.Type != ResourceType.Directory)
            {
                return(HttpNotFound());
            }

            TreeView items;

            try
            {
                items = GitUtilities.GetTreeInfo(resourceInfo.FullPath, @object, path);
            }
            catch (GitErrorException)
            {
                return(HttpNotFound());
            }

            AddRepoBreadCrumb(repo);
            this.BreadCrumbs.Append("Browse", "ViewTree", @object, new { repo, @object, path = string.Empty });
            this.BreadCrumbs.Append("Browse", "ViewTree", BreadCrumbTrail.EnumeratePath(path), p => p.Key, p => new { repo, @object, path = p.Value });

            ViewBag.RepoName = resourceInfo.Name;
            ViewBag.Tree     = @object;
            ViewBag.Path     = path ?? string.Empty;

            return(View(items));
        }
Ejemplo n.º 2
0
        private void BreadCrumbTrail_MouseClick(object sender, MouseEventArgs e)
        {
            var item = BreadCrumbTrail.GetItemAt(e.Location);

            if (item == null && BreadCrumbTrail.Items.Count > 1)
            {
                CreateManualFileEntryControl(null, null);
            }
        }
Ejemplo n.º 3
0
        public SharedControllerBase()
        {
            var reposPath = WebConfigurationManager.AppSettings["RepositoriesPath"];

            this.fileManager = new FileManager(reposPath);

            this.breadCrumbs = new BreadCrumbTrail();
            ViewBag.BreadCrumbs = this.breadCrumbs;
        }
Ejemplo n.º 4
0
        public void TestBreadCrumbTrail()
        {
            var target = new BreadCrumbTrail();

            target.Add("A", "A", true);
            target.Add("B", "B", true);

            target.BackTo(1, true);
            Assert.AreEqual(2, target.Items.Count);

            target.BackTo(0, true);
            Assert.AreEqual(1, target.Items.Count);
            Assert.AreEqual("A", target.Items[0].Name);
        }
Ejemplo n.º 5
0
        protected SearchParameters CreateSearchParameters()
        {
            SearchParameters searchParameters;

            if (BreadCrumbTrail.Count > 0)
            {
                Uri url = BreadCrumbTrail.Last().Url;
                searchParameters = new SearchParameters(url.ToString().ToParameters());
            }
            else
            {
                searchParameters = new SearchParameters(new NameValueCollection());
            }
            return(searchParameters);
        }
Ejemplo n.º 6
0
        public ActionResult Fetch(string url)
        {
            url = url ?? string.Empty;
            var resourceInfo = this.FileManager.GetResourceInfo(url);

            if (resourceInfo.Type == ResourceType.NotFound)
            {
                return(HttpNotFound());
            }

            if (resourceInfo.Type == ResourceType.File)
            {
                return(File(resourceInfo.FullPath, "application/octet-stream"));
            }

            this.BreadCrumbs.Append("File", "Fetch", BreadCrumbTrail.EnumeratePath(url), p => p.Key, p => new { url = p.Value });

            return(View("List", resourceInfo));
        }
Ejemplo n.º 7
0
        public ActionResult ViewBlob(string repo, string @object, string path, bool raw = false)
        {
            var resourceInfo = this.FileManager.GetResourceInfo(repo);

            if (resourceInfo.Type != ResourceType.Directory || string.IsNullOrEmpty(path))
            {
                return(HttpNotFound());
            }

            var fileName       = Path.GetFileName(path);
            var containingPath = path.Substring(0, path.Length - fileName.Length);

            TreeView items;

            try
            {
                items = GitUtilities.GetTreeInfo(resourceInfo.FullPath, @object, containingPath);
            }
            catch (GitErrorException)
            {
                return(HttpNotFound());
            }

            if (!items.Objects.Any(o => o.Name == fileName))
            {
                return(HttpNotFound());
            }

            var contentType = MimeUtilities.GetMimeType(fileName);

            if (raw)
            {
                return(new GitFileResult(resourceInfo.FullPath, @object, path, contentType));
            }

            AddRepoBreadCrumb(repo);
            this.BreadCrumbs.Append("Browse", "ViewTree", @object, new { repo, @object, path = string.Empty });
            var paths = BreadCrumbTrail.EnumeratePath(path, TrailingSlashBehavior.LeaveOffLastTrailingSlash).ToList();

            this.BreadCrumbs.Append("Browse", "ViewTree", paths.Take(paths.Count() - 1), p => p.Key, p => new { repo, @object, path = p.Value });
            this.BreadCrumbs.Append("Browse", "ViewBlob", paths.Last().Key, new { repo, @object, path = paths.Last().Value });

            ViewBag.RepoName    = resourceInfo.Name;
            ViewBag.Tree        = @object;
            ViewBag.Path        = path;
            ViewBag.FileName    = fileName;
            ViewBag.ContentType = contentType;
            string model = null;

            if (contentType.StartsWith("text/") || contentType == "application/xml" || Regex.IsMatch(contentType, @"^application/.*\+xml$"))
            {
                using (var blob = GitUtilities.GetBlob(resourceInfo.FullPath, @object, path))
                {
                    using (var reader = new StreamReader(blob, detectEncodingFromByteOrderMarks: true))
                    {
                        model = reader.ReadToEnd();
                    }
                }
            }

            return(View((object)model));
        }