Exemplo n.º 1
0
        public void Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                                  s => s.IsInvalid ? null : s.Items,
                                  (member, parent) =>
            {
                if (member.Type != MemberType.Toc)
                {
                    ApiIndexItemModel item;
                    if (yaml.Indexer.TryGetValue(member.Name, out item))
                    {
                        Logger.Log(LogLevel.Warning, $"{member.Name} already exists in {item.Href}, the duplicate one {member.Href} will be ignored.");
                    }
                    else
                    {
                        yaml.Indexer.Add(
                            member.Name,
                            new ApiIndexItemModel {
                            Name = member.Name, Href = context.ApiFolder.ForwardSlashCombine(member.Href)
                        });
                    }
                }

                return(true);
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// TODO: input Namespace list instead; 
        /// TODO: Save to ...yml.map
        /// </summary>
        /// <param name="allMembers"></param>
        /// <returns></returns>
        public static MetadataModel ResolveMetadata(
            Dictionary<string, MetadataItem> allMembers,
            Dictionary<string, ReferenceItem> allReferences,
            string apiFolder,
            bool preserveRawInlineComments,
            IEnumerable<string> externalReferencePackages)
        {
            MetadataModel viewModel = new MetadataModel();
            viewModel.TocYamlViewModel = new MetadataItem()
            {
                Type = MemberType.Toc,
                Items = allMembers.Where(s => s.Value.Type == MemberType.Namespace).Select(s => s.Value).ToList(),
            };
            viewModel.Members = new List<MetadataItem>();
            ResolverContext context = new ResolverContext
            {
                ApiFolder = apiFolder,
                References = allReferences,
                PreserveRawInlineComments = preserveRawInlineComments,
                ExternalReferences = externalReferencePackages == null ? null : new ExternalReferencePackageCollection(externalReferencePackages),
            };

            ExecutePipeline(viewModel, context);

            return viewModel;
        }
Exemplo n.º 3
0
 public void Run(MetadataModel yaml, ResolverContext context)
 {
     TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                           s => s.IsInvalid ? null : s.Items,
                           (current, parent) =>
     {
         if (current.References != null)
         {
             foreach (var referenceItem in current.References.Values)
             {
                 if (referenceItem.Parts != null)
                 {
                     foreach (var links in referenceItem.Parts.Values)
                     {
                         foreach (var item in links)
                         {
                             SetHref(item, yaml.Indexer, current.Name, context);
                         }
                     }
                 }
             }
         }
         return(true);
     });
 }
Exemplo n.º 4
0
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                                  s =>
            {
                if (s.IsInvalid || (s.Type != MemberType.Namespace && s.Type != MemberType.Toc))
                {
                    return(null);
                }
                else
                {
                    return(s.Items);
                }
            },
                                  (member, parent) =>
            {
                if (member.Type != MemberType.Toc)
                {
                    yaml.Members.Add(member);
                }

                return(true);
            });

            return(new ParseResult(ResultLevel.Success));
        }
Exemplo n.º 5
0
 public static void ExecutePipeline(MetadataModel yaml, ResolverContext context)
 {
     foreach (var pipeline in pipelines)
     {
         pipeline.Run(yaml, context);
     }
 }
Exemplo n.º 6
0
 public static void ExecutePipeline(MetadataModel yaml, ResolverContext context)
 {
     foreach (var pipeline in pipelines)
     {
         pipeline.Run(yaml, context);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// TODO: input Namespace list instead;
        /// TODO: Save to ...yml.map
        /// </summary>
        /// <param name="allMembers"></param>
        /// <returns></returns>
        public static MetadataModel ResolveMetadata(
            Dictionary <string, MetadataItem> allMembers,
            Dictionary <string, ReferenceItem> allReferences,
            string apiFolder,
            bool preserveRawInlineComments,
            IEnumerable <string> externalReferencePackages)
        {
            MetadataModel viewModel = new MetadataModel();

            viewModel.Indexer          = new ApiReferenceModel();
            viewModel.TocYamlViewModel = new MetadataItem()
            {
                Type  = MemberType.Toc,
                Items = allMembers.Where(s => s.Value.Type == MemberType.Namespace).Select(s => s.Value).ToList(),
            };
            viewModel.Members = new List <MetadataItem>();
            ResolverContext context = new ResolverContext
            {
                ApiFolder  = apiFolder,
                References = allReferences,
                PreserveRawInlineComments = preserveRawInlineComments,
                ExternalReferences        = externalReferencePackages == null ? null : new ExternalReferencePackageCollection(externalReferencePackages),
            };
            var result = ExecutePipeline(viewModel, context);

            Logger.Log(result);
            return(viewModel);
        }
Exemplo n.º 8
0
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                s => s.IsInvalid ? null : s.Items,
                (current, parent) =>
                {
                    if (current.References != null)
                    {
                        foreach (var referenceItem in current.References.Values)
                        {
                            if (referenceItem.Parts != null)
                            {
                                foreach (var links in referenceItem.Parts.Values)
                                {
                                    foreach (var item in links)
                                    {
                                        SetHref(item, yaml.Indexer, current.Name, context);
                                    }
                                }
                            }
                        }
                    }
                    return true;
                });

            return new ParseResult(ResultLevel.Success);
        }
