Exemplo n.º 1
0
        private async Task<IEnumerable<DynamicNode>> CreateSiteMapNodesAsync(NodeElement item, string parentKey = null)
        {
            if (item == null) throw new ArgumentNullException(nameof(item));
            if (MarkDocs == null) throw new ArgumentNullException(nameof(MarkDocs));

            var result = new List<DynamicNode>();

            var parentSiteMapNode = new DynamicNode
            {
                Key = Guid.NewGuid().ToString(),
                ParentKey = parentKey,
                Title = DisplayFor(item.Display, item.Localized),
                Folder = item.TargetFolder
            };
            result.Add(parentSiteMapNode);

            // Determine remote folder to load the document files from
            var urls = await MarkDocs.GetUrlsFromChildItemsAsync(item).ConfigureAwait(false);
            var docs = urls.Single(u => u.Key == item.SourceFolder).Value;
            if (item.Localized)
            {
                var cultureCode = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
                urls = await MarkDocs.GetUrlsFromChildItemsAsync(docs, item.Username, item.Password).ConfigureAwait(false);
                docs = urls.Single(u => u.Key == cultureCode).Value;
            }

            // Get remote documents and generate siteMapItems for them
            var files = await MarkDocs.GetChildItemsFileNamesAsync(docs, item.Username, item.Password).ConfigureAwait(false);
            var siteMapNodes = CreateSiteMapNodes(item.Localized, item.TargetFolder, files);
            foreach (var siteMapNode in siteMapNodes)
            {
                siteMapNode.ParentKey = parentSiteMapNode.Key;
                result.Add(siteMapNode);
            }

            // Do the same as above, recursively, for each child NodeElement
            foreach (var child in item.Items)
            {
                var childItemSiteMapNodes = await CreateSiteMapNodesAsync(child, parentSiteMapNode.Key).ConfigureAwait(false);
                result.AddRange(childItemSiteMapNodes);
            }
            return result;
        }
Exemplo n.º 2
0
 private async Task<string> GetFileNameAsync(NodeElement node, string document)
 {
     var fileNames = await GetFileNamesAsync(node).ConfigureAwait(false);
     var fileName = fileNames.SingleOrDefault(fn => fn.EndsWith($"-{document}.md"));
     return fileName;
 }
Exemplo n.º 3
0
        private async Task<IEnumerable<string>> GetFileNamesAsync(NodeElement node)
        {
            var urls = await GetUrlsFromChildItemsAsync(node).ConfigureAwait(false);
            var docs = urls.Single(u => u.Key == node.SourceFolder).Value;
            string cultureCode;
            if (node.Localized)
            {
                cultureCode = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
                urls = await GetUrlsFromChildItemsAsync(docs, node.Username, node.Password).ConfigureAwait(false);
                docs = urls.SingleOrDefault(u => u.Key == cultureCode).Value ??
                       urls.SingleOrDefault(u => u.Key == Settings.DefaultLanguage).Value;
                if (docs == null)
                    return Enumerable.Empty<string>();
            }

            var fileNames = await GetChildItemsFileNamesAsync(docs, node.Username, node.Password);

            return fileNames;
        }
Exemplo n.º 4
0
 internal async Task<IDictionary<string, string>> GetUrlsFromChildItemsAsync(NodeElement item)
 {
     var parentUrl = $"https://api.github.com/repos/{item.Owner}/{item.Repo}/git/trees/{item.Branch}";
     return await GetUrlsFromChildItemsAsync(parentUrl, item.Username, item.Password).ConfigureAwait(false);
 }