/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Really Simple Discovery (RSD) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillRsdResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); //------------------------------------------------------------ // Fill syndication resource using appropriate data adapter //------------------------------------------------------------ RsdDocument rsdDocument = resource as RsdDocument; if (resourceMetadata.Version == new Version("1.0")) { Rsd10SyndicationResourceAdapter rsd10Adapter = new Rsd10SyndicationResourceAdapter(this.Navigator, this.Settings); rsd10Adapter.Fill(rsdDocument); } if (resourceMetadata.Version == new Version("0.6")) { Rsd06SyndicationResourceAdapter rsd06Adapter = new Rsd06SyndicationResourceAdapter(this.Navigator, this.Settings); rsd06Adapter.Fill(rsdDocument); } }
/// <summary> /// Provides example code for the Load(XmlReader) method /// </summary> public static void LoadXmlReaderExample() { #region Load(XmlReader reader) RsdDocument document = new RsdDocument(); using (Stream stream = new FileStream("RsdDocument.xml", FileMode.Open, FileAccess.Read)) { XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; settings.IgnoreWhitespace = true; using (XmlReader reader = XmlReader.Create(stream, settings)) { document.Load(reader); foreach (RsdApplicationInterface api in document.Interfaces) { if (api.IsPreferred) { // Perform some processing on the application programming interface break; } } } } #endregion }
/// <summary> /// Provides example code for the LoadAsync(Uri, Object) method /// </summary> public static void LoadAsyncExample() { RsdDocument document = new RsdDocument(); document.Loaded += new EventHandler <SyndicationResourceLoadedEventArgs>(ResourceLoadedCallback); document.LoadAsync(new Uri("http://blog.oppositionallydefiant.com/rsd.axd"), null); }
/// <summary> /// Provides example code for the Save(Stream) method /// </summary> public static void SaveStreamExample() { RsdDocument document = new RsdDocument(); // Modify document state using public properties and methods using (Stream stream = new FileStream("RsdDocument.xml", FileMode.Create, FileAccess.Write)) { document.Save(stream); } }
//============================================================ // ASYNC METHODS //============================================================ /// <summary> /// Provides example code for the LoadAsync(Uri, Object) method /// </summary> public static void LoadAsyncExample() { #region LoadAsync(Uri source, Object userToken) //------------------------------------------------------------ // Load resource asynchronously using event-based notification //------------------------------------------------------------ RsdDocument document = new RsdDocument(); document.Loaded += new EventHandler <SyndicationResourceLoadedEventArgs>(ResourceLoadedCallback); document.LoadAsync(new Uri("http://blog.oppositionallydefiant.com/rsd.axd"), null); #endregion }
/// <summary> /// Provides example code for the RsdDocument.Create(Uri) method /// </summary> public static void CreateExample() { RsdDocument document = RsdDocument.Create(new Uri("http://blog.oppositionallydefiant.com/rsd.axd")); foreach (RsdApplicationInterface api in document.Interfaces) { if (api.IsPreferred) { // Perform some processing on the application programming interface break; } } }
/// <summary> /// Provides example code for the Load(Uri, ICredentials, IWebProxy) method /// </summary> public static void LoadUriExample() { RsdDocument document = new RsdDocument(); Uri source = new Uri("http://blog.oppositionallydefiant.com/rsd.axd"); document.Load(source, CredentialCache.DefaultNetworkCredentials, null); foreach (RsdApplicationInterface api in document.Interfaces) { if (api.IsPreferred) { // Perform some processing on the application programming interface break; } } }
/// <summary> /// Provides example code for the Load(IXPathNavigable) method /// </summary> public static void LoadIXPathNavigableExample() { XPathDocument source = new XPathDocument("http://blog.oppositionallydefiant.com/rsd.axd"); RsdDocument document = new RsdDocument(); document.Load(source); foreach (RsdApplicationInterface api in document.Interfaces) { if (api.IsPreferred) { // Perform some processing on the application programming interface break; } } }
/// <summary> /// Provides example code for the Save(XmlWriter) method /// </summary> public static void SaveXmlWriterExample() { RsdDocument document = new RsdDocument(); // Modify document state using public properties and methods using (Stream stream = new FileStream("RsdDocument.xml", FileMode.Create, FileAccess.Write)) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create(stream, settings)) { document.Save(writer); } } }
/// <summary> /// Provides example code for the Load(Stream) method /// </summary> public static void LoadStreamExample() { RsdDocument document = new RsdDocument(); using (Stream stream = new FileStream("RsdDocument.xml", FileMode.Open, FileAccess.Read)) { document.Load(stream); foreach (RsdApplicationInterface api in document.Interfaces) { if (api.IsPreferred) { // Perform some processing on the application programming interface break; } } } }
/// <summary> /// Modifies the <see cref="ISyndicationResource"/> to match the data source. /// </summary> /// <param name="resource">The Really Simple Discovery (RSD) <see cref="ISyndicationResource"/> to be filled.</param> /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception> private void FillRsdResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata) { Guard.ArgumentNotNull(resource, "resource"); Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata"); RsdDocument rsdDocument = resource as RsdDocument; if (resourceMetadata.Version == new Version("1.0")) { Rsd10SyndicationResourceAdapter rsd10Adapter = new Rsd10SyndicationResourceAdapter(this.Navigator, this.Settings); rsd10Adapter.Fill(rsdDocument); } if (resourceMetadata.Version == new Version("0.6")) { Rsd06SyndicationResourceAdapter rsd06Adapter = new Rsd06SyndicationResourceAdapter(this.Navigator, this.Settings); rsd06Adapter.Fill(rsdDocument); } }
/// <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); }
/// <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) { Guard.ArgumentNotNull(stream, "stream"); 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); } }
//============================================================ // 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); }