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 }));
}