//============================================================ // ICOMPARABLE IMPLEMENTATION //============================================================ #region CompareTo(object obj) /// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">An object to compare with this instance.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception> public int CompareTo(object obj) { //------------------------------------------------------------ // If target is a null reference, instance is greater //------------------------------------------------------------ if (obj == null) { return(1); } //------------------------------------------------------------ // Determine comparison result using property state of objects //------------------------------------------------------------ SyndicationResourceSaveSettings value = obj as SyndicationResourceSaveSettings; if (value != null) { int result = String.Compare(this.CharacterEncoding.WebName, value.CharacterEncoding.WebName, StringComparison.OrdinalIgnoreCase); result = result | this.MinimizeOutputSize.CompareTo(value.MinimizeOutputSize); result = result | ComparisonUtility.CompareSequence(this.SupportedExtensions, value.SupportedExtensions); result = result | this.AutoDetectExtensions.CompareTo(value.AutoDetectExtensions); return(result); } else { throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj"); } }
/// <summary> /// Saves the current <see cref="AtomFeed"/> collection entities to the specified <see cref="XmlWriter"/>. /// </summary> /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param> /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception> private void WriteFeedCollections(XmlWriter writer) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ SyndicationResourceSaveSettings settings = new SyndicationResourceSaveSettings(); settings.AutoDetectExtensions = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(writer, "writer"); foreach (AtomLink link in this.Links) { link.WriteTo(writer); } foreach(AtomPersonConstruct author in this.Authors) { author.WriteTo(writer, "author"); } foreach (AtomCategory category in this.Categories) { category.WriteTo(writer); } foreach (AtomPersonConstruct contributor in this.Contributors) { contributor.WriteTo(writer, "contributor"); } }
/// <summary> /// Saves the syndication resource to the specified <see cref="XmlWriter"/> and <see cref="SyndicationResourceSaveSettings"/>. /// </summary> /// <param name="writer">The <b>XmlWriter</b> to which you want to save the syndication resource.</param> /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="AtomFeed"/> instance.</param> /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception> public void Save(XmlWriter writer, SyndicationResourceSaveSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(writer, "writer"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Save feed //------------------------------------------------------------ writer.WriteStartElement("feed", AtomUtility.AtomNamespace); // writer.WriteAttributeString("version", this.Version.ToString()); if (settings.AutoDetectExtensions) { SyndicationExtensionAdapter.FillExtensionTypes(this, settings.SupportedExtensions); if (this.Generator != null) { SyndicationExtensionAdapter.FillExtensionTypes(this.Generator, settings.SupportedExtensions); } if (this.Icon != null) { SyndicationExtensionAdapter.FillExtensionTypes(this.Icon, settings.SupportedExtensions); } if (this.Id != null) { SyndicationExtensionAdapter.FillExtensionTypes(this.Id, settings.SupportedExtensions); } if (this.Logo != null) { SyndicationExtensionAdapter.FillExtensionTypes(this.Logo, settings.SupportedExtensions); } if (this.Rights != null) { SyndicationExtensionAdapter.FillExtensionTypes(this.Rights, settings.SupportedExtensions); } if (this.Subtitle != null) { SyndicationExtensionAdapter.FillExtensionTypes(this.Subtitle, settings.SupportedExtensions); } if (this.Title != null) { SyndicationExtensionAdapter.FillExtensionTypes(this.Title, settings.SupportedExtensions); } foreach (AtomPersonConstruct author in this.Authors) { SyndicationExtensionAdapter.FillExtensionTypes(author, settings.SupportedExtensions); } foreach (AtomCategory category in this.Categories) { SyndicationExtensionAdapter.FillExtensionTypes(category, settings.SupportedExtensions); } foreach (AtomPersonConstruct contributor in this.Contributors) { SyndicationExtensionAdapter.FillExtensionTypes(contributor, settings.SupportedExtensions); } foreach (AtomEntry entry in this.Entries) { SyndicationExtensionAdapter.FillExtensionTypes(entry, settings.SupportedExtensions); } foreach (AtomLink link in this.Links) { SyndicationExtensionAdapter.FillExtensionTypes(link, settings.SupportedExtensions); } } SyndicationExtensionAdapter.WriteXmlNamespaceDeclarations(settings.SupportedExtensions, writer); AtomUtility.WriteCommonObjectAttributes(this, writer); if(this.Id != null) { this.Id.WriteTo(writer); } if (this.Title != null) { this.Title.WriteTo(writer, "title"); } if(this.UpdatedOn != DateTime.MinValue) { writer.WriteElementString("updated", AtomUtility.AtomNamespace, SyndicationDateTimeUtility.ToRfc3339DateTime(this.UpdatedOn)); } this.WriteFeedOptionals(writer); this.WriteFeedCollections(writer); //------------------------------------------------------------ // Write the syndication extensions of the current instance //------------------------------------------------------------ SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer); foreach (AtomEntry entry in this.Entries) { entry.Save(writer, settings); } writer.WriteEndElement(); }
/// <summary> /// Saves the syndication resource to the specified <see cref="Stream"/>. /// </summary> /// <param name="stream">The <b>Stream</b> to which you want to save the syndication resource.</param> /// <param name="settings">The <see cref="SyndicationResourceSaveSettings"/> object used to configure the persistance of the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param> /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="XmlException">The operation would not result in well formed XML for the syndication resource.</exception> public void Save(Stream stream, SyndicationResourceSaveSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(stream, "stream"); if (settings == null) { settings = new SyndicationResourceSaveSettings(); } //------------------------------------------------------------ // Create XmlWriter against supplied stream to save feed //------------------------------------------------------------ XmlWriterSettings writerSettings = new XmlWriterSettings(); writerSettings.OmitXmlDeclaration = false; writerSettings.Indent = !settings.MinimizeOutputSize; writerSettings.Encoding = settings.CharacterEncoding; using (XmlWriter writer = XmlWriter.Create(stream, writerSettings)) { this.Save(writer, settings); } }