Пример #1
0
        private ZipDownloader MockZipDownloader()
        {
            ZipDownloader zipDownloader = Mock.Of <ZipDownloader>();

            Mock.Get(zipDownloader).CallBase = true;
            return(zipDownloader);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path">The path in the documentation folder structure that you wish to start from & list descendants</param>
        /// <param name="userType">Future Use: Backoffice Usertype requesting lessons</param>
        /// <param name="allowedSections">Future Use: AllowedSections of BackOffice User</param>
        /// <param name="lang">Future Use: Backoffice Users langunage</param>
        /// <param name="version">Umbraco CMS Version as a string</param>
        /// <returns>
        /// A partial part of the documentation tree, that lists out folders
        /// This is used in the new Starter Kit in conjuction with 'Lessons'
        /// </returns>
        public List <ZipDownloader.SiteMapItem> GetDocsForPath(string path, string userType, string allowedSections, string lang, string version)
        {
            //Ensure path is not null & empty
            if (string.IsNullOrEmpty(path))
            {
                var resp = new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content      = new StringContent("Path varibale is null or empty"),
                    ReasonPhrase = "Documentation Path is invalid"
                };

                throw new HttpResponseException(resp);
            }

            //Get the documentation Sitemap JS file that lives on disk everytime we fetch & unpack the markdown docs from GitHub
            var docs = new ZipDownloader();

            //Note: For now the folder param is NOT the folder/subtree but where the JSON file is stored to build up this model
            var allDocs = docs.DocumentationSiteMap();


            //Split path and ensure we can find each part of the path
            //In the array of nested objects
            var pathArray        = path.Split('/').Where(x => string.IsNullOrEmpty(x) == false).ToArray();
            var currentDirectory = allDocs;

            for (int i = 0; i < pathArray.Length; i++)
            {
                var pathPart = "/" + string.Join("/", pathArray.Take(i + 1));
                currentDirectory = currentDirectory.directories.First(x => x.path == pathPart);
            }

            return(currentDirectory.directories.OrderBy(x => x.sort).ToList());
        }
        public IEnumerable <SimpleDataSet> GetAllData(string indexType)
        {
            //Before getting all data, we need to make sure that the docs are available from GitHub
            ZipDownloader.EnsureGitHubDocs();


            var config   = DocumentationIndexConfig.Settings;
            var fullPath = HttpContext.Current.Server.MapPath(config.DirectoryToIndex);

            var directory = new DirectoryInfo(fullPath);

            var files = config.Recursive ? directory.GetFiles(config.SupportedFileTypes, SearchOption.AllDirectories) : directory.GetFiles(config.SupportedFileTypes);

            var i = 0; //unique id for each doc

            foreach (var file in files)
            {
                i++;
                var simpleDataSet = new SimpleDataSet {
                    NodeDefinition = new IndexedNode(), RowData = new Dictionary <string, string>()
                };
                simpleDataSet = ExamineHelper.MapFileToSimpleDataIndexItem(file, simpleDataSet, i, indexType);
                yield return(simpleDataSet);
            }
        }
Пример #4
0
        /// <summary>
        /// Gets Steps (Children of a lesson as rendered HTML from the markdown file)
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public List <LessonStep> GetStepsForPath(string path)
        {
            var docs       = new ZipDownloader();
            var rootFolder = global::Umbraco.Core.IO.IOHelper.MapPath("/Documentation/" + path);
            var mdFiles    = System.IO.Directory.GetFiles(rootFolder, "*.md");

            var result = new List <LessonStep>();

            foreach (var fpath in mdFiles)
            {
                var content = System.IO.File.ReadAllText(fpath);
                var name    = System.IO.Path.GetFileName(path);
                var md      = new MarkdownLogic(fpath);
                var html    = md.DoTransformation();

                result.Add(new LessonStep()
                {
                    Name = name, Content = html
                });
            }


            return(result);
        }