示例#1
0
        public HomePipeline()
        {
            Dependencies.AddRange(nameof(BookPipeline), nameof(RatingPipeline), nameof(AuthorPipeline), nameof(ContactPipeline));
            InputModules = new ModuleList
            {
                new ReadFiles("index.cshtml")
            };

            ProcessModules = new ModuleList {
                new RenderRazor().WithModel(Config.FromDocument((doc, context) =>
                {
                    var allBooks   = XperienceDocumentConverter.ToTreeNodes <Book>(context.Outputs.FromPipeline(nameof(BookPipeline)));
                    var allAuthors = XperienceDocumentConverter.ToTreeNodes <Author>(context.Outputs.FromPipeline(nameof(AuthorPipeline)));
                    var allRatings = XperienceDocumentConverter.ToCustomTableItems <RatingsItem>(context.Outputs.FromPipeline(nameof(RatingPipeline)), RatingsItem.CLASS_NAME);

                    var contactInfo      = XperienceDocumentConverter.ToTreeNodes <ContactUs>(context.Outputs.FromPipeline(nameof(ContactPipeline))).FirstOrDefault();
                    var booksWithReviews = allBooks.Select(b => new BookWithReviews(b, allRatings));
                    var authorsWithBooks = allAuthors.Select(a => new AuthorWithBooks(a, booksWithReviews));

                    return(new HomeViewModel()
                    {
                        Authors = authorsWithBooks,
                        Books = booksWithReviews,
                        ContactInfo = contactInfo
                    });
                })),
                new SetDestination(Config.FromDocument((doc, ctx) => {
                    return(new NormalizedPath("index.html"));
                }))
            };

            OutputModules = new ModuleList {
                new WriteFiles()
            };
        }
#pragma warning disable 1998
        protected override async Task <IEnumerable <IDocument> > ExecuteInputAsync(IDocument input, IExecutionContext context)
        {
            var node = XperienceDocumentConverter.ToTreeNode <TreeNode>(input);

            foreach (var attachment in node.AllAttachments)
            {
                DownloadAttachment(attachment, context);
            }

            return(input.Yield());
        }
示例#3
0
        protected override async Task <IEnumerable <IDocument> > ExecuteContextAsync(IExecutionContext context)
        {
            if (Query == null)
            {
                throw new NullReferenceException($"{nameof(XperienceContentModule<TPageType>)} missing query, pass a DocumentQuery in the constructor to retrieve pages from your Xperience project.");
            }

            var items = await Task.Run(() => Query.TypedResult);

            return(items.Select(i => XperienceDocumentConverter.FromBaseInfo(context, i)));
        }
 public BookPipeline()
 {
     Dependencies.Add(nameof(RatingPipeline));
     Query           = BookProvider.GetBooks();
     ReadPath        = "content/book.cshtml";
     DestinationPath = Config.FromDocument((doc, ctx) =>
     {
         var book = XperienceDocumentConverter.ToTreeNode <Book>(doc);
         return(new NormalizedPath(StatiqHelper.GetBookUrl(book)));
     });
     WithModel = Config.FromDocument((doc, context) => {
         var book       = XperienceDocumentConverter.ToTreeNode <Book>(doc);
         var allRatings = context.Outputs.FromPipeline(nameof(RatingPipeline)).ParallelSelectAsync(doc =>
                                                                                                   Task.Run(() => XperienceDocumentConverter.ToCustomTableItem <RatingsItem>(doc, RatingsItem.CLASS_NAME)));
         return(new BookWithReviews(book, allRatings.Result));
     });
 }