Exemplo n.º 1
0
        public void Execute(FeedContext context)
        {
            var termParthId = context.ValueProvider.GetValue("term");
            if (termParthId == null) return;

            var limitValue = context.ValueProvider.GetValue("limit");
            var limit = 20;
            if (limitValue != null) limit = (int)limitValue.ConvertTo(typeof(int));

            var containerId = (int)termParthId.ConvertTo(typeof(int));
            var container = _contentManager.Get<TermPart>(containerId);

            if (container == null)
            {
                return;
            }

            var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container));
            if (context.Format == "rss")
            {
                var link = new XElement("link");
                context.Response.Element.SetElementValue("title", inspector.Title);
                context.Response.Element.Add(link);
                context.Response.Element.SetElementValue("description", inspector.Description);

                context.Response.Contextualize(
                    requestContext =>
                        {
                            var urlHelper = new UrlHelper(requestContext);
                            var uriBuilder =
                                new UriBuilder(urlHelper.RequestContext.HttpContext.Request.ToRootUrlString())
                                    { Path = urlHelper.RouteUrl(inspector.Link) };
                            link.Add(uriBuilder.Uri.OriginalString);
                        });
            }
            else
            {
                context.Builder.AddProperty(context, null, "title", inspector.Title);
                context.Builder.AddProperty(context, null, "description", inspector.Description);
                context.Response.Contextualize(
                    requestContext =>
                        {
                            var urlHelper = new UrlHelper(requestContext);
                            context.Builder.AddProperty(context, null, "link", urlHelper.RouteUrl(inspector.Link));
                        });
            }

            var items = _taxonomyService.GetContentItems(container, 0, limit);

            foreach (var item in items)
            {
                // call item.ContentItem to force a cast to ContentItem, and 
                // thus use CorePartsFeedItemBuilder
                context.Builder.AddItem(context, item.ContentItem);
            }
        }
Exemplo n.º 2
0
        public void Populate(FeedContext context) {
            foreach (var feedItem in context.Response.Items.OfType<FeedItem<ContentItem>>()) {

                var inspector = new ItemInspector(
                    feedItem.Item,
                    _contentManager.GetItemMetadata(feedItem.Item), 
                    _htmlFilters);


                // TODO: author


                // add to known formats
                if (context.Format == "rss") {
                    var link = new XElement("link");
                    var guid = new XElement("guid", new XAttribute("isPermaLink", "true"));

                    context.Response.Contextualize(requestContext => {
                                                        var urlHelper = new UrlHelper(requestContext, _routes);
                                                        var uriBuilder = new UriBuilder(urlHelper.RequestContext.HttpContext.Request.ToRootUrlString()) { Path = urlHelper.RouteUrl(inspector.Link) };
                                                        link.Add(uriBuilder.Uri.OriginalString);
                                                        guid.Add(uriBuilder.Uri.OriginalString);
                                                   });

                    feedItem.Element.SetElementValue("title", inspector.Title);
                    feedItem.Element.Add(link);
                    feedItem.Element.SetElementValue("description", inspector.Description);

                    if ( inspector.PublishedUtc != null ) {
                        // RFC833 
                        // The "R" or "r" standard format specifier represents a custom date and time format string that is defined by 
                        // the DateTimeFormatInfo.RFC1123Pattern property. The pattern reflects a defined standard, and the property  
                        // is read-only. Therefore, it is always the same, regardless of the culture used or the format provider supplied.  
                        // The custom format string is "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'". When this standard format specifier is used,  
                        // the formatting or parsing operation always uses the invariant culture. 
                        feedItem.Element.SetElementValue("pubDate", inspector.PublishedUtc.Value.ToString("r"));
                    }

                    feedItem.Element.Add(guid);
                }
                else {
                    var feedItem1 = feedItem;
                    context.Response.Contextualize(requestContext => {
                                                       var urlHelper = new UrlHelper(requestContext, _routes);
                                                       context.Builder.AddProperty(context, feedItem1, "link", urlHelper.RouteUrl(inspector.Link));
                                                   });
                    context.Builder.AddProperty(context, feedItem, "title", inspector.Title);
                    context.Builder.AddProperty(context, feedItem, "description", inspector.Description);

                    if (inspector.PublishedUtc != null)
                        context.Builder.AddProperty(context, feedItem, "published-date", Convert.ToString(inspector.PublishedUtc)); // format? cvt to generic T?
                }
            }
        }
