public int Generate(IArticlePublisher saver)
        {
            var articleCount = 0;

            foreach (var package in _lib.Packages)
            {
                articleCount += ProcessModule(package, saver);
            }

            return(articleCount);
        }
Exemple #2
0
        public int Run()
        {
            var logger = LoggerFactory.Create(b => b.AddConsole())
                         .CreateLogger("AistDoc");

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory());

            Console.WriteLine($"Reading config: {ConfigPath} ...");
            try {
                builder.AddJsonFile(ConfigPath);
            }
            catch (FileNotFoundException ex) {
                throw ex;
            }


            try {
                var startTime     = DateTime.UtcNow;
                var configuration = builder.Build();

                var aistantSettings = configuration.GetSection("aistant").Get <AistantSettings>();

                IArticlePublisher publisher = null;
                if (_outputOp.HasValue())
                {
                    publisher = new FileArticlePublisher(_outputOp.Value(), logger);
                }
                else
                {
                    publisher = new AistantArticlePublisher(aistantSettings, logger);
                }

                var mode = configuration["source:mode"]?.ToString();

                IDocGenerator generator;
                if (mode == "typescript")
                {
                    generator = new TypeScriptDocGenerator(configuration);
                }
                else
                {
                    generator = new CSharpDocGenerator(configuration, logger, _outputOp.Value());
                }

                var articleCount = generator.Generate(publisher);

                logger.LogInformation("Done! " + $"{articleCount} documents added or updated");
                logger.LogInformation("Time Elapsed : " + (DateTime.UtcNow - startTime));
                Thread.Sleep(100);
            }
            catch (Exception ex) {
                logger.LogCritical(ex.Message);

                Thread.Sleep(100);

                return(-1);
            }

            return(0);
        }
        private int ProcessModule(ITypeScriptModule module, IArticlePublisher saver, string parentSectionUrl = null)
        {
            var articleCount   = 0;
            var sectionName    = module.BeautifulName;
            var sectionUrl     = sectionName.MakeUriFromString();
            var fullSectionUrl = (parentSectionUrl != null) ? parentSectionUrl.CombineWithUri(sectionUrl) : sectionUrl;

            var enums      = module.Enumerations.Where(e => e.IsExported).ToList();
            var classes    = module.Classes.Where(c => c.IsExported).ToList();
            var interfaces = module.Interfaces.Where(i => i.IsExported).ToList();
            var functions  = module.Functions.Where(f => f.IsExported).ToList();
            var variables  = module.Variables.Where(v => v.IsExported).ToList();
            var nspaces    = module.Namespaces.Where(n => n.IsExported).ToList();

            //support extention interfaces
            var extensionInterfaces = module.Namespaces.Where(n => _lib.Packages.Any(p => n.Name.Contains(p.Name)))
                                      .SelectMany(n => n.Interfaces)
                                      .ToList();

            extensionInterfaces = extensionInterfaces.Where(i => ContainsClassOrInterface(i.Name))
                                  .ToList();

            if (enums.Any() || classes.Any() || interfaces.Any() || functions.Any() || variables.Any() || extensionInterfaces.Any())
            {
                var parentSection = new ArticlePublishModel
                {
                    SectionUri     = parentSectionUrl,
                    ArticleTitle   = sectionName,
                    ArticleUri     = sectionUrl,
                    ArticleExcerpt = module.Comment?.ShortText ?? " ",
                    ArticleBody    = module.Comment?.ShortText ?? "",
                    IsSection      = true
                };

                //Create section for package/namespace
                if (saver.PublishArticle(parentSection))
                {
                    articleCount++;
                }

                foreach (var nspace in nspaces)
                {
                    articleCount += ProcessModule(nspace, saver, fullSectionUrl);
                }

                if (enums.Any())
                {
                    var section = new ArticlePublishModel
                    {
                        SectionTitle = sectionName,
                        SectionUri   = fullSectionUrl,
                        ArticleTitle = "Enumerations",
                        ArticleUri   = "enumerations",
                        IsSection    = true
                    };

                    //Create section for package/namespace
                    if (saver.PublishArticle(section))
                    {
                        articleCount++;
                    }

                    //Processing Enumerations
                    foreach (var @enum in enums)
                    {
                        var itemName    = @enum.BeautifulName;
                        var itemSummary = @enum.Comment?.ShortText;
                        var itemContent = BuildContent(@enum);

                        var articleSaveModel = new ArticlePublishModel
                        {
                            SectionTitle   = section.ArticleTitle,
                            SectionUri     = fullSectionUrl.CombineWithUri(section.ArticleUri),
                            ArticleTitle   = itemName,
                            ArticleUri     = itemName.MakeUriFromString(),
                            ArticleExcerpt = itemSummary,
                            ArticleBody    = itemContent
                        };

                        if (saver.PublishArticle(articleSaveModel))
                        {
                            articleCount++;
                        }
                    }
                }

                if (interfaces.Any())
                {
                    var section = new ArticlePublishModel
                    {
                        SectionTitle = sectionName,
                        SectionUri   = fullSectionUrl,
                        ArticleTitle = "Interfaces",
                        ArticleUri   = "interfaces",
                        IsSection    = true
                    };

                    //Create section for interfaces
                    if (saver.PublishArticle(section))
                    {
                        articleCount++;
                    }


                    //Processing Interfaces
                    foreach (var @interface in interfaces)
                    {
                        var itemName    = @interface.BeautifulName;
                        var itemSummary = GetSummary(@interface, extension: false, articleUrl: null);
                        var itemContent = BuildContent(@interface);

                        var articleSaveModel = new ArticlePublishModel
                        {
                            SectionTitle   = section.ArticleTitle,
                            SectionUri     = fullSectionUrl.CombineWithUri(section.ArticleUri),
                            ArticleTitle   = itemName,
                            ArticleUri     = itemName.MakeUriFromString(),
                            ArticleExcerpt = itemSummary,
                            ArticleBody    = itemContent
                        };

                        if (saver.PublishArticle(articleSaveModel))
                        {
                            articleCount++;
                        }
                    }
                }


                if (classes.Any())
                {
                    var section = new ArticlePublishModel
                    {
                        SectionTitle = sectionName,
                        SectionUri   = fullSectionUrl,
                        ArticleTitle = "Classes",
                        ArticleUri   = "classes",
                        IsSection    = true
                    };

                    //Create section for interfaces
                    if (saver.PublishArticle(section))
                    {
                        articleCount++;
                    }

                    //Processing Classes
                    foreach (var @class in classes)
                    {
                        var itemName    = @class.BeautifulName;
                        var itemSummary = GetSummary(@class);

                        var itemContent = BuildContent(@class);

                        var articleSaveModel = new ArticlePublishModel
                        {
                            SectionTitle   = section.ArticleTitle,
                            SectionUri     = fullSectionUrl.CombineWithUri(section.ArticleUri),
                            ArticleTitle   = itemName,
                            ArticleUri     = itemName.MakeUriFromString(),
                            ArticleExcerpt = itemSummary,
                            ArticleBody    = itemContent
                        };

                        if (saver.PublishArticle(articleSaveModel))
                        {
                            articleCount++;
                        }
                    }
                }

                if (extensionInterfaces.Any())
                {
                    var section = new ArticlePublishModel
                    {
                        SectionTitle = sectionName,
                        SectionUri   = fullSectionUrl,
                        ArticleTitle = "Extensions",
                        ArticleUri   = "extensions",
                        IsSection    = true
                    };

                    //Create section for extensions
                    if (saver.PublishArticle(section))
                    {
                        articleCount++;
                    }


                    //Processing extensions
                    foreach (var extensionInterface in extensionInterfaces)
                    {
                        var itemName   = extensionInterface.Name + " extensions";
                        var articleUrl = section.ArticleUri.CombineWithUri(itemName.MakeUriFromString());

                        var itemSummary = GetSummary(extensionInterface, extension: true, articleUrl: articleUrl);

                        var itemContent = BuildContent(extensionInterface, extension: true, articleUrl: articleUrl);

                        var articleSaveModel = new ArticlePublishModel
                        {
                            SectionTitle   = section.ArticleTitle,
                            SectionUri     = fullSectionUrl.CombineWithUri(section.ArticleUri),
                            ArticleTitle   = itemName,
                            ArticleUri     = itemName.MakeUriFromString(),
                            ArticleExcerpt = itemSummary,
                            ArticleBody    = itemContent
                        };

                        if (saver.PublishArticle(articleSaveModel))
                        {
                            articleCount++;
                        }
                    }
                }


                if (functions.Any())
                {
                    var itemSummary = GetSummary(module, module.Functions);

                    var articleSaveModel = new ArticlePublishModel
                    {
                        SectionTitle   = sectionName,
                        SectionUri     = fullSectionUrl,
                        ArticleTitle   = "Functions",
                        ArticleUri     = "functions",
                        ArticleBody    = BuildContent(functions),
                        ArticleExcerpt = itemSummary
                    };

                    if (saver.PublishArticle(articleSaveModel))
                    {
                        articleCount++;
                    }
                }

                if (variables.Any())
                {
                    var itemSummary = GetSummary(module, module.Variables);

                    var articleSaveModel = new ArticlePublishModel
                    {
                        SectionTitle   = sectionName,
                        SectionUri     = fullSectionUrl,
                        ArticleTitle   = "Variables",
                        ArticleUri     = "Variables",
                        ArticleBody    = BuildContent(variables),
                        ArticleExcerpt = itemSummary
                    };

                    if (saver.PublishArticle(articleSaveModel))
                    {
                        articleCount++;
                    }
                }
            }

            return(articleCount);
        }
