Exemplo n.º 1
0
        /// <summary>
        /// Returns the type vocabulary identifier for the supplied <see cref="DublinCoreTypeVocabularies"/>.
        /// </summary>
        /// <param name="vocabulary">The <see cref="DublinCoreTypeVocabularies"/> to get the type vocabulary identifier for.</param>
        /// <returns>The type vocabulary identifier for the supplied <paramref name="vocabulary"/>, otherwise returns an empty string.</returns>
        public static string TypeVocabularyAsString(DublinCoreTypeVocabularies vocabulary)
        {
            string name = String.Empty;

            foreach (System.Reflection.FieldInfo fieldInfo in typeof(DublinCoreTypeVocabularies).GetFields())
            {
                if (fieldInfo.FieldType == typeof(DublinCoreTypeVocabularies))
                {
                    DublinCoreTypeVocabularies typeVocabulary = (DublinCoreTypeVocabularies)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);

                    if (typeVocabulary == vocabulary)
                    {
                        object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                        if (customAttributes != null && customAttributes.Length > 0)
                        {
                            EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                            name = enumerationMetadata.AlternateValue;
                            break;
                        }
                    }
                }
            }

            return(name);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the <see cref="DublinCoreTypeVocabularies"/> enumeration value that corresponds to the specified type vocabulary name.
        /// </summary>
        /// <param name="name">The name of the type vocabulary.</param>
        /// <returns>A <see cref="DublinCoreTypeVocabularies"/> enumeration value that corresponds to the specified string, otherwise returns <b>DublinCoreTypeVocabularies.None</b>.</returns>
        /// <remarks>This method disregards case of specified type vocabulary name.</remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="name"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="name"/> is an empty string.</exception>
        public static DublinCoreTypeVocabularies TypeVocabularyByName(string name)
        {
            DublinCoreTypeVocabularies typeVocabulary = DublinCoreTypeVocabularies.None;

            Guard.ArgumentNotNullOrEmptyString(name, "name");
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(DublinCoreTypeVocabularies).GetFields())
            {
                if (fieldInfo.FieldType == typeof(DublinCoreTypeVocabularies))
                {
                    DublinCoreTypeVocabularies vocabulary = (DublinCoreTypeVocabularies)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);
                    object[] customAttributes             = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                    if (customAttributes != null && customAttributes.Length > 0)
                    {
                        EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                        if (String.Compare(name, enumerationMetadata.AlternateValue, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            typeVocabulary = vocabulary;
                            break;
                        }
                    }
                }
            }

            return(typeVocabulary);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes the syndication extension context optional elements using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="DublinCoreElementSetSyndicationExtensionContext"/>.</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="DublinCoreElementSetSyndicationExtensionContext"/> 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>
        private bool LoadOptionals(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
            //------------------------------------------------------------
            XPathNavigator coverageNavigator   = source.SelectSingleNode("dc:coverage", manager);
            XPathNavigator formatNavigator     = source.SelectSingleNode("dc:format", manager);
            XPathNavigator identifierNavigator = source.SelectSingleNode("dc:identifier", manager);
            XPathNavigator relationNavigator   = source.SelectSingleNode("dc:relation", manager);
            XPathNavigator sourceNavigator     = source.SelectSingleNode("dc:source", manager);
            XPathNavigator subjectNavigator    = source.SelectSingleNode("dc:subject", manager);
            XPathNavigator typeNavigator       = source.SelectSingleNode("dc:type", manager);

            if (coverageNavigator != null && !String.IsNullOrEmpty(coverageNavigator.Value))
            {
                this.Coverage = coverageNavigator.Value;
                wasLoaded     = true;
            }

            if (formatNavigator != null && !String.IsNullOrEmpty(formatNavigator.Value))
            {
                this.Format = formatNavigator.Value;
                wasLoaded   = true;
            }

            if (identifierNavigator != null && !String.IsNullOrEmpty(identifierNavigator.Value))
            {
                this.Identifier = identifierNavigator.Value;
                wasLoaded       = true;
            }

            if (relationNavigator != null && !String.IsNullOrEmpty(relationNavigator.Value))
            {
                this.Relation = relationNavigator.Value;
                wasLoaded     = true;
            }

            if (sourceNavigator != null && !String.IsNullOrEmpty(sourceNavigator.Value))
            {
                this.Source = sourceNavigator.Value;
                wasLoaded   = true;
            }

            if (subjectNavigator != null && !String.IsNullOrEmpty(subjectNavigator.Value))
            {
                this.Subject = subjectNavigator.Value;
                wasLoaded    = true;
            }

            if (typeNavigator != null && !String.IsNullOrEmpty(typeNavigator.Value))
            {
                DublinCoreTypeVocabularies typeVocabulary = DublinCoreElementSetSyndicationExtension.TypeVocabularyByName(typeNavigator.Value);
                if (typeVocabulary != DublinCoreTypeVocabularies.None)
                {
                    this.TypeVocabulary = typeVocabulary;
                    wasLoaded           = true;
                }
            }

            return(wasLoaded);
        }
        /// <summary>
        /// Initializes the syndication extension context optional elements using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="DublinCoreElementSetSyndicationExtensionContext"/>.</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="DublinCoreElementSetSyndicationExtensionContext"/> 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>
        private bool LoadOptionals(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
            //------------------------------------------------------------
            XPathNavigator coverageNavigator    = source.SelectSingleNode("dc:coverage", manager);
            XPathNavigator formatNavigator      = source.SelectSingleNode("dc:format", manager);
            XPathNavigator identifierNavigator  = source.SelectSingleNode("dc:identifier", manager);
            XPathNavigator relationNavigator    = source.SelectSingleNode("dc:relation", manager);
            XPathNavigator sourceNavigator      = source.SelectSingleNode("dc:source", manager);
            XPathNavigator subjectNavigator     = source.SelectSingleNode("dc:subject", manager);
            XPathNavigator typeNavigator        = source.SelectSingleNode("dc:type", manager);

            if (coverageNavigator != null && !String.IsNullOrEmpty(coverageNavigator.Value))
            {
                this.Coverage   = coverageNavigator.Value;
                wasLoaded       = true;
            }

            if (formatNavigator != null && !String.IsNullOrEmpty(formatNavigator.Value))
            {
                this.Format = formatNavigator.Value;
                wasLoaded   = true;
            }

            if (identifierNavigator != null && !String.IsNullOrEmpty(identifierNavigator.Value))
            {
                this.Identifier = identifierNavigator.Value;
                wasLoaded       = true;
            }

            if (relationNavigator != null && !String.IsNullOrEmpty(relationNavigator.Value))
            {
                this.Relation   = relationNavigator.Value;
                wasLoaded       = true;
            }

            if (sourceNavigator != null && !String.IsNullOrEmpty(sourceNavigator.Value))
            {
                this.Source = sourceNavigator.Value;
                wasLoaded   = true;
            }

            if (subjectNavigator != null && !String.IsNullOrEmpty(subjectNavigator.Value))
            {
                this.Subject    = subjectNavigator.Value;
                wasLoaded       = true;
            }

            if (typeNavigator != null && !String.IsNullOrEmpty(typeNavigator.Value))
            {
                DublinCoreTypeVocabularies typeVocabulary   = DublinCoreElementSetSyndicationExtension.TypeVocabularyByName(typeNavigator.Value);
                if (typeVocabulary != DublinCoreTypeVocabularies.None)
                {
                    this.TypeVocabulary = typeVocabulary;
                    wasLoaded           = true;
                }
            }

            return wasLoaded;
        }
        /// <summary>
        /// Returns the type vocabulary identifier for the supplied <see cref="DublinCoreTypeVocabularies"/>.
        /// </summary>
        /// <param name="vocabulary">The <see cref="DublinCoreTypeVocabularies"/> to get the type vocabulary identifier for.</param>
        /// <returns>The type vocabulary identifier for the supplied <paramref name="vocabulary"/>, otherwise returns an empty string.</returns>
        public static string TypeVocabularyAsString(DublinCoreTypeVocabularies vocabulary)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string name = String.Empty;

            //------------------------------------------------------------
            //	Return alternate value based on supplied protocol
            //------------------------------------------------------------
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(DublinCoreTypeVocabularies).GetFields())
            {
                if (fieldInfo.FieldType == typeof(DublinCoreTypeVocabularies))
                {
                    DublinCoreTypeVocabularies typeVocabulary = (DublinCoreTypeVocabularies)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);

                    if (typeVocabulary == vocabulary)
                    {
                        object[] customAttributes   = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                        if (customAttributes != null && customAttributes.Length > 0)
                        {
                            EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                            name    = enumerationMetadata.AlternateValue;
                            break;
                        }
                    }
                }
            }

            return name;
        }