예제 #1
0
        /// <summary>
        /// Modifies the <see cref="IExtensibleSyndicationObject"/> to match the data source.
        /// </summary>
        /// <param name="entity">The <see cref="IExtensibleSyndicationObject"/> to be filled.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve prefixed syndication elements and attributes.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="entity"/> 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 void Fill(IExtensibleSyndicationObject entity, XmlNamespaceManager manager)
        {
            Collection <ISyndicationExtension> extensions = new Collection <ISyndicationExtension>();

            Guard.ArgumentNotNull(entity, "entity");
            Guard.ArgumentNotNull(manager, "manager");

            if (this.Settings.AutoDetectExtensions)
            {
                extensions = SyndicationExtensionAdapter.GetExtensions(this.Settings.SupportedExtensions, (Dictionary <string, string>) this.Navigator.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml));
            }
            else
            {
                extensions = SyndicationExtensionAdapter.GetExtensions(this.Settings.SupportedExtensions);
            }

            foreach (ISyndicationExtension extension in extensions)
            {
                if (extension.ExistsInSource(this.Navigator) && extension.GetType() != entity.GetType())
                {
                    ISyndicationExtension instance = (ISyndicationExtension)Activator.CreateInstance(extension.GetType());

                    if (instance.Load(this.Navigator))
                    {
                        ((Collection <ISyndicationExtension>)entity.Extensions).Add(instance);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Creates a collection of <see cref="ISyndicationExtension"/> instances for the specified types.
        /// </summary>
        /// <param name="types">A <see cref="Collection{T}"/> collection of <see cref="Type"/> objects that represent user-defined syndication extensions to be instantiated.</param>
        /// <param name="namespaces">A collection of XML nameapces that are used to filter the available native framework syndication extensions.</param>
        /// <returns>
        ///     A <see cref="Collection{T}"/> collection of <see cref="ISyndicationExtension"/> objects instantiated using the supplied <paramref name="types"/> and <paramref name="manager"/>.
        /// </returns>
        /// <remarks>
        ///     This method instantiates all of the available native framework syndication extensions, and then filters them based on the XML namespaces and prefixes contained in the supplied <paramref name="namespaces"/>.
        ///     The user defined syndication extensions are then instantiated, and are added to the return collection if they do not already exist.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="types"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="namespaces"/> is a null reference (Nothing in Visual Basic).</exception>
        public static Collection <ISyndicationExtension> GetExtensions(Collection <Type> types, Dictionary <string, string> namespaces)
        {
            Collection <ISyndicationExtension> supportedExtensions = new Collection <ISyndicationExtension>();

            Guard.ArgumentNotNull(types, "types");
            Guard.ArgumentNotNull(namespaces, "namespaces");

            Collection <ISyndicationExtension> nativeExtensions = SyndicationExtensionAdapter.GetExtensions(SyndicationExtensionAdapter.FrameworkExtensions);

            foreach (ISyndicationExtension extension in nativeExtensions)
            {
                if (namespaces.ContainsValue(extension.XmlNamespace) || namespaces.ContainsKey(extension.XmlPrefix))
                {
                    if (!supportedExtensions.Contains(extension))
                    {
                        supportedExtensions.Add(extension);
                    }
                }
            }

            Collection <ISyndicationExtension> userExtensions = SyndicationExtensionAdapter.GetExtensions(types);

            foreach (ISyndicationExtension extension in userExtensions)
            {
                if (!supportedExtensions.Contains(extension))
                {
                    supportedExtensions.Add(extension);
                }
            }

            return(supportedExtensions);
        }
예제 #3
0
        /// <summary>
        /// Creates a collection of <see cref="ISyndicationExtension"/> instances for the specified types.
        /// </summary>
        /// <param name="types">A <see cref="Collection{T}"/> collection of <see cref="Type"/> objects that represent user-defined syndication extensions to be instantiated.</param>
        /// <param name="namespaces">A collection of XML nameapces that are used to filter the available native framework syndication extensions.</param>
        /// <returns>
        ///     A <see cref="Collection{T}"/> collection of <see cref="ISyndicationExtension"/> objects instantiated using the supplied <paramref name="types"/> and <paramref name="manager"/>.
        /// </returns>
        /// <remarks>
        ///     This method instantiates all of the available native framework syndication extensions, and then filters them based on the XML namespaces and prefixes contained in the supplied <paramref name="namespaces"/>.
        ///     The user defined syndication extensions are then instantiated, and are added to the return collection if they do not already exist.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="types"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="namespaces"/> is a null reference (Nothing in Visual Basic).</exception>
        public static Collection <ISyndicationExtension> GetExtensions(Collection <Type> types, Dictionary <string, string> namespaces)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            Collection <ISyndicationExtension> supportedExtensions = new Collection <ISyndicationExtension>();

            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(types, "types");
            Guard.ArgumentNotNull(namespaces, "namespaces");

            //------------------------------------------------------------
            //	Add native framework extensions based on XML namespaces
            //------------------------------------------------------------
            Collection <ISyndicationExtension> nativeExtensions = SyndicationExtensionAdapter.GetExtensions(SyndicationExtensionAdapter.FrameworkExtensions);

            foreach (ISyndicationExtension extension in nativeExtensions)
            {
                if (namespaces.ContainsValue(extension.XmlNamespace) || namespaces.ContainsKey(extension.XmlPrefix))
                {
                    if (!supportedExtensions.Contains(extension))
                    {
                        supportedExtensions.Add(extension);
                    }
                }
            }

            //------------------------------------------------------------
            //	Add user defined extensions if not already in collection
            //------------------------------------------------------------
            Collection <ISyndicationExtension> userExtensions = SyndicationExtensionAdapter.GetExtensions(types);

            foreach (ISyndicationExtension extension in userExtensions)
            {
                if (!supportedExtensions.Contains(extension))
                {
                    supportedExtensions.Add(extension);
                }
            }

            return(supportedExtensions);
        }
예제 #4
0
        /// <summary>
        /// Modifies the <see cref="IExtensibleSyndicationObject"/> to match the data source.
        /// </summary>
        /// <param name="entity">The <see cref="IExtensibleSyndicationObject"/> to be filled.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve prefixed syndication elements and attributes.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="entity"/> 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 void Fill(IExtensibleSyndicationObject entity, XmlNamespaceManager manager)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            Collection <ISyndicationExtension> extensions = new Collection <ISyndicationExtension>();

            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(entity, "entity");
            Guard.ArgumentNotNull(manager, "manager");

            //------------------------------------------------------------
            //	Get syndication extensions supported by the load operation
            //------------------------------------------------------------
            if (this.Settings.AutoDetectExtensions)
            {
                extensions = SyndicationExtensionAdapter.GetExtensions(this.Settings.SupportedExtensions, (Dictionary <string, string>) this.Navigator.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml));
            }
            else
            {
                extensions = SyndicationExtensionAdapter.GetExtensions(this.Settings.SupportedExtensions);
            }

            //------------------------------------------------------------
            //	Add syndication extensions to entity if they exist in source
            //------------------------------------------------------------
            foreach (ISyndicationExtension extension in extensions)
            {
                if (extension.ExistsInSource(this.Navigator) && extension.GetType() != entity.GetType())
                {
                    ISyndicationExtension instance = (ISyndicationExtension)Activator.CreateInstance(extension.GetType());

                    if (instance.Load(this.Navigator))
                    {
                        ((Collection <ISyndicationExtension>)entity.Extensions).Add(instance);
                    }
                }
            }
        }