Exemple #4
0
        public int Generate(IArticlePublisher publisher)
        {
            _logger?.LogInformation($"Processing assemblies in {_srcPath}...");
            LoadLibraryTypes();

            var dest         = Directory.GetCurrentDirectory();
            int articleCount = 0;

            var packageGroups = _types.GroupBy(x => x.Package).OrderBy(x => x.Key?.Name);

            foreach (var packageGroup in packageGroups)
            {
                var packageSectionName = packageGroup.Key?.Name;
                var packageSection     = packageSectionName != null
                    ? new ArticlePublishModel {
                    ArticleTitle   = packageSectionName,
                    ArticleUri     = packageSectionName.MakeUriFromString(),
                    ArticleBody    = packageGroup.Key.Description,
                    ArticleExcerpt = packageGroup.Key.Description,
                    IsSection      = true
                }
                    : null;

                if (packageSection != null && publisher.PublishArticle(packageSection))
                {
                    articleCount++;
                }
                ;

                var namespaceGroups = packageGroup.GroupBy(x => x.Namespace).OrderBy(x => x.Key);

                foreach (var namespaceGroup in namespaceGroups)
                {
                    var namespaceSectionName = namespaceGroup.Key + " namespace";
                    var namespaceSection     = new ArticlePublishModel {
                        SectionUri   = packageSection?.ArticleUri,
                        ArticleTitle = namespaceSectionName,
                        ArticleUri   = namespaceSectionName.MakeUriFromString(),
                        IsSection    = true
                    };

                    if (publisher.PublishArticle(namespaceSection))
                    {
                        articleCount++;
                    }
                    ;


                    var namespaceTypes = namespaceGroup.OrderBy(x => x.Name).Distinct(new MarkdownableTypeEqualityComparer());
                    foreach (var item in namespaceTypes)
                    {
                        SetLinks(item, _types, _aistantSettings.Kb, _aistantSettings.Section.Uri, _aistantSettings.Team);

                        string itemName = item.GetNameWithKind();

                        string itemString  = item.ToString();
                        string itemSummary = item.GetSummary();

                        bool ok = publisher.PublishArticle(new ArticlePublishModel {
                            SectionUri     = packageSection?.ArticleUri.CombineWithUri(namespaceSection.ArticleUri) ?? namespaceSection.ArticleUri,
                            ArticleTitle   = itemName,
                            ArticleUri     = itemName.MakeUriFromString(),
                            ArticleBody    = itemString,
                            ArticleExcerpt = itemSummary
                        });

                        if (ok)
                        {
                            articleCount++;
                        }
                    }
                }
            }

            return(articleCount);
        }