//============================================================ // STATIC METHODS //============================================================ #region CloudProtocolAsString(RssCloudProtocol protocol) /// <summary> /// Returns the cloud protocol identifier for the supplied <see cref="RssCloudProtocol"/>. /// </summary> /// <param name="protocol">The <see cref="RssCloudProtocol"/> to get the cloud protocol identifier for.</param> /// <returns>The cloud protocol identifier for the supplied <paramref name="protocol"/>, otherwise returns an empty string.</returns> /// <example> /// <code lang="cs" title="The following code example demonstrates the usage of the CloudProtocolAsString method."> /// <code /// source="..\..\Documentation\Microsoft .NET 2.0\CodeExamplesLibrary\Core\Rss\RssCloudExample.cs" /// region="CloudProtocolAsString(RssCloudProtocol protocol)" /// /> /// </code> /// </example> public static string CloudProtocolAsString(RssCloudProtocol protocol) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ string name = String.Empty; //------------------------------------------------------------ // Return alternate value based on supplied protocol //------------------------------------------------------------ foreach (System.Reflection.FieldInfo fieldInfo in typeof(RssCloudProtocol).GetFields()) { if (fieldInfo.FieldType == typeof(RssCloudProtocol)) { RssCloudProtocol cloudProtocol = (RssCloudProtocol)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); if (cloudProtocol == protocol) { 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); }
/// <summary> /// Returns the <see cref="RssCloudProtocol"/> enumeration value that corresponds to the specified protocol name. /// </summary> /// <param name="name">The name of the cloud protocol.</param> /// <returns>A <see cref="RssCloudProtocol"/> enumeration value that corresponds to the specified string, otherwise returns <b>RssCloudProtocol.None</b>.</returns> /// <remarks>This method disregards case of specified protocol 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> /// <example> /// <code lang="cs" title="The following code example demonstrates the usage of the CloudProtocolByName method."> /// <code /// source="..\..\Documentation\Microsoft .NET 3.5\CodeExamplesLibrary\Core\Rss\RssCloudExample.cs" /// region="CloudProtocolByName(string name)" /// /> /// </code> /// </example> public static RssCloudProtocol CloudProtocolByName(string name) { RssCloudProtocol cloudProtocol = RssCloudProtocol.None; Guard.ArgumentNotNullOrEmptyString(name, "name"); foreach (System.Reflection.FieldInfo fieldInfo in typeof(RssCloudProtocol).GetFields()) { if (fieldInfo.FieldType == typeof(RssCloudProtocol)) { RssCloudProtocol protocol = (RssCloudProtocol)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) { cloudProtocol = protocol; break; } } } } return(cloudProtocol); }
/// <summary> /// Initializes the supplied <see cref="RssCloud"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>. /// </summary> /// <param name="cloud">The <see cref="RssCloud"/> to be filled.</param> /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the cloud XML data.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation of the <see cref="RssFeed"/>.</param> /// <exception cref="ArgumentNullException">The <paramref name="cloud"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> 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> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillCloud(RssCloud cloud, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(cloud, "cloud"); Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract category information //------------------------------------------------------------ if (navigator.HasAttributes) { string domainAttribute = navigator.GetAttribute("domain", String.Empty); string portAttribute = navigator.GetAttribute("port", String.Empty); string pathAttribute = navigator.GetAttribute("path", String.Empty); string registerProcedureAttribute = navigator.GetAttribute("registerProcedure", String.Empty); string protocolAttribute = navigator.GetAttribute("protocol", String.Empty); if (!String.IsNullOrEmpty(domainAttribute)) { cloud.Domain = domainAttribute; } if (!String.IsNullOrEmpty(portAttribute)) { int port; if (Int32.TryParse(portAttribute, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out port)) { cloud.Port = port; } } if (!String.IsNullOrEmpty(pathAttribute)) { cloud.Path = pathAttribute; } if (!String.IsNullOrEmpty(registerProcedureAttribute)) { cloud.RegisterProcedure = registerProcedureAttribute; } if (!String.IsNullOrEmpty(protocolAttribute)) { RssCloudProtocol protocol = RssCloud.CloudProtocolByName(protocolAttribute); if (protocol != RssCloudProtocol.None) { cloud.Protocol = protocol; } } } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings); adapter.Fill(cloud); }
/// <summary> /// Provides example code for the RssCloud.CloudProtocolByName(string) method /// </summary> public static void ProtocolByNameExample() { RssCloudProtocol protocol = RssCloud.CloudProtocolByName("xml-rpc"); if (protocol == RssCloudProtocol.XmlRpc) { } }
/// <summary> /// Initializes a new instance of the <see cref="RssCloud"/> class using the supplied domain, path, port, protocol and procedure name. /// </summary> /// <param name="domain">The host name or IP address of the web service that monitors updates to a feed.</param> /// <param name="path">The path of the web service that monitors updates to a feed.</param> /// <param name="port">The TCP port of the web service that monitors updates to a feed.</param> /// <param name="protocol"> An <see cref="RssCloudProtocol"/> enumeration value that represents the message format utilized by the web service that monitors updates to a feed.</param> /// <param name="registerProcedure">The name of the remote procedure to call when requesting notification of feed updates.</param> /// <exception cref="ArgumentNullException">The <paramref name="domain"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="domain"/> is an empty string.</exception> /// <exception cref="ArgumentNullException">The <paramref name="path"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="path"/> is an empty string.</exception> /// <exception cref="ArgumentOutOfRangeException">The <paramref name="port"/> is less than <i>zero</i>.</exception> /// <exception cref="ArgumentException">The <paramref name="protocol"/> is equal to <see cref="RssCloudProtocol.None"/>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="registerProcedure"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="registerProcedure"/> is an empty string.</exception> public RssCloud(string domain, string path, int port, RssCloudProtocol protocol, string registerProcedure) { this.Domain = domain; this.Path = path; this.Port = port; this.Protocol = protocol; this.RegisterProcedure = registerProcedure; }
/// <summary> /// Loads this <see cref="RssCloud"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="RssCloud"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="RssCloud"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); if (source.HasAttributes) { string domain = source.GetAttribute("domain", String.Empty); string path = source.GetAttribute("path", String.Empty); string port = source.GetAttribute("port", String.Empty); string protocol = source.GetAttribute("protocol", String.Empty); string registerProcedure = source.GetAttribute("registerProcedure", String.Empty); if (!String.IsNullOrEmpty(domain)) { this.Domain = domain; wasLoaded = true; } if (!String.IsNullOrEmpty(path)) { this.Path = path; wasLoaded = true; } if (!String.IsNullOrEmpty(port)) { int tcpPort; if (Int32.TryParse(port, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out tcpPort)) { if (tcpPort > 0) { this.Port = tcpPort; wasLoaded = true; } } } if (!String.IsNullOrEmpty(protocol)) { RssCloudProtocol serviceProtocol = RssCloud.CloudProtocolByName(protocol); if (serviceProtocol != RssCloudProtocol.None) { this.Protocol = serviceProtocol; wasLoaded = true; } } if (!String.IsNullOrEmpty(registerProcedure)) { this.RegisterProcedure = registerProcedure; wasLoaded = true; } } return(wasLoaded); }
/// <summary> /// Provides example code for the RssCloud.CloudProtocolByName(string) method /// </summary> public static void ProtocolByNameExample() { #region CloudProtocolByName(string name) RssCloudProtocol protocol = RssCloud.CloudProtocolByName("xml-rpc"); if (protocol == RssCloudProtocol.XmlRpc) { } #endregion }
/// <summary> /// Initializes a new instance of the <see cref="RssCloud"/> class using the supplied domain, path, port, protocol and procedure name. /// </summary> /// <param name="domain">The host name or IP address of the web service that monitors updates to a feed.</param> /// <param name="path">The path of the web service that monitors updates to a feed.</param> /// <param name="port">The TCP port of the web service that monitors updates to a feed.</param> /// <param name="protocol"> An <see cref="RssCloudProtocol"/> enumeration value that represents the message format utilized by the web service that monitors updates to a feed.</param> /// <param name="registerProcedure">The name of the remote procedure to call when requesting notification of feed updates.</param> /// <exception cref="ArgumentNullException">The <paramref name="domain"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="domain"/> is an empty string.</exception> /// <exception cref="ArgumentNullException">The <paramref name="path"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="path"/> is an empty string.</exception> /// <exception cref="ArgumentOutOfRangeException">The <paramref name="port"/> is less than <i>zero</i>.</exception> /// <exception cref="ArgumentException">The <paramref name="protocol"/> is equal to <see cref="RssCloudProtocol.None"/>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="registerProcedure"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="registerProcedure"/> is an empty string.</exception> public RssCloud(string domain, string path, int port, RssCloudProtocol protocol, string registerProcedure) { //------------------------------------------------------------ // Initialize class state using guarded properties //------------------------------------------------------------ this.Domain = domain; this.Path = path; this.Port = port; this.Protocol = protocol; this.RegisterProcedure = registerProcedure; }
/// <summary> /// Returns the <see cref="RssCloudProtocol"/> enumeration value that corresponds to the specified protocol name. /// </summary> /// <param name="name">The name of the cloud protocol.</param> /// <returns>A <see cref="RssCloudProtocol"/> enumeration value that corresponds to the specified string, otherwise returns <b>RssCloudProtocol.None</b>.</returns> /// <remarks>This method disregards case of specified protocol 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> /// <example> /// <code lang="cs" title="The following code example demonstrates the usage of the CloudProtocolByName method."> /// <code /// source="..\..\Documentation\Microsoft .NET 3.5\CodeExamplesLibrary\Core\Rss\RssCloudExample.cs" /// region="CloudProtocolByName(string name)" /// /> /// </code> /// </example> public static RssCloudProtocol CloudProtocolByName(string name) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ RssCloudProtocol cloudProtocol = RssCloudProtocol.None; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNullOrEmptyString(name, "name"); //------------------------------------------------------------ // Determine syndication content format based on supplied name //------------------------------------------------------------ foreach (System.Reflection.FieldInfo fieldInfo in typeof(RssCloudProtocol).GetFields()) { if (fieldInfo.FieldType == typeof(RssCloudProtocol)) { RssCloudProtocol protocol = (RssCloudProtocol)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) { cloudProtocol = protocol; break; } } } } return cloudProtocol; }
/// <summary> /// Returns the cloud protocol identifier for the supplied <see cref="RssCloudProtocol"/>. /// </summary> /// <param name="protocol">The <see cref="RssCloudProtocol"/> to get the cloud protocol identifier for.</param> /// <returns>The cloud protocol identifier for the supplied <paramref name="protocol"/>, otherwise returns an empty string.</returns> /// <example> /// <code lang="cs" title="The following code example demonstrates the usage of the CloudProtocolAsString method."> /// <code /// source="..\..\Documentation\Microsoft .NET 3.5\CodeExamplesLibrary\Core\Rss\RssCloudExample.cs" /// region="CloudProtocolAsString(RssCloudProtocol protocol)" /// /> /// </code> /// </example> public static string CloudProtocolAsString(RssCloudProtocol protocol) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ string name = String.Empty; //------------------------------------------------------------ // Return alternate value based on supplied protocol //------------------------------------------------------------ foreach (System.Reflection.FieldInfo fieldInfo in typeof(RssCloudProtocol).GetFields()) { if (fieldInfo.FieldType == typeof(RssCloudProtocol)) { RssCloudProtocol cloudProtocol = (RssCloudProtocol)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); if (cloudProtocol == protocol) { 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; }