Ejemplo n.º 1
0
        //============================================================
        //    CLASS SUMMARY
        //============================================================
        /// <summary>
        /// Provides example code for the AtomTextConstruct class.
        /// </summary>
        public static void ClassExample()
        {
            #region AtomTextConstruct
            AtomFeed feed   = new AtomFeed();

            feed.Id         = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"));
            feed.Title      = new AtomTextConstruct("Example Feed");
            feed.UpdatedOn  = new DateTime(2003, 12, 13, 18, 30, 2);

            feed.Links.Add(new AtomLink(new Uri("http://example.org/")));
            feed.Links.Add(new AtomLink(new Uri("/feed"), "self"));

            feed.Authors.Add(new AtomPersonConstruct("John Doe"));

            AtomEntry entry = new AtomEntry();

            entry.Id        = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"));
            entry.Title     = new AtomTextConstruct("Atom-Powered Robots Run Amok");
            entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2);

            //  Provide summary as entity escaped html
            AtomTextConstruct summary   = new AtomTextConstruct();
            summary.Content             = "AT&amp;amp;T bought &lt;b&gt;by SBC&lt;/b&gt;!";
            summary.TextType            = AtomTextConstructType.Html;
            entry.Summary               = summary;

            feed.AddEntry(entry);
            #endregion
        }
        /// <summary>
        /// Saves the current <see cref="AtomTextConstruct"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <param name="elementName">The local name of the text construct being written.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="elementName"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="elementName"/> is an empty string.</exception>
        public void WriteTo(XmlWriter writer, string elementName)
        {
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNullOrEmptyString(elementName, "elementName");
            writer.WriteStartElement(elementName, AtomUtility.AtomNamespace);
            AtomUtility.WriteCommonObjectAttributes(this, writer);

            if (this.TextType == AtomTextConstructType.Xhtml && String.IsNullOrEmpty(writer.LookupPrefix(AtomUtility.XhtmlNamespace)))
            {
                writer.WriteAttributeString("xmlns", "xhtml", null, AtomUtility.XhtmlNamespace);
            }

            if (this.TextType != AtomTextConstructType.None)
            {
                writer.WriteAttributeString("type", AtomTextConstruct.ConstructTypeAsString(this.TextType));
            }

            if (this.TextType == AtomTextConstructType.Xhtml)
            {
                writer.WriteStartElement("div", AtomUtility.XhtmlNamespace);
                writer.WriteString(this.Content);
                writer.WriteEndElement();
            }
            else
            {
                writer.WriteString(this.Content);
            }
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AtomEntryResource"/> class using the supplied <see cref="AtomId"/>, <see cref="AtomTextConstruct"/>, and <see cref="DateTime"/>.
 /// </summary>
 /// <param name="id">A <see cref="AtomId"/> object that represents a permanent, universally unique identifier for this entry.</param>
 /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for this entry.</param>
 /// <param name="updatedOn">
 ///     A <see cref="DateTime"/> that indicates the most recent instant in time when this entry was modified in a way the publisher considers significant. 
 ///     The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC).
 /// </param>
 /// <exception cref="ArgumentNullException">The <paramref name="id"/> is a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="title"/> is a null reference (Nothing in Visual Basic).</exception>
 public AtomEntryResource(AtomId id, AtomTextConstruct title, DateTime updatedOn)
     : base(id, title, updatedOn)
 {
     //------------------------------------------------------------
     //	Initialization handled by base class
     //------------------------------------------------------------
 }
Ejemplo n.º 4
0
        //============================================================
        //	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
            //------------------------------------------------------------
            AtomTextConstruct value = obj as AtomTextConstruct;

            if (value != null)
            {
                int result = String.Compare(this.Content, value.Content, StringComparison.OrdinalIgnoreCase);
                result = result | this.TextType.CompareTo(value.TextType);

                result = result | AtomUtility.CompareCommonObjectAttributes(this, value);

                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>
        /// Loads this <see cref="AtomTextConstruct"/> 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="AtomTextConstruct"/> 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="AtomTextConstruct"/>.
        /// </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 = AtomUtility.CreateNamespaceManager(source.NameTable);

            if (AtomUtility.FillCommonObjectAttributes(this, source))
            {
                wasLoaded = true;
            }
            if (source.HasAttributes)
            {
                string typeAttribute = source.GetAttribute("type", String.Empty);
                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    AtomTextConstructType type = AtomTextConstruct.ConstructTypeByName(typeAttribute);
                    if (type != AtomTextConstructType.None)
                    {
                        this.TextType = type;
                        wasLoaded     = true;
                    }
                }
            }

            if (this.TextType == AtomTextConstructType.Xhtml)
            {
                XPathNavigator xhtmlDivNavigator = source.SelectSingleNode("xhtml:div", manager);
                if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value))
                {
                    this.Content = xhtmlDivNavigator.Value;
                    wasLoaded    = true;
                }
            }
            else if (this.TextType == AtomTextConstructType.Html && !String.IsNullOrEmpty(source.InnerXml))
            {
                this.Content = source.InnerXml;
                wasLoaded    = true;
            }
            else if (!String.IsNullOrEmpty(source.Value))
            {
                this.Content = source.Value;
                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);
            }
            AtomTextConstruct value = obj as AtomTextConstruct;

            if (value != null)
            {
                int result = String.Compare(this.Content, value.Content, StringComparison.OrdinalIgnoreCase);
                result = result | this.TextType.CompareTo(value.TextType);

                result = result | AtomUtility.CompareCommonObjectAttributes(this, value);

                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>
        /// Creates a <see cref="AtomTextConstruct"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <returns>A <see cref="AtomTextConstruct"/> instance initialized using the supplied <paramref name="source"/>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a Atom 0.3 Content construct.
        /// </remarks>
        /// <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>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        private static AtomTextConstruct CreateTextContent(XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            AtomTextConstruct content   = new AtomTextConstruct();

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

            //------------------------------------------------------------
            //	Attempt to extract common attributes information
            //------------------------------------------------------------
            AtomUtility.FillCommonObjectAttributes(content, source);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string modeAttribute    = source.GetAttribute("mode", String.Empty);
                if (!String.IsNullOrEmpty(modeAttribute))
                {
                    if (String.Compare(modeAttribute, "base64", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        content.TextType    = AtomTextConstructType.Text;
                    }
                    else if (String.Compare(modeAttribute, "escaped", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        content.TextType    = AtomTextConstructType.Html;
                    }
                    else if (String.Compare(modeAttribute, "xml", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        content.TextType    = AtomTextConstructType.Xhtml;
                    }
                    else
                    {
                        content.TextType    = AtomTextConstructType.Text;
                    }
                }
            }

            if (content.TextType == AtomTextConstructType.Xhtml)
            {
                XPathNavigator xhtmlDivNavigator    = source.SelectSingleNode("xhtml:div", manager);
                if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value))
                {
                    content.Content = xhtmlDivNavigator.Value;
                }
                else if (!String.IsNullOrEmpty(source.Value))
                {
                    content.Content = source.Value;
                }
            }
            else if (!String.IsNullOrEmpty(source.Value))
            {
                content.Content     = source.Value;
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(content, manager);

            return content;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AtomSource"/> class using the supplied <see cref="AtomId"/>, <see cref="AtomTextConstruct"/>, and <see cref="DateTime"/>.
 /// </summary>
 /// <param name="id">A <see cref="AtomId"/> object that represents a permanent, universally unique identifier for this source.</param>
 /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for this source.</param>
 /// <param name="utcUpdatedOn">
 ///     A <see cref="DateTime"/> that indicates the most recent instant in time when this source was modified in a way the publisher considers significant. 
 ///     The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC).
 /// </param>
 public AtomSource(AtomId id, AtomTextConstruct title, DateTime utcUpdatedOn)
 {
     //------------------------------------------------------------
     //	Initialize class state using properties
     //------------------------------------------------------------
     this.Id         = id;
     this.Title      = title;
     this.UpdatedOn  = utcUpdatedOn;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AtomWorkspace"/> class using the supplied <see cref="AtomTextConstruct"/>.
 /// </summary>
 /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for the workspace.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="title"/> is a null reference (Nothing in Visual Basic).</exception>
 public AtomWorkspace(AtomTextConstruct title)
 {
     //------------------------------------------------------------
     //	Initialize class state using guarded property
     //------------------------------------------------------------
     this.Title  = title;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Loads this <see cref="AtomWorkspace"/> 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="AtomWorkspace"/> 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="AtomWorkspace"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded              = false;

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

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

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

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if(source.HasChildren)
            {
                XPathNavigator titleNavigator           = source.SelectSingleNode("atom:title", manager);
                XPathNodeIterator collectionIterator    = source.Select("app:collection", manager);

                if (titleNavigator != null)
                {
                    this.Title  = new AtomTextConstruct();
                    if (this.Title.Load(titleNavigator))
                    {
                        wasLoaded   = true;
                    }
                }

                if (collectionIterator != null && collectionIterator.Count > 0)
                {
                    while (collectionIterator.MoveNext())
                    {
                        AtomMemberResources collection   = new AtomMemberResources();
                        if (collection.Load(collectionIterator.Current))
                        {
                            this.AddCollection(collection);
                            wasLoaded   = true;
                        }
                    }
                }
            }

            return wasLoaded;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AtomWorkspace"/> class using the supplied <see cref="AtomTextConstruct"/> and <see cref="Collection{AtomMemberResources}"/>.
        /// </summary>
        /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for the workspace.</param>
        /// <param name="collections"></param>
        /// <exception cref="ArgumentNullException">The <paramref name="title"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="collections"/> is a null reference (Nothing in Visual Basic).</exception>
        public AtomWorkspace(AtomTextConstruct title, Collection<AtomMemberResources> collections)
        {
            //------------------------------------------------------------
            //	Initialize class state using guarded property
            //------------------------------------------------------------
            this.Title  = title;

            Guard.ArgumentNotNull(collections, "collections");
            foreach (AtomMemberResources collection in collections)
            {
                this.AddCollection(collection);
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AtomMemberResources"/> class using the supplied <see cref="AtomTextConstruct"/>.
 /// </summary>
 /// <param name="href">A <see cref="Uri"/> that represents a Internationalized Resource Identifier (IRI) that identifies the location of the collection.</param>
 /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for the collection.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="href"/> is a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="title"/> is a null reference (Nothing in Visual Basic).</exception>
 public AtomMemberResources(Uri href, AtomTextConstruct title)
     : this()
 {
     //------------------------------------------------------------
     //	Initialize class state using guarded property
     //------------------------------------------------------------
     this.Uri    = href;
     this.Title  = title;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AtomSource"/> class using the supplied <see cref="AtomId"/>, <see cref="AtomTextConstruct"/>, and <see cref="DateTime"/>.
 /// </summary>
 /// <param name="id">A <see cref="AtomId"/> object that represents a permanent, universally unique identifier for this source.</param>
 /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for this source.</param>
 /// <param name="utcUpdatedOn">
 ///     A <see cref="DateTime"/> that indicates the most recent instant in time when this source was modified in a way the publisher considers significant.
 ///     The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC).
 /// </param>
 public AtomSource(AtomId id, AtomTextConstruct title, DateTime utcUpdatedOn)
 {
     this.Id        = id;
     this.Title     = title;
     this.UpdatedOn = utcUpdatedOn;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AtomEntryResource"/> class using the supplied <see cref="AtomId"/>, <see cref="AtomTextConstruct"/>, and <see cref="DateTime"/>.
 /// </summary>
 /// <param name="id">A <see cref="AtomId"/> object that represents a permanent, universally unique identifier for this entry.</param>
 /// <param name="title">A <see cref="AtomTextConstruct"/> object that represents information that conveys a human-readable title for this entry.</param>
 /// <param name="updatedOn">
 ///     A <see cref="DateTime"/> that indicates the most recent instant in time when this entry was modified in a way the publisher considers significant. 
 ///     The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC).
 /// </param>
 /// <param name="editedOn">
 ///     A <see cref="DateTime"/> that indicates the most recent instant in time when this entry was edited. 
 ///     The <see cref="DateTime"/> should be provided in Coordinated Universal Time (UTC).
 /// </param>
 /// <param name="isDraft">A value indicating if client has requested to control the visibility of the entry.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="id"/> is a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="title"/> is a null reference (Nothing in Visual Basic).</exception>
 public AtomEntryResource(AtomId id, AtomTextConstruct title, DateTime updatedOn, DateTime editedOn, bool isDraft)
     : this(id, title, updatedOn, editedOn)
 {
     //------------------------------------------------------------
     //	Initialize class state using properties
     //------------------------------------------------------------
     this.IsDraft    = isDraft;
 }
Ejemplo n.º 15
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="AtomTextConstruct"/> 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="AtomTextConstruct"/> 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="AtomTextConstruct"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

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

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

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

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string typeAttribute = source.GetAttribute("type", String.Empty);
                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    AtomTextConstructType type = AtomTextConstruct.ConstructTypeByName(typeAttribute);
                    if (type != AtomTextConstructType.None)
                    {
                        this.TextType = type;
                        wasLoaded     = true;
                    }
                }
            }

            if (this.TextType == AtomTextConstructType.Xhtml)
            {
                XPathNavigator xhtmlDivNavigator = source.SelectSingleNode("xhtml:div", manager);
                if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value))
                {
                    this.Content = xhtmlDivNavigator.Value;
                    wasLoaded    = true;
                }
            }
            else if (this.TextType == AtomTextConstructType.Html && !String.IsNullOrEmpty(source.InnerXml))
            {
                this.Content = source.InnerXml;
                wasLoaded    = true;
            }
            else if (!String.IsNullOrEmpty(source.Value))
            {
                this.Content = source.Value;
                wasLoaded    = true;
            }

            return(wasLoaded);
        }