/// <summary>
        /// Loads this <see cref="BlogMLComment"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="BlogMLComment"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="BlogMLComment"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            XmlNamespaceManager manager = BlogMLUtility.CreateNamespaceManager(source.NameTable);

            if (BlogMLUtility.FillCommonObject(this, source))
            {
                wasLoaded = true;
            }
            if (source.HasAttributes)
            {
                string userNameAttribute  = source.GetAttribute("user-name", String.Empty);
                string userEmailAttribute = source.GetAttribute("user-email", String.Empty);
                string userUrlAttribute   = source.GetAttribute("user-url", String.Empty);

                if (!String.IsNullOrEmpty(userNameAttribute))
                {
                    this.UserName = userNameAttribute;
                    wasLoaded     = true;
                }

                if (!String.IsNullOrEmpty(userEmailAttribute))
                {
                    this.UserEmailAddress = userEmailAttribute;
                    wasLoaded             = true;
                }

                if (!String.IsNullOrEmpty(userUrlAttribute))
                {
                    Uri url;
                    if (Uri.TryCreate(userUrlAttribute, UriKind.RelativeOrAbsolute, out url))
                    {
                        this.UserUrl = url;
                        wasLoaded    = true;
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNavigator contentNavigator = source.SelectSingleNode("blog:content", manager);
                if (contentNavigator != null)
                {
                    BlogMLTextConstruct content = new BlogMLTextConstruct();
                    if (content.Load(contentNavigator))
                    {
                        this.Content = content;
                        wasLoaded    = true;
                    }
                }
            }

            return(wasLoaded);
        }
        /// <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);
        }
Пример #3
0
        /// <summary>
        /// Loads this <see cref="ApmlApplication"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param>
        /// <returns><b>true</b> if the <see cref="ApmlApplication"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="ApmlApplication"/>.
        /// </remarks>
        /// <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 bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Initialize XML namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = BlogMLUtility.CreateNamespaceManager(source.NameTable);

            //------------------------------------------------------------
            //	Attempt to extract common attributes information
            //------------------------------------------------------------
            if (BlogMLUtility.FillCommonObject(this, source, settings))
            {
                wasLoaded = true;
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string userNameAttribute  = source.GetAttribute("user-name", String.Empty);
                string userEmailAttribute = source.GetAttribute("user-email", String.Empty);
                string userUrlAttribute   = source.GetAttribute("user-url", String.Empty);

                if (!String.IsNullOrEmpty(userNameAttribute))
                {
                    this.UserName = userNameAttribute;
                    wasLoaded     = true;
                }

                if (!String.IsNullOrEmpty(userEmailAttribute))
                {
                    this.UserEmailAddress = userEmailAttribute;
                    wasLoaded             = true;
                }

                if (!String.IsNullOrEmpty(userUrlAttribute))
                {
                    Uri url;
                    if (Uri.TryCreate(userUrlAttribute, UriKind.RelativeOrAbsolute, out url))
                    {
                        this.UserUrl = url;
                        wasLoaded    = true;
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNavigator contentNavigator = source.SelectSingleNode("blog:content", manager);
                if (contentNavigator != null)
                {
                    BlogMLTextConstruct content = new BlogMLTextConstruct();
                    if (content.Load(contentNavigator))
                    {
                        this.Content = content;
                        wasLoaded    = true;
                    }
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);

            adapter.Fill(this);

            return(wasLoaded);
        }