/// <summary> /// Writes the current context to the specified <see cref="XmlWriter"/>. /// </summary> /// <param name="writer">The <b>XmlWriter</b> to which you want to write the current context.</param> /// <param name="xmlNamespace">The XML namespace used to qualify prefixed syndication extension elements and attributes.</param> /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="xmlNamespace"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="xmlNamespace"/> is an empty string.</exception> public void WriteTo(XmlWriter writer, string xmlNamespace) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(writer, "writer"); Guard.ArgumentNotNullOrEmptyString(xmlNamespace, "xmlNamespace"); //------------------------------------------------------------ // Write current extension details to the writer //------------------------------------------------------------ if (this.Period != SiteSummaryUpdatePeriod.None) { writer.WriteElementString("updatePeriod", xmlNamespace, SiteSummaryUpdateSyndicationExtension.PeriodAsString(this.Period)); } if (this.Frequency != Int32.MinValue) { writer.WriteElementString("updateFrequency", xmlNamespace, this.Frequency.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); } if (this.Base != DateTime.MinValue) { writer.WriteElementString("updateBase", xmlNamespace, SyndicationDateTimeUtility.ToRfc3339DateTime(this.Base)); } }
//============================================================ // 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 //------------------------------------------------------------ SiteSummaryUpdateSyndicationExtension value = obj as SiteSummaryUpdateSyndicationExtension; if (value != null) { int result = this.Context.Base.CompareTo(value.Context.Base); result = result | this.Context.Frequency.CompareTo(value.Context.Frequency); result = result | this.Context.Period.CompareTo(value.Context.Period); 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"); } }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source, XmlNamespaceManager manager) /// <summary> /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="SiteSummaryUpdateSyndicationExtensionContext"/>.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param> /// <returns><b>true</b> if the <see cref="SiteSummaryUpdateSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source, XmlNamespaceManager manager) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ if (source.HasChildren) { XPathNavigator updatePeriodNavigator = source.SelectSingleNode("sy:updatePeriod", manager); XPathNavigator updateFrequencyNavigator = source.SelectSingleNode("sy:updateFrequency", manager); XPathNavigator updateBaseNavigator = source.SelectSingleNode("sy:updateBase", manager); if (updatePeriodNavigator != null && !String.IsNullOrEmpty(updatePeriodNavigator.Value)) { SiteSummaryUpdatePeriod period = SiteSummaryUpdateSyndicationExtension.PeriodByName(updatePeriodNavigator.Value); if (period != SiteSummaryUpdatePeriod.None) { this.Period = period; wasLoaded = true; } } if (updateFrequencyNavigator != null) { int frequency; if (Int32.TryParse(updateFrequencyNavigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out frequency)) { this.Frequency = frequency; wasLoaded = true; } } if (updateBaseNavigator != null) { DateTime updateBase; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updateBaseNavigator.Value, out updateBase)) { this.Base = updateBase; wasLoaded = true; } } } return(wasLoaded); }
/// <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 (obj == null) { return(1); } SiteSummaryUpdateSyndicationExtension value = obj as SiteSummaryUpdateSyndicationExtension; if (value != null) { int result = this.Context.Base.CompareTo(value.Context.Base); result = result | this.Context.Frequency.CompareTo(value.Context.Frequency); result = result | this.Context.Period.CompareTo(value.Context.Period); 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"); } }