public virtual ActionResult Generate(string key) { var parser = new ArticleParser( new ParserOptions { PathToDocumentationDirectory = GetArticleDirectory(), RootUrl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~")), ImagesUrl = DocsController.GetImagesUrl(DocumentStore) }, new NoOpGitFileInformationProvider()); DocumentStore .DatabaseCommands .DeleteByIndex("Raven/DocumentsByEntityName", new IndexQuery { Query = "Tag:ArticlePages" }) .WaitForCompletion(); foreach (var page in parser.Parse()) { DocumentSession.Store(page); Parallel.ForEach( page.Images, image => { if (System.IO.File.Exists(image.ImagePath) == false) return; using (var file = System.IO.File.OpenRead(image.ImagePath)) { DocumentStore.DatabaseCommands.PutAttachment(image.ImageKey, null, file, new RavenJObject()); } }); } foreach (var toc in parser.GenerateTableOfContents()) { DocumentSession.Store(toc); } DocumentSession.SaveChanges(); while (true) { var stats = DocumentStore.DatabaseCommands.GetStatistics(); if (stats.StaleIndexes.Any() == false) break; Thread.Sleep(500); } if (string.IsNullOrEmpty(key)) return RedirectToAction(MVC.Articles.ActionNames.Articles); return RedirectToAction(MVC.Articles.ActionNames.Articles, MVC.Articles.Name, new { key = key }); }
private void AppendWord(FlowDocument document, WordInfo word) { ArticleParser parser = new ArticleParser(); WordArticle article = parser.Parse(word.Word.Name, word.Word.Description); Paragraph paragraph = FlowDocumentStyles.CreateParagraph(); document.Blocks.Add(paragraph); IEnumerable <WordFormGroup> formGroups = article.FormGroups.Where(fg => fg.TranslationGroups.SelectMany(tg => tg.Translations).Contains(Translation)); foreach (WordFormGroup formGroup in formGroups) { bool firstForm = true; foreach (string form in formGroup.Forms) { Hyperlink link = new Hyperlink(); link.Command = Commands.NavigateTo; link.CommandParameter = NavigationTarget.ToWord(word.Word.Name); paragraph.Inlines.Add(link); Run run = new Run(form); link.Inlines.Add(run); if (firstForm) { FlowDocumentStyles.FormatWord(run); firstForm = false; } else { FlowDocumentStyles.FormatWordForm(run); } paragraph.Inlines.Add(new LineBreak()); } foreach (WordTranslationGroup translationGroup in formGroup.TranslationGroups.Where(tg => tg.Translations.Contains(Translation))) { foreach (string translation in translationGroup.Translations) { Run run = new Run("\u2022 " + translation); paragraph.Inlines.Add(run); FlowDocumentStyles.FormatTranslation(run); paragraph.Inlines.Add(new LineBreak()); } foreach (string example in translationGroup.Examples) { Run run = new Run("Example: " + example); paragraph.Inlines.Add(run); FlowDocumentStyles.FormatExample(run); paragraph.Inlines.Add(new LineBreak()); } } } }
public void Test() { ArticleParser parser = new ArticleParser(); WordArticle article = parser.Parse("a", "b"); Assert.That(article.FormGroups.Count, Is.EqualTo(1)); Assert.That(article.FormGroups[0].Forms, Is.EquivalentTo(new string[] { "a" })); Assert.That(article.FormGroups[0].TranslationGroups.Count, Is.EqualTo(1)); Assert.That(article.FormGroups[0].TranslationGroups[0].Translations, Is.EquivalentTo(new string[] { "b" })); Assert.That(article.Format(), Is.EqualTo("#a\nb\n")); }
private List <ArticlePage> GetParsedPages(Options options) { var parser = new ArticleParser( new ParserOptions { PathToDocumentationDirectory = options.ArticleDirectory, RootUrl = DummyRootUrl, ImageUrlGenerator = ImageUrlGenerator }, new NoOpGitFileInformationProvider()); var parserOutput = parser.Parse(); return(parserOutput.Pages.ToList()); }
public virtual ActionResult Generate(string key) { var parser = new ArticleParser( new ParserOptions { PathToDocumentationDirectory = GetArticleDirectory(), RootUrl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~")), ImagesUrl = DocsController.GetImagesUrl(DocumentStore) }, new NoOpGitFileInformationProvider()); DocumentStore .DatabaseCommands .DeleteByIndex("Raven/DocumentsByEntityName", new IndexQuery { Query = "Tag:ArticlePages" }) .WaitForCompletion(); foreach (var page in parser.Parse()) { DocumentSession.Store(page); Parallel.ForEach( page.Images, image => { if (System.IO.File.Exists(image.ImagePath) == false) { return; } using (var file = System.IO.File.OpenRead(image.ImagePath)) { DocumentStore.DatabaseCommands.PutAttachment(image.ImageKey, null, file, new RavenJObject()); } }); } foreach (var toc in parser.GenerateTableOfContents()) { DocumentSession.Store(toc); } DocumentSession.SaveChanges(); while (true) { var stats = DocumentStore.DatabaseCommands.GetStatistics(); if (stats.StaleIndexes.Any() == false) { break; } Thread.Sleep(500); } if (string.IsNullOrEmpty(key)) { return(RedirectToAction(MVC.Articles.ActionNames.Articles)); } return(RedirectToAction(MVC.Articles.ActionNames.Articles, MVC.Articles.Name, new { key = key })); }
public virtual ActionResult Generate(string key) { var parser = new ArticleParser( new ParserOptions { PathToDocumentationDirectory = GetArticleDirectory(), RootUrl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~")), ImageUrlGenerator = DocsController.GetImageUrlGenerator(HttpContext, DocumentStore, ArticleType.Articles) }, new NoOpGitFileInformationProvider()); var query = DocumentSession .Advanced .DocumentQuery <ArticlePage>() .GetIndexQuery(); DocumentStore .Operations .Send(new DeleteByQueryOperation(query)) .WaitForCompletion(); DocumentSession.SaveChanges(); var toDispose = new List <IDisposable>(); var parserOutput = parser.Parse(); try { foreach (var page in parserOutput.Pages) { DocumentSession.Store(page); foreach (var image in page.Images) { var fileInfo = new FileInfo(image.ImagePath); if (fileInfo.Exists == false) { continue; } var file = fileInfo.OpenRead(); toDispose.Add(file); var documentId = page.Id; var fileName = Path.GetFileName(image.ImagePath); DocumentSession.Advanced.Attachments.Store(documentId, fileName, file, AttachmentsController.FileExtensionToContentTypeMapping[fileInfo.Extension]); } } foreach (var toc in parserOutput.TableOfContents) { DocumentSession.Store(toc); } DocumentSession.SaveChanges(); } finally { foreach (var disposable in toDispose) { disposable?.Dispose(); } } while (true) { var stats = DocumentStore.Maintenance.Send(new GetStatisticsOperation()); if (stats.StaleIndexes.Any() == false) { break; } Thread.Sleep(500); } if (string.IsNullOrEmpty(key)) { return(RedirectToAction(MVC.Articles.ActionNames.Articles)); } return(RedirectToAction(MVC.Articles.ActionNames.Articles, MVC.Articles.Name, new { key = key })); }