コード例 #1
0
        /// <summary>
        /// Modifies the <see cref="RsdDocument"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="RsdDocument"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(RsdDocument resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager     = RsdUtility.CreateNamespaceManager(this.Navigator.NameTable);

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator serviceNavigator = RsdUtility.SelectSafeSingleNode(this.Navigator, "rsd:rsd/rsd:service", manager);

            if (serviceNavigator == null)
            {
                //  dasBlog places an empty default XML namespace on the <service> element, this is a hack/compromise
                serviceNavigator    = RsdUtility.SelectSafeSingleNode(this.Navigator, "rsd:rsd/service", manager);
            }

            if (serviceNavigator != null)
            {
                XPathNavigator engineNameNavigator      = RsdUtility.SelectSafeSingleNode(serviceNavigator, "rsd:engineName", manager);
                XPathNavigator engineLinkNavigator      = RsdUtility.SelectSafeSingleNode(serviceNavigator, "rsd:engineLink", manager);
                XPathNavigator homePageLinkNavigator    = RsdUtility.SelectSafeSingleNode(serviceNavigator, "rsd:homePageLink", manager);
                XPathNodeIterator apiIterator           = RsdUtility.SelectSafe(serviceNavigator, "rsd:apis/rsd:api", manager);

                if (engineNameNavigator != null && !String.IsNullOrEmpty(engineNameNavigator.Value))
                {
                    resource.EngineName     = engineNameNavigator.Value;
                }

                if (engineLinkNavigator != null)
                {
                    Uri link;
                    if (Uri.TryCreate(engineLinkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                    {
                        resource.EngineLink = link;
                    }
                }

                if (homePageLinkNavigator != null)
                {
                    Uri homepage;
                    if (Uri.TryCreate(homePageLinkNavigator.Value, UriKind.RelativeOrAbsolute, out homepage))
                    {
                        resource.Homepage   = homepage;
                    }
                }

                if (apiIterator != null && apiIterator.Count > 0)
                {
                    int counter = 0;
                    while (apiIterator.MoveNext())
                    {
                        RsdApplicationInterface api = new RsdApplicationInterface();
                        counter++;

                        Uri link;
                        string rpcLinkAttribute = apiIterator.Current.GetAttribute("rpcLink", String.Empty);
                        if (Uri.TryCreate(rpcLinkAttribute, UriKind.RelativeOrAbsolute, out link))
                        {
                            api.Link    = link;
                        }

                        if (api.Load(apiIterator.Current, this.Settings) || api.Link != null)
                        {
                            if (this.Settings.RetrievalLimit != 0 && counter > this.Settings.RetrievalLimit)
                            {
                                break;
                            }

                            ((Collection<RsdApplicationInterface>)resource.Interfaces).Add(api);
                        }
                    }
                }
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(RsdUtility.SelectSafeSingleNode(this.Navigator, "rsd:rsd", manager), this.Settings);
            adapter.Fill(resource, manager);
        }
コード例 #2
0
ファイル: RsdDocument.cs プロジェクト: Jiyuu/Argotic
        /// <summary>
        /// Creates a new <see cref="RsdDocument"/> instance using the specified <see cref="Uri"/>, <see cref="ICredentials"/>, <see cref="IWebProxy"/>, and <see cref="SyndicationResourceLoadSettings"/> object.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="RsdDocument"/> instance. This value can be <b>null</b>.</param>
        /// <returns>An <see cref="RsdDocument"/> object loaded using the <paramref name="source"/> data.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the document remains empty.</exception>
        public static RsdDocument Create(Uri source, WebRequestOptions options, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            RsdDocument syndicationResource = new RsdDocument();

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

            //------------------------------------------------------------
            //	Create new instance using supplied parameters
            //------------------------------------------------------------
            syndicationResource.Load(source, options, settings);

            return syndicationResource;
        }
コード例 #3
0
        /// <summary>
        /// Instantiates a <see cref="ISyndicationResource"/> that conforms to the specified <see cref="SyndicationContentFormat"/> using the supplied <see cref="Stream"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> used to load the syndication resource.</param>
        /// <param name="format">A <see cref="SyndicationContentFormat"/> enumeration value that indicates the type syndication resource the <paramref name="stream"/> represents.</param>
        /// <returns>
        ///     An <see cref="ISyndicationResource"/> object that conforms to the specified <paramref name="format"/>, initialized using the supplied <paramref name="stream"/>. 
        ///     If the <paramref name="format"/> is not supported by the provider, returns a <b>null</b> reference.
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception>
        private static ISyndicationResource BuildResource(SyndicationContentFormat format, Stream stream)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(stream, "stream");

            //------------------------------------------------------------
            //	Create syndication resource based on content format
            //------------------------------------------------------------
            if (format == SyndicationContentFormat.Apml)
            {
                ApmlDocument document   = new ApmlDocument();
                document.Load(stream);
                return document;
            }
            else if (format == SyndicationContentFormat.Atom)
            {
                XPathDocument document      = new XPathDocument(stream);
                XPathNavigator navigator    = document.CreateNavigator();
                navigator.MoveToRoot();
                navigator.MoveToChild(XPathNodeType.Element);

                if(String.Compare(navigator.LocalName, "entry", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AtomEntry entry     = new AtomEntry();
                    entry.Load(navigator);
                    return entry;
                }
                else if (String.Compare(navigator.LocalName, "feed", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AtomFeed feed       = new AtomFeed();
                    feed.Load(navigator);
                    return feed;
                }
                else
                {
                    return null;
                }
            }
            else if (format == SyndicationContentFormat.BlogML)
            {
                BlogMLDocument document = new BlogMLDocument();
                document.Load(stream);
                return document;
            }
            else if (format == SyndicationContentFormat.Opml)
            {
                OpmlDocument document   = new OpmlDocument();
                document.Load(stream);
                return document;
            }
            else if (format == SyndicationContentFormat.Rsd)
            {
                RsdDocument document    = new RsdDocument();
                document.Load(stream);
                return document;
            }
            else if (format == SyndicationContentFormat.Rss)
            {
                RssFeed feed            = new RssFeed();
                feed.Load(stream);
                return feed;
            }
            else
            {
                return null;
            }
        }