示例#1
0
        /// <summary>
        /// Compares objects that implement the <see cref="IAtomCommonObjectAttributes"/> interface.
        /// </summary>
        /// <param name="source">A object that implements the <see cref="IAtomCommonObjectAttributes"/> interface to be compared.</param>
        /// <param name="target">A object that implements the <see cref="IAtomCommonObjectAttributes"/> 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 CompareCommonObjectAttributes(IAtomCommonObjectAttributes source, IAtomCommonObjectAttributes 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 = result | Uri.Compare(source.BaseUri, target.BaseUri, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase);

            string sourceLanguageName = source.Language != null ? source.Language.Name : String.Empty;
            string targetLanguageName = target.Language != null ? target.Language.Name : String.Empty;

            result = result | String.Compare(sourceLanguageName, targetLanguageName, StringComparison.OrdinalIgnoreCase);

            return(result);
        }
        /// <summary>
        /// Compares objects that implement the <see cref="IAtomCommonObjectAttributes"/> interface.
        /// </summary>
        /// <param name="source">A object that implements the <see cref="IAtomCommonObjectAttributes"/> interface to be compared.</param>
        /// <param name="target">A object that implements the <see cref="IAtomCommonObjectAttributes"/> 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 CompareCommonObjectAttributes(IAtomCommonObjectAttributes source, IAtomCommonObjectAttributes 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 = result | Uri.Compare(source.BaseUri, target.BaseUri, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase);

            string sourceLanguageName = source.Language != null ? source.Language.Name : String.Empty;
            string targetLanguageName = target.Language != null ? target.Language.Name : String.Empty;

            result = result | String.Compare(sourceLanguageName, targetLanguageName, StringComparison.OrdinalIgnoreCase);

            return(result);
        }
示例#3
0
        /// <summary>
        /// Modifies the <see cref="IAtomCommonObjectAttributes"/> to match the data source.
        /// </summary>
        /// <param name="target">The object that implements the <see cref="IAtomCommonObjectAttributes"/> interface to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract Atom common attribute information from.</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>
        public static bool FillCommonObjectAttributes(IAtomCommonObjectAttributes target, XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

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

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

            //------------------------------------------------------------
            //	Attempt to extract xml:base attribute information
            //------------------------------------------------------------
            string xmlBaseAttribute = source.GetAttribute("base", manager.LookupNamespace("xml"));

            if (!String.IsNullOrEmpty(xmlBaseAttribute))
            {
                Uri baseUri;
                if (Uri.TryCreate(xmlBaseAttribute, UriKind.RelativeOrAbsolute, out baseUri))
                {
                    target.BaseUri = baseUri;
                    wasLoaded      = true;
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract xml:lang attribute information
            //------------------------------------------------------------
            string xmlLangAttribute = source.GetAttribute("lang", manager.LookupNamespace("xml"));

            if (!String.IsNullOrEmpty(xmlLangAttribute))
            {
                try
                {
                    CultureInfo language = new CultureInfo(source.XmlLang);
                    target.Language = language;
                    wasLoaded       = true;
                }
                catch (ArgumentException)
                {
                    System.Diagnostics.Trace.TraceWarning("Unable to determine CultureInfo with a name of {0}.", source.XmlLang);
                }
            }

            return(wasLoaded);
        }
 /// <summary>
 /// Saves the current <see cref="IAtomCommonObjectAttributes"/> to the specified <see cref="XmlWriter"/>.
 /// </summary>
 /// <param name="source">A object that implements the <see cref="IAtomCommonObjectAttributes"/> interface to extract Atom common attribute 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(IAtomCommonObjectAttributes source, XmlWriter writer)
 {
     Guard.ArgumentNotNull(source, "source");
     Guard.ArgumentNotNull(writer, "writer");
     if (source.BaseUri != null)
     {
         writer.WriteAttributeString("xml", "base", XML_NAMESPACE, source.BaseUri.ToString());
     }
     if (source.Language != null)
     {
         writer.WriteAttributeString("xml", "lang", XML_NAMESPACE, source.Language.Name);
     }
 }
示例#5
0
        /// <summary>
        /// Saves the current <see cref="IAtomCommonObjectAttributes"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="source">A object that implements the <see cref="IAtomCommonObjectAttributes"/> interface to extract Atom common attribute 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(IAtomCommonObjectAttributes source, XmlWriter writer)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(writer, "writer");

            //------------------------------------------------------------
            //	Write xml:base attribute if necessary
            //------------------------------------------------------------
            if (source.BaseUri != null)
            {
                writer.WriteAttributeString("xml", "base", XML_NAMESPACE, source.BaseUri.ToString());
            }

            //------------------------------------------------------------
            //	Write xml:lang attribute if necessary
            //------------------------------------------------------------
            if (source.Language != null)
            {
                writer.WriteAttributeString("xml", "lang", XML_NAMESPACE, source.Language.Name);
            }
        }
示例#6
0
        /// <summary>
        /// Compares objects that implement the <see cref="IAtomCommonObjectAttributes"/> interface.
        /// </summary>
        /// <param name="source">A object that implements the <see cref="IAtomCommonObjectAttributes"/> interface to be compared.</param>
        /// <param name="target">A object that implements the <see cref="IAtomCommonObjectAttributes"/> 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 CompareCommonObjectAttributes(IAtomCommonObjectAttributes source, IAtomCommonObjectAttributes 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  = result | Uri.Compare(source.BaseUri, target.BaseUri, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase);

            string sourceLanguageName   = source.Language != null ? source.Language.Name : String.Empty;
            string targetLanguageName   = target.Language != null ? target.Language.Name : String.Empty;
            result                      = result | String.Compare(sourceLanguageName, targetLanguageName, StringComparison.OrdinalIgnoreCase);

            return result;
        }
