Example #1
0
        private IDocument GenerateFeed(FeedType feedType, Feed feed, ContextConfig path, IExecutionContext context)
        {
            // Get the output path
            FilePath outputPath = path?.Invoke<FilePath>(context);
            if (outputPath == null)
            {
                return null;
            }
            if (!outputPath.IsRelative)
            {
                throw new ArgumentException("The feed output path must be relative");
            }

            // Generate the feed and document
            MemoryStream stream = new MemoryStream();
            FeedSerializer.SerializeXml(feedType, feed, stream);
            stream.Position = 0;
            return context.GetDocument(stream, new MetadataItems
            {
                new MetadataItem(Keys.RelativeFilePath, outputPath),
                new MetadataItem(Keys.WritePath, outputPath)
            });
        }
Example #2
0
        public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
        {
            // Get the feed
            Feed feed = new Feed
            {
                ID = _feedId?.Invoke<Uri>(context),
                Title = _feedTitle?.Invoke<string>(context),
                Description = _feedDescription?.Invoke<string>(context),
                Author = _feedAuthor?.Invoke<string>(context),
                Published = _feedPublished?.Invoke<DateTime?>(context),
                Updated = _feedUpdated?.Invoke<DateTime?>(context),
                Link = _feedLink?.Invoke<Uri>(context),
                ImageLink = _feedImageLink?.Invoke<Uri>(context),
                Copyright = _feedCopyright?.Invoke<string>(context)
            };

            // Add items
            foreach (IDocument input in inputs.Take(_maximumItems))
            {
                feed.Items.Add(new FeedItem
                {
                    ID = _itemId?.Invoke<Uri>(input, context),
                    Title = _itemTitle?.Invoke<string>(input, context),
                    Description = _itemDescription?.Invoke<string>(input, context),
                    Author = _itemAuthor?.Invoke<string>(input, context),
                    Published = _itemPublished?.Invoke<DateTime?>(input, context),
                    Updated = _itemUpdated?.Invoke<DateTime?>(input, context),
                    Link = _itemLink?.Invoke<Uri>(input, context),
                    ImageLink = _itemImageLink?.Invoke<Uri>(input, context),
                    Content = _itemContent?.Invoke<string>(input, context),
                    ThreadLink = _itemThreadLink?.Invoke<Uri>(input, context),
                    ThreadCount = _itemThreadCount?.Invoke<int?>(input, context),
                    ThreadUpdated = _itemThreadUpdated?.Invoke<DateTime?>(input, context)
                });
            }

            // Generate the feeds
            return new[]
            {
                GenerateFeed(FeedType.Rss, feed, _rssPath, context),
                GenerateFeed(FeedType.Atom, feed, _atomPath, context),
                GenerateFeed(FeedType.Rdf, feed, _rdfPath, context)
            }.Where(x => x != null);
        }