FeedLib.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4. using System.ServiceModel.Syndication;
  5. class FeedLib
  6. {
  7. public static readonly DateTime FixedChangedDate = new DateTime(2000, 5, 12, 0, 0, 0);
  8. public static SyndicationFeed EmptyFeed
  9. {
  10. get {
  11. SyndicationFeed f = new SyndicationFeed();
  12. f.Id = "Id should be guid if not set";
  13. return f;
  14. }
  15. }
  16. public static SyndicationFeed FeedNoItems
  17. {
  18. get {
  19. SyndicationFeed f = new SyndicationFeed();
  20. f.Id = "FeedNoItems";
  21. f.Title = SyndicationContent.CreatePlaintextTextSyndicationContent("Sample Title");
  22. return f;
  23. }
  24. }
  25. public static SyndicationFeed FeedNoItemsSimpleProps
  26. {
  27. get {
  28. SyndicationFeed f = new SyndicationFeed();
  29. f.Id = "FeedNoItems";
  30. f.Title = SyndicationContent.CreatePlaintextTextSyndicationContent("My Title");
  31. f.Copyright = SyndicationContent.CreatePlaintextTextSyndicationContent("My Copyright");
  32. f.Generator = "My Generator";
  33. f.Language = "My Language";
  34. f.ImageUrl = new Uri("http://example.org/image.png");
  35. f.Copyright = SyndicationContent.CreatePlaintextTextSyndicationContent("My Description");
  36. return f;
  37. }
  38. }
  39. public static SyndicationFeed FeedWithItems
  40. {
  41. get {
  42. SyndicationFeed f = new SyndicationFeed();
  43. f.Id = "Id should be guid if not set";
  44. f.Title = SyndicationContent.CreatePlaintextTextSyndicationContent("Words in a popular panagram.");
  45. string words = "The quick brown fox jumps over the lazy dog";
  46. int indx = 0;
  47. foreach (string p in words.Split(' '))
  48. {
  49. SyndicationItem i = new SyndicationItem();
  50. i.Id = indx.ToString();
  51. indx++;
  52. i.Title = SyndicationContent.CreatePlaintextTextSyndicationContent(p);
  53. i.Summary = new TextSyndicationContent(String.Format("<b>{0} in bold letters</b>", p), TextSyndicationContentKind.Html);
  54. i.Content = new TextSyndicationContent("My Content");
  55. i.Copyright = new TextSyndicationContent("My Copyright");
  56. i.LastUpdatedTime = FixedChangedDate;
  57. i.PublishDate = FixedChangedDate;
  58. i.SourceFeed = f;
  59. f.Items.Add(i);
  60. }
  61. return f;
  62. }
  63. }
  64. }