Exemplo n.º 1
0
        private static ReferencesViewModel SelectReferenceSection(ReferencesViewModel allReferences, Location range)
        {
            ReferencesViewModel referenceSection = new ReferencesViewModel();

            foreach (var reference in allReferences)
            {
                Dictionary <string, Section> sections = new Dictionary <string, Section>();
                foreach (var referenceKey in reference.Value.ReferenceKeys)
                {
                    foreach (var location in referenceKey.Value.Locations)
                    {
                        if (location.IsIn(range))
                        {
                            sections.Add(referenceKey.Key, referenceKey.Value);
                            continue;
                        }
                    }
                }

                if (sections.Count > 0)
                {
                    var referenceCloned = (MapFileItemViewModel)reference.Value.Clone();
                    referenceCloned.ReferenceKeys = sections;
                    referenceSection.AddItem(referenceCloned);
                }
            }

            return(referenceSection);
        }
Exemplo n.º 2
0
        public ParseResult Run(MapFileItemViewModel item, IndexerContext context)
        {
            var filePath = context.MarkdownFilePath;
            var apis     = context.ExternalApiIndex;
            var content  = context.MarkdownContent;
            var links    = LinkParser.Select(content);

            if (links == null || links.Count == 0)
            {
                return(new ParseResult(ResultLevel.Info, "No Api reference found for {0}", filePath));
            }
            if (item.References == null)
            {
                item.References = new ReferencesViewModel();
            }
            ReferencesViewModel references = item.References;

            foreach (var matchDetail in links)
            {
                var          referenceId = matchDetail.Id;
                var          apiId       = matchDetail.Id;
                MetadataItem api;
                if (apis.TryGetValue(apiId, out api))
                {
                    var reference = new MapFileItemViewModel
                    {
                        Id            = referenceId,
                        ReferenceKeys = matchDetail.MatchedSections,
                        Href          = FileExtensions.MakeRelativePath(Path.GetDirectoryName(filePath), api.Href),
                        MapFileType   = MapFileType.Link
                    };

                    // Api Index file only contains Id and Href
                    references.AddItem(reference);
                }
            }

            return(new ParseResult(ResultLevel.Success));
        }
Exemplo n.º 3
0
        public ParseResult Run(MapFileItemViewModel item, IndexerContext context)
        {
            var filePath     = context.MarkdownFilePath;
            var content      = context.MarkdownContent;
            var codeSnippets = CodeSnippetParser.Select(content);

            if (codeSnippets == null || codeSnippets.Count == 0)
            {
                return(new ParseResult(ResultLevel.Info, "No code snippet reference found for {0}", filePath));
            }
            if (item.References == null)
            {
                item.References = new ReferencesViewModel();
            }
            ReferencesViewModel references = item.References;
            var defaultReferenceFolder     = Environment.CurrentDirectory;
            var referenceFolder            = string.IsNullOrEmpty(context.ReferenceOutputFolder)
                                    ? defaultReferenceFolder
                                    : context.ReferenceOutputFolder;

            foreach (var codeSnippet in codeSnippets)
            {
                var referenceId     = codeSnippet.Id;
                var codeSnippetPath = FileExtensions.GetFullPath(Path.GetDirectoryName(filePath), codeSnippet.Path);
                // As reference, copy file to local
                var targetFileName = FileExtensions.MakeRelativePath(referenceFolder, codeSnippetPath).ToValidFilePath();
                // Append ref incase the file name starts with ".", which means a hidden file in Linux
                targetFileName = "ref" + targetFileName;
                var targetPath = Path.Combine(referenceFolder, targetFileName);
                MapFileItemViewModel reference;
                if (!File.Exists(codeSnippetPath))
                {
                    reference = new MapFileItemViewModel
                    {
                        Id            = referenceId,
                        ReferenceKeys = codeSnippet.MatchedSections,
                        Message       = string.Format("{0} does not exist.", Path.GetFullPath(codeSnippetPath)),
                        MapFileType   = MapFileType.CodeSnippet
                    };

                    ParseResult.WriteToConsole(ResultLevel.Warn, reference.Message);
                }
                else
                {
                    FileExtensions.CopyFile(codeSnippetPath, targetPath);
                    reference = new MapFileItemViewModel
                    {
                        Id            = referenceId,
                        ReferenceKeys = codeSnippet.MatchedSections,
                        Href          = FileExtensions.MakeRelativePath(Path.GetDirectoryName(filePath), targetPath).BackSlashToForwardSlash(),
                        Startline     = codeSnippet.StartLine,
                        Endline       = codeSnippet.EndLine,
                        MapFileType   = MapFileType.CodeSnippet
                    };
                }

                // Api Index file only contains Id and Href
                references.AddItem(reference);
            }

            return(new ParseResult(ResultLevel.Success));
        }