/// <summary>
        /// Returns the <see cref="SiteSummaryUpdatePeriod"/> enumeration value that corresponds to the specified period name.
        /// </summary>
        /// <param name="name">The name of the period.</param>
        /// <returns>A <see cref="SiteSummaryUpdatePeriod"/> enumeration value that corresponds to the specified string, otherwise returns <b>SiteSummaryUpdatePeriod.None</b>.</returns>
        /// <remarks>This method disregards case of specified period 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 SiteSummaryUpdatePeriod PeriodByName(string name)
        {
            SiteSummaryUpdatePeriod updatePeriod = SiteSummaryUpdatePeriod.None;

            Guard.ArgumentNotNullOrEmptyString(name, "name");
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(SiteSummaryUpdatePeriod).GetFields())
            {
                if (fieldInfo.FieldType == typeof(SiteSummaryUpdatePeriod))
                {
                    SiteSummaryUpdatePeriod period = (SiteSummaryUpdatePeriod)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)
                        {
                            updatePeriod = period;
                            break;
                        }
                    }
                }
            }

            return(updatePeriod);
        }
Exemple #2
0
        /// <summary>
        /// Returns the period identifier for the supplied <see cref="SiteSummaryUpdatePeriod"/>.
        /// </summary>
        /// <param name="period">The <see cref="SiteSummaryUpdatePeriod"/> to get the period identifier for.</param>
        /// <returns>The period identifier for the supplied <paramref name="vocabulary"/>, otherwise returns an empty string.</returns>
        public static string PeriodAsString(SiteSummaryUpdatePeriod period)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string name = String.Empty;

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

                    if (updatePeriod == period)
                    {
                        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);
        }
Exemple #3
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source, XmlNamespaceManager manager)
        /// <summary>
        /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="SiteSummaryUpdateSyndicationExtensionContext"/>.</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="SiteSummaryUpdateSyndicationExtensionContext"/> 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>
        public bool Load(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
            //------------------------------------------------------------
            if (source.HasChildren)
            {
                XPathNavigator updatePeriodNavigator    = source.SelectSingleNode("sy:updatePeriod", manager);
                XPathNavigator updateFrequencyNavigator = source.SelectSingleNode("sy:updateFrequency", manager);
                XPathNavigator updateBaseNavigator      = source.SelectSingleNode("sy:updateBase", manager);

                if (updatePeriodNavigator != null && !String.IsNullOrEmpty(updatePeriodNavigator.Value))
                {
                    SiteSummaryUpdatePeriod period = SiteSummaryUpdateSyndicationExtension.PeriodByName(updatePeriodNavigator.Value);
                    if (period != SiteSummaryUpdatePeriod.None)
                    {
                        this.Period = period;
                        wasLoaded   = true;
                    }
                }

                if (updateFrequencyNavigator != null)
                {
                    int frequency;
                    if (Int32.TryParse(updateFrequencyNavigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out frequency))
                    {
                        this.Frequency = frequency;
                        wasLoaded      = true;
                    }
                }

                if (updateBaseNavigator != null)
                {
                    DateTime updateBase;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updateBaseNavigator.Value, out updateBase))
                    {
                        this.Base = updateBase;
                        wasLoaded = true;
                    }
                }
            }

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

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

                    if (updatePeriod == period)
                    {
                        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;
        }