示例#7
0
        /// <summary>
        /// Saves the current <see cref="IAtomCommonObjectAttributes"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="source">A object that implements the <see cref="IAtomCommonObjectAttributes"/> interface to extract Atom common attribute 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(IAtomCommonObjectAttributes source, XmlWriter writer)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(writer, "writer");

            //------------------------------------------------------------
            //	Write xml:base attribute if necessary
            //------------------------------------------------------------
            if (source.BaseUri != null)
            {
                writer.WriteAttributeString("xml", "base", XML_NAMESPACE, source.BaseUri.ToString());
            }

            //------------------------------------------------------------
            //	Write xml:lang attribute if necessary
            //------------------------------------------------------------
            if (source.Language != null)
            {
                writer.WriteAttributeString("xml", "lang", XML_NAMESPACE, source.Language.Name);
            }
        }
示例#8
0
        /// <summary>
        /// Modifies the <see cref="IAtomCommonObjectAttributes"/> to match the data source.
        /// </summary>
        /// <param name="target">The object that implements the <see cref="IAtomCommonObjectAttributes"/> interface to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract Atom common attribute information from.</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>
        public static bool FillCommonObjectAttributes(IAtomCommonObjectAttributes target, XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded  = false;

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

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

            //------------------------------------------------------------
            //	Attempt to extract xml:base attribute information
            //------------------------------------------------------------
            string xmlBaseAttribute = source.GetAttribute("base", manager.LookupNamespace("xml"));
            if (!String.IsNullOrEmpty(xmlBaseAttribute))
            {
                Uri baseUri;
                if (Uri.TryCreate(xmlBaseAttribute, UriKind.RelativeOrAbsolute, out baseUri))
                {
                    target.BaseUri  = baseUri;
                    wasLoaded       = true;
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract xml:lang attribute information
            //------------------------------------------------------------
            string xmlLangAttribute = source.GetAttribute("lang", manager.LookupNamespace("xml"));
            if (!String.IsNullOrEmpty(xmlLangAttribute))
            {
                try
                {
                    CultureInfo language    = new CultureInfo(source.XmlLang);
                    target.Language         = language;
                    wasLoaded               = true;
                }
                catch (ArgumentException)
                {
                    System.Diagnostics.Trace.TraceWarning("Unable to determine CultureInfo with a name of {0}.", source.XmlLang);
                }
            }

            return wasLoaded;
        }