Exemplo n.º 9
0
        public void Run(MetadataModel yaml, ResolverContext context)
        {
            yaml.TocYamlViewModel = yaml.TocYamlViewModel.ShrinkToSimpleTocWithNamespaceNotEmpty();
            // Comparing to toc files, yaml files are all in api folder
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                                  (s) =>
            {
                if (s.IsInvalid)
                {
                    return(null);
                }
                else
                {
                    return(s.Items);
                }
            }, (current, parent) =>
            {
                if (current.Type != MemberType.Toc)
                {
                    if (!string.IsNullOrEmpty(current.Href))
                    {
                        current.Href = context.ApiFolder.ForwardSlashCombine(current.Href);
                    }
                }

                return(true);
            });
        }
Exemplo n.º 10
0
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                s => s.IsInvalid ? null : s.Items,
                (member, parent) =>
                {
                    if (member.Type != MemberType.Toc)
                    {
                        ApiIndexItemModel item;
                        if (yaml.Indexer.TryGetValue(member.Name, out item))
                        {
                            Logger.Log(LogLevel.Warning, $"{member.Name} already exists in {item.Href}, the duplicate one {member.Href} will be ignored.");
                        }
                        else
                        {
                            yaml.Indexer.Add(
                                member.Name,
                                new ApiIndexItemModel { Name = member.Name, Href = context.ApiFolder.ForwardSlashCombine(member.Href) });
                        }
                    }

                    return true;
                });

            return new ParseResult(ResultLevel.Success);
        }
Exemplo n.º 11
0
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                                  s => s.IsInvalid ? null : s.Items,
                                  (current, parent) =>
            {
                current.Parent = parent;
                return(true);
            });

            return(new ParseResult(ResultLevel.Success));
        }
Exemplo n.º 12
0
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                s => s.IsInvalid ? null : s.Items,
                (current, parent) =>
                {
                    current.Parent = parent;
                    return true;
                });

            return new ParseResult(ResultLevel.Success);
        }
Exemplo n.º 13
0
        /// <summary>
        /// The yaml layout should be 
        /// namespace -- class level -- method level
        /// </summary>
        /// <param name="allMembers"></param>
        /// <returns></returns>
        public void Run(MetadataModel yaml, ResolverContext context)
        {
            StringBuilder message = new StringBuilder();
            foreach (var member in yaml.TocYamlViewModel.Items)
            {
                var result = CheckNamespaces(member);
                if (!string.IsNullOrEmpty(result))
                {
                    message.AppendLine(result);
                }
            }

            if (message.Length > 0)
            {
                Logger.LogWarning(message.ToString());
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// The yaml layout should be 
        /// namespace -- class level -- method level
        /// </summary>
        /// <param name="allMembers"></param>
        /// <returns></returns>
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            ParseResult overall = new ParseResult(ResultLevel.Success);
            StringBuilder message = new StringBuilder();
            foreach (var member in yaml.TocYamlViewModel.Items)
            {
                CheckNamespaces(member);
            }

            if (message.Length > 0)
            {
                overall.ResultLevel = ResultLevel.Warning;
                overall.Message = message.ToString();
            }

            return overall;
        }
Exemplo n.º 15
0
        /// <summary>
        /// The yaml layout should be
        /// namespace -- class level -- method level
        /// </summary>
        /// <param name="allMembers"></param>
        /// <returns></returns>
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            ParseResult   overall = new ParseResult(ResultLevel.Success);
            StringBuilder message = new StringBuilder();

            foreach (var member in yaml.TocYamlViewModel.Items)
            {
                CheckNamespaces(member);
            }

            if (message.Length > 0)
            {
                overall.ResultLevel = ResultLevel.Warning;
                overall.Message     = message.ToString();
            }

            return(overall);
        }