Exemplo n.º 3
0
        public void Execute(FeedContext context)
        {
            var containerIdValue = context.ValueProvider.GetValue("containerid");
            if (containerIdValue == null)
                return;

            var limitValue = context.ValueProvider.GetValue("limit");
            var limit = 20;
            if (limitValue != null) {
                Int32.TryParse(Convert.ToString(limitValue), out limit);
            }

            limit = Math.Min(limit, 100);

            var containerId = (int)containerIdValue.ConvertTo(typeof(int));
            var container = _contentManager.Get(containerId);

            if (container == null) {
                return;
            }

            var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container), _htmlFilters);
            if (context.Format == "rss") {
                var link = new XElement("link");
                context.Response.Element.SetElementValue("title", inspector.Title);
                context.Response.Element.Add(link);
                context.Response.Element.SetElementValue("description", inspector.Description);

                context.Response.Contextualize(requestContext => {
                    var urlHelper = new UrlHelper(requestContext);
                    var uriBuilder = new UriBuilder(urlHelper.MakeAbsolute("/")) { Path = urlHelper.RouteUrl(inspector.Link) };
                    link.Add(uriBuilder.Uri.OriginalString);
                });
            }
            else {
                context.Builder.AddProperty(context, null, "title", inspector.Title);
                context.Builder.AddProperty(context, null, "description", inspector.Description);
                context.Response.Contextualize(requestContext => {
                    var urlHelper = new UrlHelper(requestContext);
                    context.Builder.AddProperty(context, null, "link",urlHelper.MakeAbsolute(urlHelper.RouteUrl(inspector.Link)));
                });
            }

            var items = _contentManager.Query()
                .Where<CommonPartRecord>(x => x.Container == container.Record)
                .OrderByDescending(x => x.CreatedUtc)
                .Slice(0, limit);

            foreach (var item in items) {
                context.Builder.AddItem(context, item);
            }
        }
        public void Execute(FeedContext context)
        {
            var calendarId = context.ValueProvider.GetValue("calendar");
            if (calendarId == null)
                return;

            var containerId = (int)calendarId.ConvertTo(typeof(int));
            var container = _contentManager.Get<CalendarPart>(containerId);

            if (container == null)
            {
                return;
            }

            var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container));
            if (context.Format == "rss")
            {
                var link = new XElement("link");
                context.Response.Element.SetElementValue("title", inspector.Title);
                context.Response.Element.Add(link);
                context.Response.Element.SetElementValue("description", inspector.Description);

                context.Response.Contextualize(requestContext =>
                {
                    var urlHelper = new UrlHelper(requestContext);
                    var uriBuilder = new UriBuilder(urlHelper.MakeAbsolute("/"))
                    {
                        Path = urlHelper.RouteUrl(inspector.Link) ?? "/"
                    };
                    link.Add(uriBuilder.Uri.OriginalString);
                });
            }
            else
            {
                context.Builder.AddProperty(context, null, "title", inspector.Title);
                context.Builder.AddProperty(context, null, "description", inspector.Description);
                context.Response.Contextualize(requestContext =>
                {
                    var urlHelper = new UrlHelper(requestContext);
                    context.Builder.AddProperty(context, null, "link", urlHelper.RouteUrl(inspector.Link));
                });
            }

            var items = _calendarService.GetEvents(container.As<IdentityPart>().Identifier);

            foreach (var item in items)
            {
                // call item.ContentItem to force a cast to ContentItem, and 
                // thus use CorePartsFeedItemBuilder
                context.Builder.AddItem(context, item.ContentItem);
            }
        }
Exemplo n.º 5
0
        public void Execute(FeedContext context) {
            var projectionId = context.ValueProvider.GetValue("projection");
            if (projectionId == null)
                return;

            var limitValue = context.ValueProvider.GetValue("limit");
            var limit = 20;
            if (limitValue != null) {
                Int32.TryParse(Convert.ToString(limitValue), out limit);
            }

            var containerId = (int)projectionId.ConvertTo(typeof(int));
            var container = _contentManager.Get<ProjectionPart>(containerId);

            if (container == null) {
                return;
            }

            var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container), _htmlFilters);
            if (context.Format == "rss") {
                var link = new XElement("link");
                context.Response.Element.SetElementValue("title", inspector.Title);
                context.Response.Element.Add(link);
                context.Response.Element.SetElementValue("description", inspector.Description);

                context.Response.Contextualize(requestContext => {
                    var urlHelper = new UrlHelper(requestContext);
                    var uriBuilder = new UriBuilder(urlHelper.RequestContext.HttpContext.Request.ToRootUrlString()) { Path = urlHelper.RouteUrl(inspector.Link) };
                    link.Add(uriBuilder.Uri.OriginalString);
                });
            }
            else {
                context.Builder.AddProperty(context, null, "title", inspector.Title);
                context.Builder.AddProperty(context, null, "description", inspector.Description);
                context.Response.Contextualize(requestContext => {
                    var urlHelper = new UrlHelper(requestContext);
                    context.Builder.AddProperty(context, null, "link", urlHelper.RouteUrl(inspector.Link));
                });
            }

            var items = _projectionManager.GetContentItems(container.Record.QueryPartRecord.Id, 0, limit).ToList();

            foreach (var item in items) {
                context.Builder.AddItem(context, item);
            }
        }
