コード例 #1
0
        /// <summary>
        /// Provides example code for the RsdDocument class.
        /// </summary>
        public static void ClassExample()
        {
            RsdDocument document = new RsdDocument();

            document.EngineName = "Blog Munging CMS";
            document.EngineLink = new Uri("http://www.blogmunging.com/");
            document.Homepage   = new Uri("http://www.userdomain.com/");

            document.AddInterface(new RsdApplicationInterface("MetaWeblog", new Uri("http://example.com/xml/rpc/url"), true, "123abc"));
            document.AddInterface(new RsdApplicationInterface("Blogger", new Uri("http://example.com/xml/rpc/url"), false, "123abc"));
            document.AddInterface(new RsdApplicationInterface("MetaWiki", new Uri("http://example.com/some/other/url"), false, "123abc"));
            document.AddInterface(new RsdApplicationInterface("Antville", new Uri("http://example.com/yet/another/url"), false, "123abc"));

            RsdApplicationInterface conversantApi = new RsdApplicationInterface("Conversant", new Uri("http://example.com/xml/rpc/url"), false, String.Empty);

            conversantApi.Documentation = new Uri("http://www.conversant.com/docs/api/");
            conversantApi.Notes         = "Additional explanation here.";
            conversantApi.Settings.Add("service-specific-setting", "a value");
            conversantApi.Settings.Add("another-setting", "another value");
            document.AddInterface(conversantApi);
        }
コード例 #2
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Fill(RsdDocument resource)
        /// <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);
        }