Exemplo n.º 16
0
        /// <summary>
        /// The yaml layout should be
        /// namespace -- class level -- method level
        /// </summary>
        /// <param name="allMembers"></param>
        /// <returns></returns>
        public void Run(MetadataModel yaml, ResolverContext context)
        {
            StringBuilder message = new StringBuilder();

            foreach (var member in yaml.TocYamlViewModel.Items)
            {
                var result = CheckNamespaces(member);
                if (!string.IsNullOrEmpty(result))
                {
                    message.AppendLine(result);
                }
            }

            if (message.Length > 0)
            {
                Logger.LogWarning(message.ToString());
            }
        }
Exemplo n.º 17
0
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                                  s => s.IsInvalid ? null : s.Items,
                                  (current, parent) =>
            {
                MetadataItem page;
                var addingReferences   = new List <ReferenceItem>();
                var documentReferences = current.References;
                if (current.Type.IsPageLevel())
                {
                    page = current;
                    current.References = new Dictionary <string, ReferenceItem>();
                }
                else
                {
                    page = parent;
                    current.References = null;
                }
                if (documentReferences != null && documentReferences.Count > 0)
                {
                    foreach (var key in documentReferences.Keys)
                    {
                        TryAddReference(context, page, addingReferences, key);
                    }
                }
                foreach (var key in GetReferenceKeys(current))
                {
                    TryAddReference(context, page, addingReferences, key);
                }
                if (current.Type == MemberType.Namespace)
                {
                    foreach (var item in current.Items)
                    {
                        TryAddReference(context, page, addingReferences, item.Name);
                    }
                }
                AddIndirectReference(context, page, addingReferences);
                return(true);
            });

            return(new ParseResult(ResultLevel.Success));
        }
Exemplo n.º 18
0
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                s => s.IsInvalid ? null : s.Items,
                (current, parent) =>
                {
                    MetadataItem page;
                    var addingReferences = new List<ReferenceItem>();
                    var documentReferences = current.References;
                    if (current.Type.IsPageLevel())
                    {
                        page = current;
                        current.References = new Dictionary<string, ReferenceItem>();
                    }
                    else
                    {
                        page = parent;
                        current.References = null;
                    }
                    if (documentReferences != null && documentReferences.Count > 0)
                    {
                        foreach (var key in documentReferences.Keys)
                        {
                            TryAddReference(context, page, addingReferences, key);
                        }
                    }
                    foreach (var key in GetReferenceKeys(current))
                    {
                        TryAddReference(context, page, addingReferences, key);
                    }
                    if (current.Type == MemberType.Namespace)
                    {
                        foreach (var item in current.Items)
                        {
                            TryAddReference(context, page, addingReferences, item.Name);
                        }
                    }
                    AddIndirectReference(context, page, addingReferences);
                    return true;
                });

            return new ParseResult(ResultLevel.Success);
        }
Exemplo n.º 19
0
        public static ParseResult ExecutePipeline(MetadataModel yaml, ResolverContext context)
        {
            ParseResult result = new ParseResult(ResultLevel.Success);
            foreach (var pipeline in pipelines)
            {
                result = pipeline.Run(yaml, context);
                if (result.ResultLevel == ResultLevel.Error)
                {
                    return result;
                }

                if (!string.IsNullOrEmpty(result.Message))
                {
                    Logger.Log(result);
                }
            }

            return result;
        }
Exemplo n.º 20
0
        public static ParseResult ExecutePipeline(MetadataModel yaml, ResolverContext context)
        {
            ParseResult result = new ParseResult(ResultLevel.Success);

            foreach (var pipeline in pipelines)
            {
                result = pipeline.Run(yaml, context);
                if (result.ResultLevel == ResultLevel.Error)
                {
                    return(result);
                }

                if (!string.IsNullOrEmpty(result.Message))
                {
                    Logger.Log(result);
                }
            }

            return(result);
        }