Exemplo n.º 6
0
        public void Execute(FeedContext context) {
            var containerIdValue = context.ValueProvider.GetValue("containerid");
            if (containerIdValue == null)
                return;

            var limitValue = context.ValueProvider.GetValue("limit");
            var limit = 20;
            if (limitValue != null)
                limit = (int)limitValue.ConvertTo(typeof(int));

            var containerId = (int)containerIdValue.ConvertTo(typeof(int));
            var container = _contentManager.Get(containerId);

            var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container));
            if (context.Format == "rss") {
                var link = new XElement("link");
                context.Response.Element.SetElementValue("title", inspector.Title);
                context.Response.Element.Add(link);
                context.Response.Element.SetElementValue("description", inspector.Description);

                context.Response.Contextualize(requestContext => {
                    var urlHelper = new UrlHelper(requestContext);
                    link.Add(urlHelper.RouteUrl(inspector.Link));
                });
            }
            else {
                context.Builder.AddProperty(context, null, "title", inspector.Title);
                context.Builder.AddProperty(context, null, "description", inspector.Description);
                context.Response.Contextualize(requestContext => {
                    var urlHelper = new UrlHelper(requestContext);
                    context.Builder.AddProperty(context, null, "link", urlHelper.RouteUrl(inspector.Link));
                });
            }

            var items = _contentManager.Query()
                .Where<CommonRecord>(x => x.Container == container.Record)
                .OrderByDescending(x => x.PublishedUtc)
                .Slice(0, limit);

            foreach (var item in items) {
                context.Builder.AddItem(context, item);
            }
        }
        public void Populate(FeedContext context) {
            foreach (var feedItem in context.Response.Items.OfType<FeedItem<ContentItem>>()) {

                var inspector = new ItemInspector(
                    feedItem.Item,
                    _contentManager.GetItemMetadata(feedItem.Item));


                // TODO: author


                // add to known formats
                if (context.Format == "rss") {
                    var link = new XElement("link");
                    var guid = new XElement("guid", new XAttribute("isPermaLink", "true"));

                    context.Response.Contextualize(requestContext => {
                                                       var urlHelper = new UrlHelper(requestContext, _routes);
                                                       link.Add(urlHelper.RouteUrl(inspector.Link));
                                                       guid.Add(urlHelper.RouteUrl(inspector.Link));
                                                   });

                    feedItem.Element.SetElementValue("title", inspector.Title);
                    feedItem.Element.Add(link);
                    feedItem.Element.SetElementValue("description", inspector.Description);
                    if (inspector.PublishedUtc != null)
                        feedItem.Element.SetElementValue("pubDate", inspector.PublishedUtc);//TODO: format
                    feedItem.Element.Add(guid);
                }
                else {
                    var feedItem1 = feedItem;
                    context.Response.Contextualize(requestContext => {
                                                       var urlHelper = new UrlHelper(requestContext, _routes);
                                                       context.Builder.AddProperty(context, feedItem1, "link", urlHelper.RouteUrl(inspector.Link));
                                                   });
                    context.Builder.AddProperty(context, feedItem, "title", inspector.Title);
                    context.Builder.AddProperty(context, feedItem, "description", inspector.Description);

                    if (inspector.PublishedUtc != null)
                        context.Builder.AddProperty(context, feedItem, "published-date", Convert.ToString(inspector.PublishedUtc)); // format? cvt to generic T?
                }
            }
        }
        public void Populate(FeedContext context) {
            foreach (var feedItem in context.Response.Items.OfType<FeedItem<CommentPart>>()) {
                var comment = feedItem.Item;
                var commentedOn = _contentManager.Get(feedItem.Item.Record.CommentedOn);
                var commentedOnInspector = new ItemInspector(
                    commentedOn,
                    _contentManager.GetItemMetadata(commentedOn)
                );

                var title = T("Comment on {0} by {1}", commentedOnInspector.Title, comment.Record.Author);

                
                // add to known formats
                if (context.Format == "rss") {
                    var link = new XElement("link");
                    var guid = new XElement("guid", new XAttribute("isPermaLink", "false"));
                    context.Response.Contextualize(requestContext => {
                        var urlHelper = new UrlHelper(requestContext);
                        link.Add(urlHelper.RouteUrl(commentedOnInspector.Link) + "#comment-" + comment.Record.Id);
                        guid.Add("urn:comment:" + comment.Record.Id);
                    });

                    feedItem.Element.SetElementValue("title", title);
                    feedItem.Element.Add(link);
                    feedItem.Element.SetElementValue("description", comment.Record.CommentText);
                    feedItem.Element.SetElementValue("pubDate", comment.Record.CommentDateUtc);//TODO: format
                    feedItem.Element.Add(guid);
                }
                else {
                    var feedItem1 = feedItem;
                    context.Response.Contextualize(requestContext => {
                        var urlHelper = new UrlHelper(requestContext);
                        context.Builder.AddProperty(context, feedItem1, "link", urlHelper.RouteUrl(commentedOnInspector.Link));
                    });
                    context.Builder.AddProperty(context, feedItem, "title", title.ToString());
                    context.Builder.AddProperty(context, feedItem, "description", comment.Record.CommentText);

                    context.Builder.AddProperty(context, feedItem, "published-date", Convert.ToString(comment.Record.CommentDateUtc)); // format? cvt to generic T?
                }
            }
        }
        public void Populate(FeedContext context)
        {
            foreach (var feedItem in context.Response.Items.OfType <FeedItem <ContentItem> >())
            {
                var inspector = new ItemInspector(
                    feedItem.Item,
                    _contentManager.GetItemMetadata(feedItem.Item),
                    _htmlFilters);

                // author is intentionally left empty as it could result in unwanted spam

                // add to known formats
                if (context.Format == "rss")
                {
                    var link = new XElement("link");
                    var guid = new XElement("guid", new XAttribute("isPermaLink", "true"));

                    context.Response.Contextualize(requestContext => {
                        var urlHelper  = new UrlHelper(requestContext, _routes);
                        var uriBuilder = new UriBuilder(urlHelper.MakeAbsolute("/"))
                        {
                            Path = urlHelper.RouteUrl(inspector.Link)
                        };
                        link.Add(uriBuilder.Uri.OriginalString);
                        guid.Add(uriBuilder.Uri.OriginalString);
                    });

                    feedItem.Element.SetElementValue("title", inspector.Title);
                    feedItem.Element.Add(link);
                    feedItem.Element.SetElementValue("description", inspector.Description);

                    if (inspector.PublishedUtc != null)
                    {
                        // RFC833
                        // The "R" or "r" standard format specifier represents a custom date and time format string that is defined by
                        // the DateTimeFormatInfo.RFC1123Pattern property. The pattern reflects a defined standard, and the property
                        // is read-only. Therefore, it is always the same, regardless of the culture used or the format provider supplied.
                        // The custom format string is "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'". When this standard format specifier is used,
                        // the formatting or parsing operation always uses the invariant culture.
                        feedItem.Element.SetElementValue("pubDate", inspector.PublishedUtc.Value.ToString("r"));
                    }

                    feedItem.Element.Add(guid);
                }
                else
                {
                    var feedItem1 = feedItem;
                    context.Response.Contextualize(requestContext => {
                        var urlHelper = new UrlHelper(requestContext, _routes);
                        context.Builder.AddProperty(context, feedItem1, "link", urlHelper.RouteUrl(inspector.Link));
                    });
                    context.Builder.AddProperty(context, feedItem, "title", inspector.Title);
                    context.Builder.AddProperty(context, feedItem, "description", inspector.Description);

                    if (inspector.PublishedUtc != null)
                    {
                        context.Builder.AddProperty(context, feedItem, "published-date", Convert.ToString(inspector.PublishedUtc)); // format? cvt to generic T?
                    }
                }
            }
        }
