ServiceDocument.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 ServiceDocument : IExtensibleSyndicationObject
  14. {
  15. Uri baseUri;
  16. ExtensibleSyndicationObject extensions = new ExtensibleSyndicationObject();
  17. string language;
  18. Collection<Workspace> workspaces;
  19. public ServiceDocument() : this(null)
  20. {
  21. }
  22. public ServiceDocument(IEnumerable<Workspace> workspaces)
  23. {
  24. if (workspaces != null)
  25. {
  26. this.workspaces = new NullNotAllowedCollection<Workspace>();
  27. foreach (Workspace workspace in workspaces)
  28. {
  29. this.workspaces.Add(workspace);
  30. }
  31. }
  32. }
  33. public Dictionary<XmlQualifiedName, string> AttributeExtensions
  34. {
  35. get { return this.extensions.AttributeExtensions; }
  36. }
  37. public Uri BaseUri
  38. {
  39. get { return this.baseUri; }
  40. set { this.baseUri = value; }
  41. }
  42. public SyndicationElementExtensionCollection ElementExtensions
  43. {
  44. get { return this.extensions.ElementExtensions; }
  45. }
  46. public string Language
  47. {
  48. get { return this.language; }
  49. set { this.language = value; }
  50. }
  51. public Collection<Workspace> Workspaces
  52. {
  53. get
  54. {
  55. if (this.workspaces == null)
  56. {
  57. this.workspaces = new NullNotAllowedCollection<Workspace>();
  58. }
  59. return this.workspaces;
  60. }
  61. }
  62. public static ServiceDocument Load(XmlReader reader)
  63. {
  64. return Load<ServiceDocument>(reader);
  65. }
  66. public static TServiceDocument Load<TServiceDocument>(XmlReader reader)
  67. where TServiceDocument : ServiceDocument, new ()
  68. {
  69. AtomPub10ServiceDocumentFormatter<TServiceDocument> formatter = new AtomPub10ServiceDocumentFormatter<TServiceDocument>();
  70. formatter.ReadFrom(reader);
  71. return (TServiceDocument)(object) formatter.Document;
  72. }
  73. public ServiceDocumentFormatter GetFormatter()
  74. {
  75. return new AtomPub10ServiceDocumentFormatter(this);
  76. }
  77. public void Save(XmlWriter writer)
  78. {
  79. new AtomPub10ServiceDocumentFormatter(this).WriteTo(writer);
  80. }
  81. protected internal virtual Workspace CreateWorkspace()
  82. {
  83. return new Workspace();
  84. }
  85. protected internal virtual bool TryParseAttribute(string name, string ns, string value, string version)
  86. {
  87. return false;
  88. }
  89. protected internal virtual bool TryParseElement(XmlReader reader, string version)
  90. {
  91. return false;
  92. }
  93. protected internal virtual void WriteAttributeExtensions(XmlWriter writer, string version)
  94. {
  95. this.extensions.WriteAttributeExtensions(writer);
  96. }
  97. protected internal virtual void WriteElementExtensions(XmlWriter writer, string version)
  98. {
  99. this.extensions.WriteElementExtensions(writer);
  100. }
  101. internal void LoadElementExtensions(XmlReader readerOverUnparsedExtensions, int maxExtensionSize)
  102. {
  103. this.extensions.LoadElementExtensions(readerOverUnparsedExtensions, maxExtensionSize);
  104. }
  105. internal void LoadElementExtensions(XmlBuffer buffer)
  106. {
  107. this.extensions.LoadElementExtensions(buffer);
  108. }
  109. }
  110. }