Esempio n. 1
0
    private void GetPosts(object sender, EventArgs e)
    {
        TransitPostQueryOptions options = new TransitPostQueryOptions();
        options.PageNumber = 0;
        options.PageSize = 25;
        options.SortDirection = WebServiceQuerySortDirection.Descending;
        options.SortExpression = "Created";
        options.PublishedOnly = true;
        options.DisplayedOnly = true;

        Response.ContentType = "application/atom+xml;charset=\"utf-8\"";

        AtomFeed feed = new AtomFeed();
        feed.Title = new AtomTextConstruct(SessionManager.GetSetting("title", "Untitled"));

        List<TransitPost> posts = SessionManager.GetCachedCollection<TransitPost>(
            "GetPosts", SessionManager.PostTicket, options);

        foreach (TransitPost post in posts)
        {
            AtomEntry atomEntry = GetPost(post);
            feed.AddEntry(atomEntry);
        }

        feed.Save(Response.OutputStream);
        Response.End();
    }
Esempio n. 2
0
        /// <summary>
        /// Provides example code for the Save(XmlWriter) method
        /// </summary>
        public static void SaveXmlWriterExample()
        {
            #region Save(XmlWriter writer)
            AtomFeed feed   = new AtomFeed();

            //  Modify feed state using public properties and methods

            using (Stream stream = new FileStream("AtomFeed.xml", FileMode.Create, FileAccess.Write))
            {
                XmlWriterSettings settings  = new XmlWriterSettings();
                settings.Indent             = true;

                using(XmlWriter writer = XmlWriter.Create(stream, settings))
                {
                    feed.Save(writer);
                }
            }
            #endregion
        }
 private static string ToXmlString(AtomFeed feed)
 {
     var stringBuilder = new StringBuilder();
     var xmlWriter = XmlWriter.Create(stringBuilder);
     feed.Save(xmlWriter);
     xmlWriter.Flush();
     xmlWriter.Close();
     return stringBuilder.ToString();
 }
Esempio n. 4
0
        /// <summary>
        /// Provides example code for the Save(Stream) method
        /// </summary>
        public static void SaveStreamExample()
        {
            #region Save(Stream stream)
            AtomFeed feed   = new AtomFeed();

            //  Modify feed state using public properties and methods

            using(Stream stream = new FileStream("AtomFeed.xml", FileMode.Create, FileAccess.Write))
            {
                feed.Save(stream);
            }
            #endregion
        }
Esempio n. 5
0
        public override void ExecuteItemSequence(string groupByValue, IEnumerable<Tuple<ITaskItem, ITaskItem, ITaskItem>> items)
        {
            var feed = new AtomFeed
            {
                Id = new AtomId(new Uri(FeedId)),
                Title = new AtomTextConstruct(FeedTitle ?? ""),
                UpdatedOn = DateTime.Now,
            };

            if (!string.IsNullOrWhiteSpace(FeedRights))
            {
                feed.Rights = new AtomTextConstruct(FeedRights);
            }

            if (!string.IsNullOrWhiteSpace(FeedIcon))
            {
                feed.Icon = new AtomIcon(new Uri(FeedIcon));
            }

            if (!string.IsNullOrWhiteSpace(FeedLogo))
            {
                feed.Logo = new AtomLogo(new Uri(FeedLogo));
            }

            if (!string.IsNullOrWhiteSpace(FeedSubtitle))
            {
                feed.Subtitle = new AtomTextConstruct(FeedSubtitle);
            }

            if (!string.IsNullOrWhiteSpace(FeedAuthors))
            {
                foreach (string author in FeedAuthors.Split(';').Select(item => item.Trim()))
                {
                    feed.Authors.Add(new AtomPersonConstruct(author));
                }
            }

            if (!string.IsNullOrWhiteSpace(FeedContributors))
            {
                foreach (string contributor in FeedContributors.Split(';').Select(item => item.Trim()))
                {
                    feed.Contributors.Add(new AtomPersonConstruct(contributor));
                }
            }

            if (!string.IsNullOrWhiteSpace(FeedCategories))
            {
                foreach (string category in FeedCategories.Split(';').Select(item => item.Trim()))
                {
                    feed.Categories.Add(new AtomCategory(category));
                }
            }

            if (FeedLinkRelationSelf != null)
            {

                var selfLink = new AtomLink
                       {
                           Relation = "self",
                           Uri = new Uri(FeedLinkRelationSelf)
                       };
                feed.Links.Add(selfLink);
            }

            foreach (Tuple<ITaskItem, ITaskItem, ITaskItem> tuple in items.OrderByDescending(item => item.Item2.GetTimestamp()))
            {
                ITaskItem modelInput = tuple.Item1;
                ITaskItem receiptInput = tuple.Item2;
                ITaskItem contentInput = tuple.Item3;

                modelInput.LoadCustomMetadata();

                DateTime receiptModified = receiptInput.GetTimestamp();
                var entry = new AtomEntry
                {
                    Id = new AtomId(new Uri(modelInput.GetMetadata(EntryIdSelector ?? "Uri"))),
                    Title = new AtomTextConstruct(modelInput.GetMetadata(EntryTitleSelector ?? "Title")),
                    UpdatedOn = receiptModified,
                    Summary = new AtomTextConstruct(modelInput.GetMetadata(EntrySummarySelector ?? "Summary")),
                };

                if (string.IsNullOrWhiteSpace(entry.Title.Content))
                {
                    entry.Title.Content = tuple.Item1.ItemSpec;
                }
                if (string.IsNullOrWhiteSpace(entry.Summary.Content))
                {
                    entry.Summary.Content = entry.Title.Content;
                }

                if (contentInput.Exists())
                {
                    if (string.IsNullOrWhiteSpace(EntryContentEncoding))
                    {
                        entry.Content = new AtomContent(contentInput.ReadAllText());
                    }
                    else
                    {
                        entry.Content = new AtomContent(contentInput.ReadAllText(), EntryContentEncoding);
                    }

                    if (!string.IsNullOrWhiteSpace(EntryContentType))
                    {
                        entry.Content.ContentType = EntryContentType;
                    }
                }

                var alternateLink = new AtomLink
                {
                    Relation = "alternate",
                    Uri = new Uri(modelInput.GetMetadata(EntryLinkAlternateSelector ?? "Uri"))
                };
                entry.Links.Add(alternateLink);
                feed.AddEntry(entry);
            }
            using (FileStream stream = File.OpenWrite(Output.ItemSpec))
            {
                SyndicationResourceSaveSettings s = new SyndicationResourceSaveSettings() { CharacterEncoding = Encoding.UTF8 };
                feed.Save(stream, s);
            }
        }