Exemplo n.º 10
0
        public string Execute(int queryId)
        {
            var projection = this.Services.ContentManager.Query<ProjectionPart>()
                .Where<ProjectionPartRecord>(e => e.QueryPartRecord.Id == queryId)
                .List()
                .FirstOrDefault();

            var layout = projection.Record.LayoutRecord;

            LayoutDescriptor layoutDescriptor = layout == null ? null :
                _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == layout.Category && x.Type == layout.Type);

            var tokens = new Dictionary<string, object> { { "Content", projection.ContentItem } };
            var allFielDescriptors = _projectionManager.DescribeProperties().ToList();
            var fieldDescriptors = layout.Properties.OrderBy(p => p.Position).Select(p => allFielDescriptors.SelectMany(x => x.Descriptors).Select(d => new { Descriptor = d, Property = p }).FirstOrDefault(x => x.Descriptor.Category == p.Category && x.Descriptor.Type == p.Type)).ToList();
            var tokenizedDescriptors = fieldDescriptors.Select(fd => new { fd.Descriptor, fd.Property, State = FormParametersHelper.ToDynamic(tokenizer.Replace(fd.Property.State, tokens)) }).ToList();

            var limit = projection.Record.MaxItems;
            var items = _projectionManager.GetContentItems(queryId, 0, limit).ToList();

            //var container = _contentManager.Get<Orchard.Projections.Models.QueryPart>(projection.Record.QueryPartRecord.Id);

            var inspector = new ItemInspector(projection, Services.ContentManager.GetItemMetadata(projection), _htmlFilters);

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            var display = displayHelperFactory.CreateHelper(new ViewContext { HttpContext = workContextAccessor.GetContext().HttpContext }, new ViewDataContainer());

            using (JsonWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.Formatting = Formatting.Indented;

                jsonWriter.WriteStartObject();

                jsonWriter.WritePropertyName("title");
                jsonWriter.WriteValue(inspector.Title);
                jsonWriter.WritePropertyName("description");
                jsonWriter.WriteValue(inspector.Description);

                jsonWriter.WritePropertyName("Items");
                jsonWriter.WriteStartArray();
                foreach (var contentItem in items)
                {
                    var contentItemMetadata = Services.ContentManager.GetItemMetadata(contentItem);
                    var propertyDescriptors = tokenizedDescriptors.Select(d =>
                                {
                                    var fieldContext = new PropertyContext
                                    {
                                        State = d.State,
                                        Tokens = tokens
                                    };

                                    return new { d.Property, Shape = d.Descriptor.Property(fieldContext, contentItem) };
                                });

                    var properties = Services.New.Properties(
                            Items: propertyDescriptors.Select(
                                pd => Services.New.PropertyWrapper(
                                    Item: pd.Shape,
                                    Property: pd.Property,
                                    ContentItem: contentItem,
                                    ContentItemMetadata: contentItemMetadata
                                )
                            )
                        );

                    var itemInspector = new ItemInspector(contentItem, contentItemMetadata, _htmlFilters);
                    jsonWriter.WriteStartObject();
                    //jsonWriter.WriteComment("title");
                    //jsonWriter.WritePropertyName("title");
                    //jsonWriter.WriteValue(itemInspector.Title);
                    //jsonWriter.WritePropertyName("description");
                    //jsonWriter.WriteValue(itemInspector.Description);

                    var propertyShapes = ((IEnumerable<dynamic>)properties.Items)
                        .Select(e => new {
                            Property = ((PropertyRecord)e.Property),
                            Description = ((PropertyRecord)e.Property).Description,
                            Proxy = e,
                            Content = Convert.ToString(display(e))
                        })
                        .ToList();

                    foreach (var field in propertyShapes)
                    {
                        jsonWriter.WritePropertyName(field.Description);
                        jsonWriter.WriteValue(field.Content);
                    }

                    jsonWriter.WriteEndObject();
                }

                jsonWriter.WriteEndArray();

                jsonWriter.WriteEndObject();

            }

            return sb.ToString();
            //        var projectionId = context.ValueProvider.GetValue("projection");
            //        if (projectionId == null)
            //            return;

            //        var limitValue = context.ValueProvider.GetValue("limit");
            //        var limit = 20;
            //        if (limitValue != null)
            //            limit = (int)limitValue.ConvertTo(typeof(int));

            //        var containerId = (int)projectionId.ConvertTo(typeof(int));
            //        var container = _contentManager.Get<ProjectionPart>(containerId);

            //        if (container == null)
            //        {
            //            return;
            //        }

            //        var inspector = new ItemInspector(container, _contentManager.GetItemMetadata(container), _htmlFilters);
        }