/// <summary> /// Saves the current <see cref="IBlogMLCommonObject"/> attributes to the specified <see cref="XmlWriter"/>. /// </summary> /// <param name="source">A object that implements the <see cref="IBlogMLCommonObject"/> interface to extract BlogML common object information from.</param> /// <param name="writer">The <see cref="XmlWriter"/> to which the <paramref name="source"/> information will be written.</param> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception> public static void WriteCommonObjectAttributes(IBlogMLCommonObject source, XmlWriter writer) { Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(writer, "writer"); if (!String.IsNullOrEmpty(source.Id)) { writer.WriteAttributeString("id", source.Id); } if (source.CreatedOn != DateTime.MinValue) { writer.WriteAttributeString("date-created", SyndicationDateTimeUtility.ToRfc3339DateTime(source.CreatedOn)); } if (source.LastModifiedOn != DateTime.MinValue) { writer.WriteAttributeString("date-modified", SyndicationDateTimeUtility.ToRfc3339DateTime(source.LastModifiedOn)); } if (source.ApprovalStatus != BlogMLApprovalStatus.None) { writer.WriteAttributeString("approved", BlogMLUtility.ApprovalStatusAsString(source.ApprovalStatus)); } }
/// <summary> /// Saves the current <see cref="IBlogMLCommonObject"/> elements to the specified <see cref="XmlWriter"/>. /// </summary> /// <param name="source">A object that implements the <see cref="IBlogMLCommonObject"/> interface to extract BlogML common object information from.</param> /// <param name="writer">The <see cref="XmlWriter"/> to which the <paramref name="source"/> information will be written.</param> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception> public static void WriteCommonObjectElements(IBlogMLCommonObject source, XmlWriter writer) { Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(writer, "writer"); if (source.Title != null) { source.Title.WriteTo(writer, "title"); } }
/// <summary> /// Saves the current <see cref="IBlogMLCommonObject"/> elements to the specified <see cref="XmlWriter"/>. /// </summary> /// <param name="source">A object that implements the <see cref="IBlogMLCommonObject"/> interface to extract BlogML common object information from.</param> /// <param name="writer">The <see cref="XmlWriter"/> to which the <paramref name="source"/> information will be written.</param> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception> public static void WriteCommonObjectElements(IBlogMLCommonObject source, XmlWriter writer) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(writer, "writer"); //------------------------------------------------------------ // Write common entity information //------------------------------------------------------------ if (source.Title != null) { source.Title.WriteTo(writer, "title"); } }
/// <summary> /// Compares objects that implement the <see cref="IBlogMLCommonObject"/> interface. /// </summary> /// <param name="source">A object that implements the <see cref="IBlogMLCommonObject"/> interface to be compared.</param> /// <param name="target">A object that implements the <see cref="IBlogMLCommonObject"/> to compare with the <paramref name="source"/>.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> public static int CompareCommonObjects(IBlogMLCommonObject source, IBlogMLCommonObject target) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ int result = 0; //------------------------------------------------------------ // Handle parameter null reference cases //------------------------------------------------------------ if (source == null && target == null) { return(0); } else if (source != null && target == null) { return(1); } else if (source == null && target != null) { return(-1); } //------------------------------------------------------------ // Attempt to perform comparison //------------------------------------------------------------ result = source.ApprovalStatus.CompareTo(target.ApprovalStatus); result = result | source.CreatedOn.CompareTo(target.CreatedOn); result = result | String.Compare(source.Id, target.Id, StringComparison.OrdinalIgnoreCase); result = result | source.LastModifiedOn.CompareTo(target.LastModifiedOn); if (source.Title != null && target.Title != null) { result = result | source.Title.CompareTo(target.Title); } else if (source.Title != null && target.Title == null) { result = result | 1; } else if (source.Title == null && target.Title != null) { result = result | -1; } return(result); }
/// <summary> /// Compares objects that implement the <see cref="IBlogMLCommonObject"/> interface. /// </summary> /// <param name="source">A object that implements the <see cref="IBlogMLCommonObject"/> interface to be compared.</param> /// <param name="target">A object that implements the <see cref="IBlogMLCommonObject"/> to compare with the <paramref name="source"/>.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> public static int CompareCommonObjects(IBlogMLCommonObject source, IBlogMLCommonObject target) { int result = 0; if (source == null && target == null) { return(0); } else if (source != null && target == null) { return(1); } else if (source == null && target != null) { return(-1); } result = source.ApprovalStatus.CompareTo(target.ApprovalStatus); result = result | source.CreatedOn.CompareTo(target.CreatedOn); result = result | String.Compare(source.Id, target.Id, StringComparison.OrdinalIgnoreCase); result = result | source.LastModifiedOn.CompareTo(target.LastModifiedOn); if (source.Title != null && target.Title != null) { result = result | source.Title.CompareTo(target.Title); } else if (source.Title != null && target.Title == null) { result = result | 1; } else if (source.Title == null && target.Title != null) { result = result | -1; } return(result); }
/// <summary> /// Modifies the <see cref="IBlogMLCommonObject"/> to match the data source. /// </summary> /// <param name="target">The object that implements the <see cref="IBlogMLCommonObject"/> interface to be filled.</param> /// <param name="source">The <see cref="XPathNavigator"/> to extract BlogML common object information from.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param> /// <returns><b>true</b> if the <paramref name="target"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="target"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="source"/> 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> public static bool FillCommonObject(IBlogMLCommonObject target, XPathNavigator source, SyndicationResourceLoadSettings settings) { bool wasLoaded = false; Guard.ArgumentNotNull(target, "target"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(settings, "settings"); XmlNamespaceManager manager = BlogMLUtility.CreateNamespaceManager(source.NameTable); if (source.HasAttributes) { string idAttribute = source.GetAttribute("id", String.Empty); string dateCreatedAttribute = source.GetAttribute("date-created", String.Empty); string dateModifiedAttribute = source.GetAttribute("date-modified", String.Empty); string approvedAttribute = source.GetAttribute("approved", String.Empty); if (!String.IsNullOrEmpty(idAttribute)) { target.Id = idAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(dateCreatedAttribute)) { DateTime createdOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(dateCreatedAttribute, out createdOn)) { target.CreatedOn = createdOn; wasLoaded = true; } else if (DateTime.TryParse(dateCreatedAttribute, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out createdOn)) { target.CreatedOn = createdOn; wasLoaded = true; } } if (!String.IsNullOrEmpty(dateModifiedAttribute)) { DateTime modifiedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(dateModifiedAttribute, out modifiedOn)) { target.LastModifiedOn = modifiedOn; wasLoaded = true; } else if (DateTime.TryParse(dateModifiedAttribute, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out modifiedOn)) { target.LastModifiedOn = modifiedOn; wasLoaded = true; } } if (!String.IsNullOrEmpty(approvedAttribute)) { BlogMLApprovalStatus status = BlogMLUtility.ApprovalStatusByValue(approvedAttribute); if (status != BlogMLApprovalStatus.None) { target.ApprovalStatus = status; wasLoaded = true; } } } if (source.HasChildren) { XPathNavigator titleNavigator = source.SelectSingleNode("blog:title", manager); if (titleNavigator != null) { BlogMLTextConstruct title = new BlogMLTextConstruct(); if (title.Load(titleNavigator, settings)) { target.Title = title; wasLoaded = true; } } } return(wasLoaded); }