ResourceCollectionInfo.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Syndication
  5. {
  6. using System.Collections.ObjectModel;
  7. using System.Runtime.Serialization;
  8. using System.Xml.Serialization;
  9. using System.Collections.Generic;
  10. using System.Xml;
  11. using System.Runtime.CompilerServices;
  12. [TypeForwardedFrom("System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
  13. public class ResourceCollectionInfo : IExtensibleSyndicationObject
  14. {
  15. static IEnumerable<string> singleEmptyAccept;
  16. Collection<string> accepts;
  17. Uri baseUri;
  18. Collection<CategoriesDocument> categories;
  19. ExtensibleSyndicationObject extensions = new ExtensibleSyndicationObject();
  20. Uri link;
  21. TextSyndicationContent title;
  22. public ResourceCollectionInfo()
  23. {
  24. }
  25. public ResourceCollectionInfo(string title, Uri link)
  26. : this((title == null) ? null : new TextSyndicationContent(title), link)
  27. {
  28. }
  29. public ResourceCollectionInfo(TextSyndicationContent title, Uri link)
  30. : this(title, link, null, null)
  31. {
  32. }
  33. public ResourceCollectionInfo(TextSyndicationContent title, Uri link, IEnumerable<CategoriesDocument> categories, bool allowsNewEntries)
  34. : this(title, link, categories, (allowsNewEntries) ? null : CreateSingleEmptyAccept())
  35. {
  36. }
  37. public ResourceCollectionInfo(TextSyndicationContent title, Uri link, IEnumerable<CategoriesDocument> categories, IEnumerable<string> accepts)
  38. {
  39. if (title == null)
  40. {
  41. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("title");
  42. }
  43. if (link == null)
  44. {
  45. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("link");
  46. }
  47. this.title = title;
  48. this.link = link;
  49. if (categories != null)
  50. {
  51. this.categories = new NullNotAllowedCollection<CategoriesDocument>();
  52. foreach (CategoriesDocument category in categories)
  53. {
  54. this.categories.Add(category);
  55. }
  56. }
  57. if (accepts != null)
  58. {
  59. this.accepts = new NullNotAllowedCollection<string>();
  60. foreach (string accept in accepts)
  61. {
  62. this.accepts.Add(accept);
  63. }
  64. }
  65. }
  66. public Collection<string> Accepts
  67. {
  68. get
  69. {
  70. if (this.accepts == null)
  71. {
  72. this.accepts = new NullNotAllowedCollection<string>();
  73. }
  74. return this.accepts;
  75. }
  76. }
  77. public Dictionary<XmlQualifiedName, string> AttributeExtensions
  78. {
  79. get
  80. {
  81. return this.extensions.AttributeExtensions;
  82. }
  83. }
  84. public Uri BaseUri
  85. {
  86. get { return this.baseUri; }
  87. set { this.baseUri = value; }
  88. }
  89. public Collection<CategoriesDocument> Categories
  90. {
  91. get
  92. {
  93. if (this.categories == null)
  94. {
  95. this.categories = new NullNotAllowedCollection<CategoriesDocument>();
  96. }
  97. return this.categories;
  98. }
  99. }
  100. public SyndicationElementExtensionCollection ElementExtensions
  101. {
  102. get
  103. {
  104. return this.extensions.ElementExtensions;
  105. }
  106. }
  107. public Uri Link
  108. {
  109. get { return this.link; }
  110. set { this.link = value; }
  111. }
  112. public TextSyndicationContent Title
  113. {
  114. get { return this.title; }
  115. set { this.title = value; }
  116. }
  117. protected internal virtual InlineCategoriesDocument CreateInlineCategoriesDocument()
  118. {
  119. return new InlineCategoriesDocument();
  120. }
  121. protected internal virtual ReferencedCategoriesDocument CreateReferencedCategoriesDocument()
  122. {
  123. return new ReferencedCategoriesDocument();
  124. }
  125. protected internal virtual bool TryParseAttribute(string name, string ns, string value, string version)
  126. {
  127. return false;
  128. }
  129. protected internal virtual bool TryParseElement(XmlReader reader, string version)
  130. {
  131. return false;
  132. }
  133. protected internal virtual void WriteAttributeExtensions(XmlWriter writer, string version)
  134. {
  135. this.extensions.WriteAttributeExtensions(writer);
  136. }
  137. protected internal virtual void WriteElementExtensions(XmlWriter writer, string version)
  138. {
  139. this.extensions.WriteElementExtensions(writer);
  140. }
  141. internal void LoadElementExtensions(XmlReader readerOverUnparsedExtensions, int maxExtensionSize)
  142. {
  143. this.extensions.LoadElementExtensions(readerOverUnparsedExtensions, maxExtensionSize);
  144. }
  145. internal void LoadElementExtensions(XmlBuffer buffer)
  146. {
  147. this.extensions.LoadElementExtensions(buffer);
  148. }
  149. static IEnumerable<string> CreateSingleEmptyAccept()
  150. {
  151. if (singleEmptyAccept == null)
  152. {
  153. List<string> tmp = new List<string>(1);
  154. tmp.Add(string.Empty);
  155. singleEmptyAccept = tmp.AsReadOnly();
  156. }
  157. return singleEmptyAccept;
  158. }
  159. }
  160. }