Beispiel #1
0
        public bool SaveArticle(ArticleSaveModel model)
        {
            try {
                var articleDirectory = Path.Combine(_outputFolder, MakeFileNameFromTitle(model.SectionTitle));
                Directory.CreateDirectory(articleDirectory);

                var articleTitleAndExcerpt = "## " + model.ArticleTitle + "\n";
                articleTitleAndExcerpt += model.ArticleExcerpt + "\n";

                //section index file
                File.AppendAllText(Path.Combine(articleDirectory, ".md"), articleTitleAndExcerpt);

                //article file
                var filepath = Path.Combine(articleDirectory, MakeFileNameFromTitle(model.ArticleBody)) + ".md";
                File.WriteAllText(filepath, model.ArticleBody);

                _logger.LogInformation("Article was SAVED. Path: " + filepath);
            }
            catch (Exception ex) {
                _logger.LogError("Article '" + model.ArticleTitle + "' WASN'T SAVED");
                return(false);
            }

            return(true);
        }
Beispiel #2
0
 public bool SaveArticle(ArticleSaveModel model)
 {
     return(_service.UploadArticleAsync(model.SectionUri, model.SectionTitle, model.ArticleUri, model.ArticleTitle, model.ArticleBody, model.ArticleExcerpt, model.IsSection).Result);
 }
        private int ProcessModule(ITypeScriptModule module, IArticleSaver 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();

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

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

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

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

                    //Create section for package/namespace
                    if (saver.SaveArticle(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 ArticleSaveModel
                        {
                            SectionTitle   = section.ArticleTitle,
                            SectionUri     = fullSectionUrl.CombineWithUri(section.ArticleUri),
                            ArticleTitle   = itemName,
                            ArticleUri     = itemName.MakeUriFromString(),
                            ArticleExcerpt = itemSummary,
                            ArticleBody    = itemContent
                        };

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

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

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


                    //Processing Interfaces
                    foreach (var @interface in interfaces)
                    {
                        var itemName    = @interface.BeautifulName;
                        var itemSummary = @interface.Comment?.ShortText;
                        var itemContent = BuildContent(@interface);

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

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


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

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

                    //Processing Classes
                    foreach (var @class in classes)
                    {
                        var itemName    = @class.BeautifulName;
                        var itemSummary = @class.Comment?.ShortText;
                        var itemContent = BuildContent(@class);

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

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


                if (functions.Any())
                {
                    var articleSaveModel = new ArticleSaveModel
                    {
                        SectionTitle = sectionName,
                        SectionUri   = fullSectionUrl,
                        ArticleTitle = "Functions",
                        ArticleUri   = "functions",
                        ArticleBody  = BuildContent(functions)
                    };

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

                if (variables.Any())
                {
                    var articleSaveModel = new ArticleSaveModel
                    {
                        SectionTitle = sectionName,
                        SectionUri   = fullSectionUrl,
                        ArticleTitle = "Variables",
                        ArticleUri   = "Variables",
                        ArticleBody  = BuildContent(variables)
                    };

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

            return(articleCount);
        }