Exemplo n.º 21
0
        public void Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                                  s => s.IsInvalid ? null : s.Items,
                                  (member, parent) =>
            {
                // get all the possible places where link is possible
                if (member.Syntax != null && member.Syntax.Content != null)
                {
                    SyntaxLanguage[] keys = new SyntaxLanguage[member.Syntax.Content.Count];
                    member.Syntax.Content.Keys.CopyTo(keys, 0);
                    foreach (var key in keys)
                    {
                        member.Syntax.Content[key] = NormalizeLines(member.Syntax.Content[key]);
                    }
                }

                return(true);
            });
        }
Exemplo n.º 22
0
        public void Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                s => s.IsInvalid ? null : s.Items,
                (member, parent) =>
                {
                    // get all the possible places where link is possible
                    if (member.Syntax != null && member.Syntax.Content != null)
                    {
                        SyntaxLanguage[] keys = new SyntaxLanguage[member.Syntax.Content.Count];
                        member.Syntax.Content.Keys.CopyTo(keys, 0);
                        foreach(var key in keys)
                        {
                            member.Syntax.Content[key] = NormalizeLines(member.Syntax.Content[key]);
                        }
                    }

                    return true;
                });
        }
Exemplo n.º 23
0
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                s =>
                {
                    if (s.IsInvalid || (s.Type != MemberType.Namespace && s.Type != MemberType.Toc)) return null;
                    else return s.Items;
                },
                (member, parent) =>
                {
                    if (member.Type != MemberType.Toc)
                    {
                        yaml.Members.Add(member);
                    }

                    return true;
                });

            return new ParseResult(ResultLevel.Success);
        }
Exemplo n.º 24
0
        public void Run(MetadataModel yaml, ResolverContext context)
        {
            yaml.TocYamlViewModel = yaml.TocYamlViewModel.ShrinkToSimpleTocWithNamespaceNotEmpty();
            // Comparing to toc files, yaml files are all in api folder
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                (s) =>
                {
                    if (s.IsInvalid) return null;
                    else return s.Items;
                }, (current, parent) =>
                {
                    if (current.Type != MemberType.Toc)
                    {
                        if (!string.IsNullOrEmpty(current.Href))
                        {
                            current.Href = context.ApiFolder.ForwardSlashCombine(current.Href);
                        }
                    }

                    return true;
                });
        }
Exemplo n.º 25
0
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                                  s => s.IsInvalid ? null : s.Items,
                                  (current, parent) =>
            {
                if (current.Type != MemberType.Toc)
                {
                    if (current.Type.IsPageLevel())
                    {
                        current.Href = current.Name + Constants.YamlExtension;
                    }
                    else
                    {
                        current.Href = parent.Href;
                    }
                }

                return(true);
            });

            return(new ParseResult(ResultLevel.Success));
        }
Exemplo n.º 26
0
        public ParseResult Run(MetadataModel yaml, ResolverContext context)
        {
            TreeIterator.Preorder(yaml.TocYamlViewModel, null,
                s => s.IsInvalid ? null : s.Items,
                (current, parent) =>
                {
                    if (current.Type != MemberType.Toc)
                    {
                        if (current.Type.IsPageLevel())
                        {
                            current.Href = current.Name + Constants.YamlExtension;
                        }
                        else
                        {
                            current.Href = parent.Href;
                        }
                    }

                    return true;
                });

            return new ParseResult(ResultLevel.Success);
        }
Exemplo n.º 27
0
 public ParseResult Run(MetadataModel yaml, ResolverContext context)
 {
     // Moved to Metadata Visitor
     return new ParseResult(ResultLevel.Success);
 }
Exemplo n.º 28
0
 public void Run(MetadataModel yaml, ResolverContext context)
 {
     yaml.TocYamlViewModel = yaml.TocYamlViewModel.ShrinkToSimpleTocWithNamespaceNotEmpty();
 }
Exemplo n.º 29
0
 public ParseResult Run(MetadataModel yaml, ResolverContext context)
 {
     // Moved to Metadata Visitor
     return(new ParseResult(ResultLevel.Success));
 }