Пример #1
0
        public ApiReferenceViewModel ToViewModel()
        {
            ApiReferenceViewModel viewModel = new ApiReferenceViewModel();

            foreach (var item in this)
            {
                viewModel[item.Value.Name] = item.Value.Href;
            }
            return(viewModel);
        }
Пример #2
0
        private static IList <string> ResolveAndExportYamlMetadata(
            Dictionary <string, MetadataItem> allMembers,
            Dictionary <string, ReferenceItem> allReferences,
            string folder,
            string indexFileName,
            string tocFileName,
            string apiFolder,
            bool preserveRawInlineComments,
            bool shouldSkipMarkup,
            IEnumerable <string> externalReferencePackages,
            bool useCompatibilityFileName)
        {
            var outputFiles = new List <string>();
            var model       = YamlMetadataResolver.ResolveMetadata(allMembers, allReferences, apiFolder, preserveRawInlineComments, externalReferencePackages);

            // 1. generate toc.yml
            outputFiles.Add(tocFileName);
            model.TocYamlViewModel.Type = MemberType.Toc;

            // TOC do not change
            var    tocViewModel = model.TocYamlViewModel.ToTocViewModel();
            string tocFilePath  = Path.Combine(folder, tocFileName);

            YamlUtility.Serialize(tocFilePath, tocViewModel, YamlMime.TableOfContent);

            ApiReferenceViewModel indexer = new ApiReferenceViewModel();

            // 2. generate each item's yaml
            var members = model.Members;

            foreach (var memberModel in members)
            {
                var outputPath = memberModel.Name + Constants.YamlExtension;
                if (!useCompatibilityFileName)
                {
                    outputPath = outputPath.Replace('`', '-');
                }
                outputFiles.Add(Path.Combine(apiFolder, outputPath));
                string itemFilePath = Path.Combine(folder, apiFolder, outputPath);
                Directory.CreateDirectory(Path.GetDirectoryName(itemFilePath));
                var memberViewModel = memberModel.ToPageViewModel();
                memberViewModel.ShouldSkipMarkup = shouldSkipMarkup;
                YamlUtility.Serialize(itemFilePath, memberViewModel, YamlMime.ManagedReference);
                Logger.Log(LogLevel.Verbose, $"Metadata file for {memberModel.Name} is saved to {itemFilePath}.");
                AddMemberToIndexer(memberModel, outputPath, indexer);
            }

            // 3. generate manifest file
            outputFiles.Add(indexFileName);
            string indexFilePath = Path.Combine(folder, indexFileName);

            JsonUtility.Serialize(indexFilePath, indexer);

            return(outputFiles);
        }
Пример #3
0
        private static IEnumerable <string> ResolveAndExportYamlMetadata(
            Dictionary <string, MetadataItem> allMembers,
            Dictionary <string, ReferenceItem> allReferences,
            string folder,
            bool preserveRawInlineComments,
            bool shouldSkipMarkup,
            bool useCompatibilityFileName)
        {
            var outputFileNames = new Dictionary <string, int>(FilePathComparer.OSPlatformSensitiveStringComparer);
            var model           = YamlMetadataResolver.ResolveMetadata(allMembers, allReferences, preserveRawInlineComments);

            var tocFileName = Constants.TocYamlFileName;

            // 0. load last Manifest and remove files
            CleanupHistoricalFile(folder);

            // 1. generate toc.yml
            model.TocYamlViewModel.Type = MemberType.Toc;

            // TOC do not change
            var    tocViewModel = model.TocYamlViewModel.ToTocViewModel();
            string tocFilePath  = Path.Combine(folder, tocFileName);

            YamlUtility.Serialize(tocFilePath, tocViewModel, YamlMime.TableOfContent);
            outputFileNames.Add(tocFilePath, 1);
            yield return(tocFileName);

            ApiReferenceViewModel indexer = new ApiReferenceViewModel();

            // 2. generate each item's yaml
            var members = model.Members;

            foreach (var memberModel in members)
            {
                var    fileName       = useCompatibilityFileName ? memberModel.Name : memberModel.Name.Replace('`', '-');
                var    outputFileName = GetUniqueFileNameWithSuffix(fileName + Constants.YamlExtension, outputFileNames);
                string itemFilePath   = Path.Combine(folder, outputFileName);
                Directory.CreateDirectory(Path.GetDirectoryName(itemFilePath));
                var memberViewModel = memberModel.ToPageViewModel();
                memberViewModel.ShouldSkipMarkup = shouldSkipMarkup;
                YamlUtility.Serialize(itemFilePath, memberViewModel, YamlMime.ManagedReference);
                Logger.Log(LogLevel.Diagnostic, $"Metadata file for {memberModel.Name} is saved to {itemFilePath}.");
                AddMemberToIndexer(memberModel, outputFileName, indexer);
                yield return(outputFileName);
            }

            // 3. generate manifest file
            string indexFilePath = Path.Combine(folder, IndexFileName);

            JsonUtility.Serialize(indexFilePath, indexer, Newtonsoft.Json.Formatting.Indented);
            yield return(IndexFileName);
        }
Пример #4
0
 private static void AddMemberToIndexer(MetadataItem memberModel, string outputPath, ApiReferenceViewModel indexer)
 {
     if (memberModel.Type == MemberType.Namespace)
     {
         indexer.Add(memberModel.Name, outputPath);
     }
     else
     {
         TreeIterator.Preorder(memberModel, null, s => s.Items, (member, parent) =>
         {
             if (indexer.TryGetValue(member.Name, out string path))
             {
                 Logger.LogWarning($"{member.Name} already exists in {path}, the duplicate one {outputPath} will be ignored.");
             }
             else
             {
                 indexer.Add(member.Name, outputPath);
             }
             return(true);
         });
     }
 }