SyndicationLink.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Syndication
  5. {
  6. using System.Collections.Generic;
  7. using System.Xml;
  8. using System.Collections.ObjectModel;
  9. using System.Xml.Serialization;
  10. using System.Runtime.Serialization;
  11. using System.Runtime.CompilerServices;
  12. // NOTE: This class implements Clone so if you add any members, please update the copy ctor
  13. [TypeForwardedFrom("System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
  14. public class SyndicationLink : IExtensibleSyndicationObject
  15. {
  16. Uri baseUri;
  17. ExtensibleSyndicationObject extensions = new ExtensibleSyndicationObject();
  18. long length;
  19. string mediaType;
  20. string relationshipType;
  21. string title;
  22. Uri uri;
  23. public SyndicationLink(Uri uri)
  24. : this(uri, null, null, null, 0)
  25. {
  26. }
  27. public SyndicationLink(Uri uri, string relationshipType, string title, string mediaType, long length)
  28. {
  29. if (length < 0)
  30. {
  31. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("length"));
  32. }
  33. this.baseUri = null;
  34. this.uri = uri;
  35. this.title = title;
  36. this.relationshipType = relationshipType;
  37. this.mediaType = mediaType;
  38. this.length = length;
  39. }
  40. public SyndicationLink()
  41. : this(null, null, null, null, 0)
  42. {
  43. }
  44. protected SyndicationLink(SyndicationLink source)
  45. {
  46. if (source == null)
  47. {
  48. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
  49. }
  50. this.length = source.length;
  51. this.mediaType = source.mediaType;
  52. this.relationshipType = source.relationshipType;
  53. this.title = source.title;
  54. this.baseUri = source.baseUri;
  55. this.uri = source.uri;
  56. this.extensions = source.extensions.Clone();
  57. }
  58. public Dictionary<XmlQualifiedName, string> AttributeExtensions
  59. {
  60. get { return this.extensions.AttributeExtensions; }
  61. }
  62. public Uri BaseUri
  63. {
  64. get { return this.baseUri; }
  65. set { this.baseUri = value; }
  66. }
  67. public SyndicationElementExtensionCollection ElementExtensions
  68. {
  69. get { return this.extensions.ElementExtensions; }
  70. }
  71. public long Length
  72. {
  73. get { return this.length; }
  74. set
  75. {
  76. if (value < 0)
  77. {
  78. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
  79. }
  80. this.length = value;
  81. }
  82. }
  83. public string MediaType
  84. {
  85. get { return mediaType; }
  86. set { mediaType = value; }
  87. }
  88. public string RelationshipType
  89. {
  90. get { return relationshipType; }
  91. set { relationshipType = value; }
  92. }
  93. public string Title
  94. {
  95. get { return title; }
  96. set { title = value; }
  97. }
  98. public Uri Uri
  99. {
  100. get { return uri; }
  101. set { this.uri = value; }
  102. }
  103. public static SyndicationLink CreateAlternateLink(Uri uri)
  104. {
  105. return CreateAlternateLink(uri, null);
  106. }
  107. public static SyndicationLink CreateAlternateLink(Uri uri, string mediaType)
  108. {
  109. return new SyndicationLink(uri, Atom10Constants.AlternateTag, null, mediaType, 0);
  110. }
  111. public static SyndicationLink CreateMediaEnclosureLink(Uri uri, string mediaType, long length)
  112. {
  113. return new SyndicationLink(uri, Rss20Constants.EnclosureTag, null, mediaType, length);
  114. }
  115. public static SyndicationLink CreateSelfLink(Uri uri)
  116. {
  117. return CreateSelfLink(uri, null);
  118. }
  119. public static SyndicationLink CreateSelfLink(Uri uri, string mediaType)
  120. {
  121. return new SyndicationLink(uri, Atom10Constants.SelfTag, null, mediaType, 0);
  122. }
  123. public virtual SyndicationLink Clone()
  124. {
  125. return new SyndicationLink(this);
  126. }
  127. public Uri GetAbsoluteUri()
  128. {
  129. if (this.uri != null)
  130. {
  131. if (this.uri.IsAbsoluteUri)
  132. {
  133. return this.uri;
  134. }
  135. else if (this.baseUri != null)
  136. {
  137. return new Uri(this.baseUri, this.uri);
  138. }
  139. else
  140. {
  141. return null;
  142. }
  143. }
  144. else
  145. {
  146. return null;
  147. }
  148. }
  149. protected internal virtual bool TryParseAttribute(string name, string ns, string value, string version)
  150. {
  151. return false;
  152. }
  153. protected internal virtual bool TryParseElement(XmlReader reader, string version)
  154. {
  155. return false;
  156. }
  157. protected internal virtual void WriteAttributeExtensions(XmlWriter writer, string version)
  158. {
  159. this.extensions.WriteAttributeExtensions(writer);
  160. }
  161. protected internal virtual void WriteElementExtensions(XmlWriter writer, string version)
  162. {
  163. this.extensions.WriteElementExtensions(writer);
  164. }
  165. internal void LoadElementExtensions(XmlReader readerOverUnparsedExtensions, int maxExtensionSize)
  166. {
  167. this.extensions.LoadElementExtensions(readerOverUnparsedExtensions, maxExtensionSize);
  168. }
  169. internal void LoadElementExtensions(XmlBuffer buffer)
  170. {
  171. this.extensions.LoadElementExtensions(buffer);
  172. }
  173. }
  174. }