コード例 #1
0
ファイル: ArticlesController.cs プロジェクト: ravendb/docs
        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 });
        }
コード例 #2
0
        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 }));
        }
コード例 #3
0
        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(HttpContext, DocumentStore, ArticleType.Articles)
            }, new NoOpGitFileInformationProvider());

            DocumentSession.Delete(AttachmentsController.AttachmentsForArticlesPrefix);

            var query = DocumentSession
                        .Advanced
                        .DocumentQuery <ArticlePage>()
                        .GetIndexQuery();

            DocumentStore
            .Operations
            .Send(new DeleteByQueryOperation(query))
            .WaitForCompletion();

            DocumentSession.SaveChanges();

            var toDispose   = new List <IDisposable>();
            var attachments = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            try
            {
                DocumentSession.Store(new Attachment(), AttachmentsController.AttachmentsForArticlesPrefix);

                foreach (var page in parser.Parse())
                {
                    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);

                        if (attachments.Add(image.ImageKey))
                        {
                            DocumentSession.Advanced.Attachments.Store(AttachmentsController.AttachmentsForArticlesPrefix, image.ImageKey, file, AttachmentsController.FileExtensionToContentTypeMapping[fileInfo.Extension]);
                        }
                    }
                }

                foreach (var toc in parser.GenerateTableOfContents())
                {
                    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 }));
        }