Beispiel #1
0
        internal static Dictionary <string, object> GetGlobalMetadataFromOption(Dictionary <string, object> globalMetadataFromConfig, string globalMetadataFilePath, ListWithStringFallback globalMetadataFilePaths, string globalMetadataContent)
        {
            Dictionary <string, object> globalMetadata = null;

            if (globalMetadataContent != null)
            {
                using var sr = new StringReader(globalMetadataContent);
                try
                {
                    globalMetadata = JsonUtility.Deserialize <Dictionary <string, object> >(sr, GetToObjectSerializer());
                }
                catch (JsonException e)
                {
                    Logger.LogWarning($"Metadata from \"--globalMetadata {globalMetadataContent}\" is not a valid JSON format global metadata, ignored: {e.Message}");
                }
            }

            if (globalMetadataFilePaths != null)
            {
                foreach (var filePath in globalMetadataFilePaths)
                {
                    globalMetadata = MergeMetadataFromFile("globalMetadata", globalMetadata, filePath, path => JsonUtility.Deserialize <Dictionary <string, object> >(path, GetToObjectSerializer()), MergeGlobalMetadataItem);
                }
            }

            if (globalMetadataFilePath != null)
            {
                globalMetadata = MergeMetadataFromFile("globalMetadata", globalMetadata, globalMetadataFilePath, path => JsonUtility.Deserialize <BuildJsonConfig>(path)?.GlobalMetadata, MergeGlobalMetadataItem);
            }

            return(OptionMerger.MergeDictionary(
                       new DictionaryMergeContext <object>("globalMetadata from docfx config file", globalMetadataFromConfig),
                       new DictionaryMergeContext <object>("globalMetadata merged with command option and globalMetadata config file", globalMetadata),
                       MergeGlobalMetadataItem));
        }
Beispiel #2
0
        private static Dictionary <string, T> MergeMetadataFromFile <T>(
            string metadataType,
            Dictionary <string, T> originalMetadata,
            string metadataFilePath,
            Func <string, Dictionary <string, T> > metadataFileLoader,
            OptionMerger.Merger <T> merger)
        {
            Dictionary <string, T> metadata = null;

            try
            {
                if (metadataFilePath != null)
                {
                    metadata = metadataFileLoader(metadataFilePath);
                }

                if (metadata == null)
                {
                    Logger.LogWarning($"File from \"{metadataType} config file {metadataFilePath}\" does not contain \"{metadataType}\" definition.");
                }
            }
            catch (FileNotFoundException)
            {
                Logger.LogWarning($"Invalid option \"{metadataType} config file {metadataFilePath}\": file does not exist, ignored.");
            }
            catch (JsonException e)
            {
                Logger.LogWarning($"File from \"{metadataType} config file {metadataFilePath}\" is not in valid JSON format, ignored: {e.Message}");
            }

            if (metadata != null)
            {
                return(OptionMerger.MergeDictionary(
                           new DictionaryMergeContext <T>($"globalMetadata config file {metadataFilePath}", metadata),
                           new DictionaryMergeContext <T>("previous global metadata", originalMetadata),
                           merger));
            }

            return(originalMetadata);
        }
Beispiel #3
0
        internal static Dictionary <string, FileMetadataPairs> GetFileMetadataFromOption(Dictionary <string, FileMetadataPairs> fileMetadataFromConfig, string fileMetadataFilePath, ListWithStringFallback fileMetadataFilePaths)
        {
            var fileMetadata = new Dictionary <string, FileMetadataPairs>();

            if (fileMetadataFilePaths != null)
            {
                foreach (var filePath in fileMetadataFilePaths)
                {
                    fileMetadata = MergeMetadataFromFile("fileMetadata", fileMetadata, filePath, path => JsonUtility.Deserialize <Dictionary <string, FileMetadataPairs> >(path), MergeFileMetadataPairs);
                }
            }

            if (fileMetadataFilePath != null)
            {
                fileMetadata = MergeMetadataFromFile("fileMetadata", fileMetadata, fileMetadataFilePath, path => JsonUtility.Deserialize <BuildJsonConfig>(path)?.FileMetadata, MergeFileMetadataPairs);
            }

            return(OptionMerger.MergeDictionary(
                       new DictionaryMergeContext <FileMetadataPairs>("fileMetadata from docfx config file", fileMetadataFromConfig),
                       new DictionaryMergeContext <FileMetadataPairs>("fileMetadata from fileMetadata config file", fileMetadata),
                       MergeFileMetadataPairs));
        }