예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SyndicationResourceLoadedEventArgs"/> class using the supplied <see cref="IXPathNavigable"/>, <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
        /// </summary>
        /// <param name="data">A <see cref="IXPathNavigable"/> object that represents the XML data that was used to load the syndication resource.</param>
        /// <param name="source">
        ///     The <see cref="Uri"/> of the Internet resource that the syndication resource was loaded from. Can be <b>null</b> if syndication resource was not loaded using an Internet resource.
        /// </param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="data"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public SyndicationResourceLoadedEventArgs(IXPathNavigable data, Uri source, WebRequestOptions options) : this(data)
        {
            Guard.ArgumentNotNull(source, "source");

            eventSource  = source;
            eventOptions = options ?? new WebRequestOptions();
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SyndicationResourceLoadedEventArgs"/> class using the supplied <see cref="IXPathNavigable"/>, <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
        /// </summary>
        /// <param name="data">A <see cref="IXPathNavigable"/> object that represents the XML data that was used to load the syndication resource.</param>
        /// <param name="source">
        ///     The <see cref="Uri"/> of the Internet resource that the syndication resource was loaded from. Can be <b>null</b> if syndication resource was not loaded using an Internet resource.
        /// </param>
        /// <param name="credentials">
        ///    The <see cref="ICredentials"/> that were used to authenticate the request to an Internet resource. Can be <b>null</b> if syndication resource was not loaded using an Internet resource.
        /// </param>
        /// <param name="proxy">
        ///     The <see cref="IWebProxy"/> used to access the Internet resource. Can be <b>null</b> if syndication resource was not loaded using an Internet resource.
        /// </param>
        /// <exception cref="ArgumentNullException">The <paramref name="data"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public SyndicationResourceLoadedEventArgs(IXPathNavigable data, Uri source, ICredentials credentials, IWebProxy proxy) : this(data)
        {
            Guard.ArgumentNotNull(source, "source");

            eventSource  = source;
            eventOptions = new WebRequestOptions(credentials, proxy);
        }
        /// <summary>
        /// Returns a <see cref="WebRequest"/> that makes a request for a resource located at the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that points to the location of the resource to be retrieved.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <returns>
        ///     An <see cref="WebRequest"/> that makes a request to the <paramref name="source"/>. If unable to create a <see cref="WebRequest"/> for
        ///     the specified <paramref name="source"/>, returns a <b>null</b> reference (Nothing in Visual Basic).
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public static WebRequest CreateWebRequest(Uri source, WebRequestOptions options)
        {
            WebRequest request = null;

            Guard.ArgumentNotNull(source, "source");

            request = WebRequest.Create(source);

            if (source.IsAbsoluteUri)
            {
                if (String.Compare(source.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) == 0 ||
                    String.Compare(source.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    HttpWebRequest httpRequest = (HttpWebRequest)request;
                    httpRequest.UserAgent = SyndicationDiscoveryUtility.FrameworkUserAgent;
                    request = httpRequest;
                }
            }

            if (options != null)
            {
                options.ApplyOptions(request);
            }
            return(request);
        }
 /// <summary>
 /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
 /// </summary>
 /// <param name="source">A <see cref="Uri"/> that points to the location of the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param>
 /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
 /// <returns>
 ///     An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="source"/>.
 ///     The supplied <paramref name="source"/> XML data is parsed to remove invalid XML characters that would normally prevent
 ///     a navigator from being created.
 /// </returns>
 /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
 public static XPathNavigator CreateSafeNavigator(Uri source, WebRequestOptions options)
 {
     //------------------------------------------------------------
     //	Create safe navigator using auto-detection of encoding
     //------------------------------------------------------------
     return(SyndicationEncodingUtility.CreateSafeNavigator(source, options, null));
 }
        /// <summary>
        /// Returns the <see cref="WebResponse"/> to a request for a resource located at the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that points to the location of the resource to be retrieved.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <returns>
        ///     An <see cref="WebResponse"/> that contains the response from the requested resource. If unable to create a <see cref="WebResponse"/> for
        ///     the requested <paramref name="source"/>, returns a <b>null</b> reference (Nothing in Visual Basic).
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public static WebResponse CreateWebResponse(Uri source, WebRequestOptions options)
        {
            WebResponse response = null;

            Guard.ArgumentNotNull(source, "source");

            WebRequest webRequest = SyndicationEncodingUtility.CreateWebRequest(source, options);

            if (webRequest != null)
            {
                response = webRequest.GetResponse();
            }

            return(response);
        }
        /// <summary>
        /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that points to the location of the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <param name="encoding">A <see cref="Encoding"/> object that indicates the expected character encoding of the supplied <paramref name="source"/>. This value can be <b>null</b>.</param>
        /// <returns>
        ///     An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="source"/>.
        ///     The supplied <paramref name="source"/> XML data is parsed to remove invalid XML characters that would normally prevent
        ///     a navigator from being created.
        /// </returns>
        /// <remarks>
        ///     If the <paramref name="encoding"/> is <b>null</b>, the character encoding of the supplied <paramref name="source"/> is determined automatically.
        ///     Otherwise the specified <paramref name="encoding"/> is used when reading the XML data represented by the supplied <paramref name="source"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public static XPathNavigator CreateSafeNavigator(Uri source, WebRequestOptions options, Encoding encoding)
        {
            Guard.ArgumentNotNull(source, "source");

            using (WebResponse response = SyndicationEncodingUtility.CreateWebResponse(source, options))
            {
                Stream          stream       = null;
                HttpWebResponse httpResponse = response as HttpWebResponse;

                if (httpResponse != null)
                {
                    string contentEncoding = httpResponse.ContentEncoding?.ToUpperInvariant();

                    if (string.IsNullOrEmpty(contentEncoding))
                    {
                        stream = response.GetResponseStream();
                    }
                    else
                    {
                        if (contentEncoding.Contains("GZIP"))
                        {
                            stream = new GZipStream(httpResponse.GetResponseStream(), CompressionMode.Decompress);
                        }
                        else if (contentEncoding.Contains("DEFLATE"))
                        {
                            stream = new DeflateStream(httpResponse.GetResponseStream(), CompressionMode.Decompress);
                        }
                        else
                        {
                            stream = httpResponse.GetResponseStream();
                        }
                    }
                }
                else
                {
                    stream = response.GetResponseStream();
                }

                if (encoding != null)
                {
                    return(SyndicationEncodingUtility.CreateSafeNavigator(stream, encoding));
                }
                else
                {
                    return(SyndicationEncodingUtility.CreateSafeNavigator(stream));
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Initializes a new <see cref="WebRequest"/> suitable for sending a remote procedure call using the supplied host, user agent, message, credentials, and proxy.
        /// </summary>
        /// <param name="host">A <see cref="Uri"/> that represents the URL of the host computer used for XML-RPC transactions.</param>
        /// <param name="userAgent">Information such as the application name, version, host operating system, and language.</param>
        /// <param name="message">A <see cref="XmlRpcMessage"/> that represents the information needed to execute the remote procedure call.</param>
        /// <param name="useDefaultCredentials">
        ///     Controls whether the <see cref="CredentialCache.DefaultCredentials">DefaultCredentials</see> are sent when making remote procedure calls.
        /// </param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="host"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="userAgent"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="userAgent"/> is an empty string.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="message"/> is a null reference (Nothing in Visual Basic).</exception>
        private static WebRequest CreateWebRequest(Uri host, string userAgent, XmlRpcMessage message, bool useDefaultCredentials, WebRequestOptions options)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            HttpWebRequest httpRequest  = null;
            byte[] payloadData;

            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(host, "host");
            Guard.ArgumentNotNullOrEmptyString(userAgent, "userAgent");
            Guard.ArgumentNotNull(message, "message");

            //------------------------------------------------------------
            //	Build the XML-RPC payload data
            //------------------------------------------------------------
            using(MemoryStream stream = new MemoryStream())
            {
                XmlWriterSettings settings  = new XmlWriterSettings();
                settings.ConformanceLevel   = ConformanceLevel.Document;
                settings.Encoding           = message.Encoding;
                settings.Indent             = true;
                settings.OmitXmlDeclaration = false;

                using(XmlWriter writer = XmlWriter.Create(stream, settings))
                {
                    message.WriteTo(writer);
                    writer.Flush();
                }

                stream.Seek(0, SeekOrigin.Begin);
                payloadData                 = message.Encoding.GetBytes((new StreamReader(stream)).ReadToEnd());
            }

            //------------------------------------------------------------
            //	Build HTTP web request used to send a remote procedure call
            //------------------------------------------------------------
            httpRequest                     = (HttpWebRequest)HttpWebRequest.Create(host);
            httpRequest.Method              = "POST";
            httpRequest.ContentLength       = payloadData.Length;
            httpRequest.ContentType         = String.Format(null, "text/xml; charset={0}", message.Encoding.WebName);
            httpRequest.UserAgent           = userAgent;
            if (options != null) options.ApplyOptions(httpRequest);

            if(useDefaultCredentials)
            {
                httpRequest.Credentials = CredentialCache.DefaultCredentials;
            }

            using (Stream stream = httpRequest.GetRequestStream())
            {
                stream.Write(payloadData, 0, payloadData.Length);
            }

            return httpRequest;
        }
 /// <summary>
 /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
 /// </summary>
 /// <param name="source">A <see cref="Uri"/> that points to the location of the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param>
 /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
 /// <returns>
 ///     An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="source"/>.
 ///     The supplied <paramref name="source"/> XML data is parsed to remove invalid XML characters that would normally prevent
 ///     a navigator from being created.
 /// </returns>
 /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
 public static XPathNavigator CreateSafeNavigator(Uri source, WebRequestOptions options)
 {
     return(SyndicationEncodingUtility.CreateSafeNavigator(source, options, null));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SyndicationResourceLoadedEventArgs"/> class using the supplied <see cref="IXPathNavigable"/>, <see cref="ICredentials">credentials</see>, <see cref="IWebProxy">proxy</see> and user token.
 /// </summary>
 /// <param name="data">A <see cref="IXPathNavigable"/> object that represents the XML data that was used to load the syndication resource.</param>
 /// <param name="source">
 ///     The <see cref="Uri"/> of the Internet resource that the syndication resource was loaded from. Can be <b>null</b> if syndication resource was not loaded using an Internet resource.
 /// </param>
 /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
 /// <param name="state">The user-defined object that was passed to the asynchronous operation.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="data"/> is a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
 public SyndicationResourceLoadedEventArgs(IXPathNavigable data, Uri source, WebRequestOptions options, Object state)
     : this(data, source, options)
 {
     eventUserToken  = state;
 }
예제 #10
0
파일: AtomEntry.cs 프로젝트: Jiyuu/Argotic
 /// <summary>
 /// Creates a new <see cref="AtomEntry"/> instance using the specified <see cref="Uri"/>, <see cref="ICredentials"/>, and <see cref="IWebProxy"/>.
 /// </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>
 /// <returns>An <see cref="AtomEntry"/> object loaded using the <paramref name="source"/> data.</returns>
 /// <remarks>
 ///     The <see cref="AtomEntry"/> is created using the default <see cref="SyndicationResourceLoadSettings"/>.
 /// </remarks>
 /// <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 entry remains empty.</exception>
 public static AtomEntry Create(Uri source, WebRequestOptions options)
 {
     //------------------------------------------------------------
     //	Create instance using supplied parameters and default settings
     //------------------------------------------------------------
     return AtomEntry.Create(source, options, null);
 }
예제 #11
0
        /// <summary>
        /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that points to the location of the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <param name="encoding">A <see cref="Encoding"/> object that indicates the expected character encoding of the supplied <paramref name="source"/>. This value can be <b>null</b>.</param>
        /// <returns>
        ///     An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="source"/>. 
        ///     The supplied <paramref name="source"/> XML data is parsed to remove invalid XML characters that would normally prevent 
        ///     a navigator from being created.
        /// </returns>
        /// <remarks>
        ///     If the <paramref name="encoding"/> is <b>null</b>, the character encoding of the supplied <paramref name="source"/> is determined automatically. 
        ///     Otherwise the specified <paramref name="encoding"/> is used when reading the XML data represented by the supplied <paramref name="source"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public static XPathNavigator CreateSafeNavigator(Uri source, WebRequestOptions options, Encoding encoding)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            using (WebResponse response = SyndicationEncodingUtility.CreateWebResponse(source, options))
            {
                Stream stream                   = null;
                HttpWebResponse httpResponse    = response as HttpWebResponse;

                if (httpResponse != null)
                {
                    string contentEncoding  = httpResponse.ContentEncoding.ToUpperInvariant();

                    if (contentEncoding.Contains("GZIP"))
                    {
                        stream  = new GZipStream(httpResponse.GetResponseStream(), CompressionMode.Decompress);
                    }
                    else if (contentEncoding.Contains("DEFLATE"))
                    {
                        stream  = new DeflateStream(httpResponse.GetResponseStream(), CompressionMode.Decompress);
                    }
                    else
                    {
                        stream  = httpResponse.GetResponseStream();
                    }
                }
                else
                {
                    stream      = response.GetResponseStream();
                }

                if (encoding != null)
                {
                    return SyndicationEncodingUtility.CreateSafeNavigator(stream, encoding);
                }
                else
                {
                    return SyndicationEncodingUtility.CreateSafeNavigator(stream);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SyndicationResourceLoadedEventArgs"/> class using the supplied <see cref="IXPathNavigable"/>, <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
        /// </summary>
        /// <param name="data">A <see cref="IXPathNavigable"/> object that represents the XML data that was used to load the syndication resource.</param>
        /// <param name="source">
        ///     The <see cref="Uri"/> of the Internet resource that the syndication resource was loaded from. Can be <b>null</b> if syndication resource was not loaded using an Internet resource.
        /// </param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="data"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public SyndicationResourceLoadedEventArgs(IXPathNavigable data, Uri source, WebRequestOptions options)
            : this(data)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            eventSource         = source;
            eventOptions        = options ?? new WebRequestOptions();
        }
예제 #13
0
        /// <summary>
        /// Creates a new <see cref="GenericSyndicationFeed"/> 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="GenericSyndicationFeed"/> instance. This value can be <b>null</b>.</param>
        /// <returns>An <see cref="GenericSyndicationFeed"/> 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 feed remains empty.</exception>
        public static GenericSyndicationFeed Create(Uri source, WebRequestOptions options, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            GenericSyndicationFeed syndicationResource  = new GenericSyndicationFeed();

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

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

            return syndicationResource;
        }
예제 #14
0
        /// <summary>
        /// Loads the syndication resource from the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see>, <see cref="IWebProxy">proxy</see> and <see cref="SyndicationResourceLoadSettings"/>.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that points to the location of the web resource used to load the syndication resource.</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="GenericSyndicationFeed"/> instance. This value can be <b>null</b>.</param>
        /// <remarks>
        ///     <para>
        ///         <list type="bullet">
        ///             <item>
        ///                 <description>
        ///                     If <paramref name="settings"/> has a <see cref="SyndicationResourceLoadSettings.CharacterEncoding">character encoding</see> of <see cref="System.Text.Encoding.UTF8"/> 
        ///                     the character encoding of the <paramref name="source"/> will be attempt to be determined automatically, otherwise the specified character encoding will be used. 
        ///                     If automatic detection fails, a character encoding of <see cref="System.Text.Encoding.UTF8"/> is used by default.
        ///                 </description>
        ///             </item>
        ///             <item>
        ///                 <description>
        ///                     After the load operation has successfully completed, the <see cref="GenericSyndicationFeed.Loaded"/> event will be raised.
        ///                 </description>
        ///             </item>
        ///         </list>
        ///     </para>
        /// </remarks>
        /// <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 a supported syndication content format. In this case, the feed remains empty.</exception>
        /// <exception cref="XmlException">There is a load or parse error in the XML. In this case, the feed remains empty.</exception>
        public void Load(Uri source, WebRequestOptions options, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            XPathNavigator navigator    = null;

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

            //------------------------------------------------------------
            //	Use default settings if none specified by the caller
            //------------------------------------------------------------
            if (settings == null)
            {
                settings = new SyndicationResourceLoadSettings();
            }

            //------------------------------------------------------------
            //	Initialize XPathNavigator for supplied Uri, credentials, and proxy
            //------------------------------------------------------------
            if (settings.CharacterEncoding == System.Text.Encoding.UTF8)
            {
                navigator    = SyndicationEncodingUtility.CreateSafeNavigator(source, options, null);
            }
            else
            {
                navigator    = SyndicationEncodingUtility.CreateSafeNavigator(source, options, settings.CharacterEncoding);
            }

            //------------------------------------------------------------
            //	Load syndication resource using the framework adapters
            //------------------------------------------------------------
            this.Load(navigator, settings, new SyndicationResourceLoadedEventArgs(navigator, source, options));
        }
예제 #15
0
        /// <summary>
        /// Returns a <see cref="WebRequest"/> that makes a request for a resource located at the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that points to the location of the resource to be retrieved.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <returns>
        ///     An <see cref="WebRequest"/> that makes a request to the <paramref name="source"/>. If unable to create a <see cref="WebRequest"/> for 
        ///     the specified <paramref name="source"/>, returns a <b>null</b> reference (Nothing in Visual Basic).
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public static WebRequest CreateWebRequest(Uri source, WebRequestOptions options)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            WebRequest request  = null;

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

            request             = WebRequest.Create(source);

            if(source.IsAbsoluteUri)
            {
                if (String.Compare(source.Scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) == 0 ||
                    String.Compare(source.Scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    HttpWebRequest httpRequest      = (HttpWebRequest)request;
                    httpRequest.UserAgent           = SyndicationDiscoveryUtility.FrameworkUserAgent;
                    request                         = httpRequest;
                }
            }

            if (options != null) options.ApplyOptions(request);
            return request;
        }
예제 #16
0
 /// <summary>
 /// Creates a new <see cref="OpmlDocument"/> instance using the specified <see cref="Uri"/>, <see cref="ICredentials"/>, and <see cref="IWebProxy"/>.
 /// </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>
 /// <returns>An <see cref="OpmlDocument"/> object loaded using the <paramref name="source"/> data.</returns>
 /// <remarks>
 ///     The <see cref="OpmlDocument"/> is created using the default <see cref="SyndicationResourceLoadSettings"/>.
 /// </remarks>
 /// <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 OpmlDocument Create(Uri source, WebRequestOptions options)
 {
     //------------------------------------------------------------
     //	Create instance using supplied parameters and default settings
     //------------------------------------------------------------
     return OpmlDocument.Create(source, options, null);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SyndicationResourceLoadedEventArgs"/> class using the supplied <see cref="IXPathNavigable"/>, <see cref="ICredentials">credentials</see>, <see cref="IWebProxy">proxy</see> and user token.
 /// </summary>
 /// <param name="data">A <see cref="IXPathNavigable"/> object that represents the XML data that was used to load the syndication resource.</param>
 /// <param name="source">
 ///     The <see cref="Uri"/> of the Internet resource that the syndication resource was loaded from. Can be <b>null</b> if syndication resource was not loaded using an Internet resource.
 /// </param>
 /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
 /// <param name="state">The user-defined object that was passed to the asynchronous operation.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="data"/> is a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
 public SyndicationResourceLoadedEventArgs(IXPathNavigable data, Uri source, WebRequestOptions options, Object state) : this(data, source, options)
 {
     eventUserToken = state;
 }
예제 #18
0
        /// <summary>
        /// Initializes a new <see cref="WebRequest"/> suitable for sending an Trackback ping request using the supplied host, user agent, message, credentials, and proxy.
        /// </summary>
        /// <param name="host">A <see cref="Uri"/> that represents the URL of the host computer used for Trackback transactions.</param>
        /// <param name="userAgent">Information such as the application name, version, host operating system, and language.</param>
        /// <param name="message">A <see cref="TrackbackMessage"/> that represents the information needed to execute the Trackback ping request.</param>
        /// <param name="useDefaultCredentials">
        ///     Controls whether the <see cref="CredentialCache.DefaultCredentials">DefaultCredentials</see> are sent when making Trackback pings.
        /// </param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="host"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="userAgent"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="userAgent"/> is an empty string.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="message"/> is a null reference (Nothing in Visual Basic).</exception>
        private static WebRequest CreateWebRequest(Uri host, string userAgent, TrackbackMessage message, bool useDefaultCredentials, WebRequestOptions options)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            HttpWebRequest httpRequest  = null;
            byte[] payloadData;

            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(host, "host");
            Guard.ArgumentNotNullOrEmptyString(userAgent, "userAgent");
            Guard.ArgumentNotNull(message, "message");

            //------------------------------------------------------------
            //	Build the Trackback payload data
            //------------------------------------------------------------
            using(MemoryStream stream = new MemoryStream())
            {
                using(StreamWriter writer = new StreamWriter(stream, message.Encoding))
                {
                    message.WriteTo(writer);
                    writer.Flush();

                    stream.Seek(0, SeekOrigin.Begin);
                    payloadData = message.Encoding.GetBytes((new StreamReader(stream)).ReadToEnd());
                }
            }

            //------------------------------------------------------------
            //	Build Trackback web request used to send an Trackback ping request
            //------------------------------------------------------------
            httpRequest                     = (HttpWebRequest)HttpWebRequest.Create(host);
            httpRequest.Method              = "POST";
            httpRequest.ContentLength       = payloadData.Length;
            httpRequest.ContentType         = String.Format(null, "application/x-www-form-urlencoded; charset={0}", message.Encoding.WebName);
            httpRequest.UserAgent           = userAgent;
            if (options != null) options.ApplyOptions(httpRequest);

            if(useDefaultCredentials)
            {
                httpRequest.Credentials     = CredentialCache.DefaultCredentials;
            }

            using (Stream stream = httpRequest.GetRequestStream())
            {
                stream.Write(payloadData, 0, payloadData.Length);
            }

            return httpRequest;
        }
예제 #19
0
        /// <summary>
        /// Returns the <see cref="WebResponse"/> to a request for a resource located at the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that points to the location of the resource to be retrieved.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <returns>
        ///     An <see cref="WebResponse"/> that contains the response from the requested resource. If unable to create a <see cref="WebResponse"/> for 
        ///     the requested <paramref name="source"/>, returns a <b>null</b> reference (Nothing in Visual Basic).
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public static WebResponse CreateWebResponse(Uri source, WebRequestOptions options)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            WebResponse response    = null;

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

            WebRequest webRequest   = SyndicationEncodingUtility.CreateWebRequest(source, options);
            if (webRequest != null)
            {
                response    = webRequest.GetResponse();
            }

            return response;
        }
예제 #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TrackbackMessageSentEventArgs"/> class using the supplied parameters.
        /// </summary>
        /// <param name="host">A <see cref="Uri"/> that represents the URL of the host computer used for the XML-RPC transaction.</param>
        /// <param name="message">An <see cref="TrackbackMessage"/> that represents the Trackback ping request payload.</param>
        /// <param name="response">An <see cref="TrackbackResponse"/> that represents the response to the Trackback ping request.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <param name="state">A <see cref="Object"/> containing state information that was passed to the asynchronous send operation. This parameter may be <b>null</b>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="host"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="message"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="response"/> is a null reference (Nothing in Visual Basic).</exception>
        public TrackbackMessageSentEventArgs(Uri host, TrackbackMessage message, TrackbackResponse response, WebRequestOptions options, Object state)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(host, "host");
            Guard.ArgumentNotNull(message, "message");
            Guard.ArgumentNotNull(response, "response");

            //------------------------------------------------------------
            //	Initialize class members
            //------------------------------------------------------------
            eventHost           = host;
            eventMessage        = message;
            eventResponse       = response;
            eventOptions        = options ?? new WebRequestOptions();
            eventUserToken      = state;
        }
예제 #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlRpcMessageSentEventArgs"/> class using the supplied parameters.
        /// </summary>
        /// <param name="host">A <see cref="Uri"/> that represents the URL of the host computer used for the XML-RPC transaction.</param>
        /// <param name="message">An <see cref="XmlRpcMessage"/> that represents the remote procedure call payload.</param>
        /// <param name="response">An <see cref="XmlRpcResponse"/> that represents the response to the remote procedure call.</param>
        /// <param name="credentials">A <see cref="ICredentials"/> that represents the authentication credentials utilized by the client when making the remote procedure call. This parameter may be <b>null</b>.</param>
        /// <param name="proxy">A <see cref="IWebProxy"/> that represents the web proxy utilized by the client to proxy the remote procedure call. This parameter may be <b>null</b>.</param>
        /// <param name="state">A <see cref="Object"/> containing state information that was passed to the asynchronous send operation. This parameter may be <b>null</b>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="host"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="message"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="response"/> is a null reference (Nothing in Visual Basic).</exception>
        public XmlRpcMessageSentEventArgs(Uri host, XmlRpcMessage message, XmlRpcResponse response, ICredentials credentials, IWebProxy proxy, Object state)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(host, "host");
            Guard.ArgumentNotNull(message, "message");
            Guard.ArgumentNotNull(response, "response");

            //------------------------------------------------------------
            //	Initialize class members
            //------------------------------------------------------------
            eventHost           = host;
            eventMessage        = message;
            eventResponse       = response;
            eventOptions        = new WebRequestOptions(credentials, proxy);
            eventUserToken      = state;
        }
예제 #22
0
        /// <summary>
        /// Performs a conditional get operation against the supplied <see cref="Uri"/> using the specified <see cref="DateTime"/>, entity tag and <see cref="ICredentials">credentials</see>.
        /// </summary>
        /// <param name="source">The <see cref="Uri"/> to perform a conditional GET operation against.</param>
        /// <param name="lastModified">A <see cref="DateTime"/> object that represents the date and time at which the <paramref name="source"/> was last known to be modified.</param>
        /// <param name="entityTag">The entity tag provided by the <paramref name="source"/> that is used to determine change in content.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <returns>A <see cref="HttpWebResponse"/> for the <paramref name="source"/> if it has been modfied, otherwise <b>null</b>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public static HttpWebResponse ConditionalGet(Uri source, DateTime lastModified, string entityTag, WebRequestOptions options)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            HttpWebResponse response    = null;

            //------------------------------------------------------------
            //	Attempt to perform conditional get operation
            //------------------------------------------------------------
            if (SyndicationDiscoveryUtility.TryConditionalGet(source, lastModified, entityTag, options, out response))
            {
                return response;
            }
            else
            {
                return null;
            }
        }
예제 #23
0
        /// <summary>
        /// Performs a conditional get operation against the supplied <see cref="Uri"/> using the specified <see cref="DateTime"/>, entity tag and <see cref="ICredentials">credentials</see>.
        /// </summary>
        /// <param name="source">The <see cref="Uri"/> to perform a conditional GET operation against.</param>
        /// <param name="lastModified">A <see cref="DateTime"/> object that represents the date and time at which the <paramref name="source"/> was last known to be modified.</param>
        /// <param name="entityTag">The entity tag provided by the <paramref name="source"/> that is used to determine change in content.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <param name="response">
        ///     When this method returns, contains the <see cref="HttpWebResponse"/> for the supplied <paramref name="source"/>, if the web resource has been modified, or <b>null</b> if the web resource has <u>not</u> been modified. 
        ///     This parameter is passed uninitialized.
        /// </param>
        /// <returns><b>true</b> if the <paramref name="source"/> has been modified, otherwise <b>false</b>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public static bool TryConditionalGet(Uri source, DateTime lastModified, string entityTag, WebRequestOptions options, out HttpWebResponse response)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool sourceHasBeenModified  = false;

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

            //------------------------------------------------------------
            //	Initialize web request as a condtional get operation
            //------------------------------------------------------------
            HttpWebRequest httpRequest      = (HttpWebRequest)HttpWebRequest.Create(source);
            httpRequest.UserAgent           = frameworkUserAgent;
            httpRequest.IfModifiedSince     = lastModified;
            httpRequest.Headers.Add(HttpRequestHeader.IfNoneMatch, entityTag);
            if (options != null) options.ApplyOptions(httpRequest);

            //------------------------------------------------------------
            //	Perform conditional get operation
            //------------------------------------------------------------
            try
            {
                response    = (HttpWebResponse)httpRequest.GetResponse();

                if (DateTime.Compare(response.LastModified, lastModified) != 0)
                {
                    sourceHasBeenModified   = true;
                }
            }
            catch (WebException webException)
            {
                //------------------------------------------------------------
                //	Determine if response indicated resource was not modified
                //------------------------------------------------------------
                if (webException.Response != null && ((HttpWebResponse)webException.Response).StatusCode == HttpStatusCode.NotModified)
                {
                    sourceHasBeenModified   = false;
                    response                = null;
                }
                else
                {
                    //------------------------------------------------------------
                    //	Rethrow unexpected web exception
                    //------------------------------------------------------------
                    throw;
                }
            }

            return sourceHasBeenModified;
        }
예제 #24
0
 /// <summary>
 /// Creates a new <see cref="GenericSyndicationFeed"/> instance using the specified <see cref="Uri"/>, <see cref="ICredentials"/>, and <see cref="IWebProxy"/>.
 /// </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>
 /// <returns>An <see cref="GenericSyndicationFeed"/> object loaded using the <paramref name="source"/> data.</returns>
 /// <remarks>
 ///     The <see cref="GenericSyndicationFeed"/> is created using the default <see cref="SyndicationResourceLoadSettings"/>.
 /// </remarks>
 /// <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 feed remains empty.</exception>
 public static GenericSyndicationFeed Create(Uri source, WebRequestOptions options)
 {
     //------------------------------------------------------------
     //	Create instance using supplied parameters and default settings
     //------------------------------------------------------------
     return GenericSyndicationFeed.Create(source, options, null);
 }
예제 #25
0
        /// <summary>
        /// Loads the syndication resource from the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see>, <see cref="IWebProxy">proxy</see> and <see cref="SyndicationResourceLoadSettings"/>.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that points to the location of the web resource used to load the syndication resource.</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="AtomEntry"/> instance. This value can be <b>null</b>.</param>
        /// <remarks>
        ///     <para>
        ///         <list type="bullet">
        ///             <item>
        ///                 <description>
        ///                     If <paramref name="settings"/> has a <see cref="SyndicationResourceLoadSettings.CharacterEncoding">character encoding</see> of <see cref="System.Text.Encoding.UTF8"/> 
        ///                     the character encoding of the <paramref name="source"/> will be attempt to be determined automatically, otherwise the specified character encoding will be used. 
        ///                     If automatic detection fails, a character encoding of <see cref="System.Text.Encoding.UTF8"/> is used by default.
        ///                 </description>
        ///             </item>
        ///             <item>
        ///                 <description>
        ///                     After the load operation has successfully completed, the <see cref="AtomEntry.Loaded"/> event will be raised.
        ///                 </description>
        ///             </item>
        ///         </list>
        ///     </para>
        /// </remarks>
        /// <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 entry remains empty.</exception>
        /// <exception cref="XmlException">There is a load or parse error in the XML. In this case, the entry remains empty.</exception>
        public new void Load(Uri source, WebRequestOptions options, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Load syndication resource using base entry implementation
            //------------------------------------------------------------
            base.Load(source, options, settings);

            //------------------------------------------------------------
            //	Extract member resource information from extensions
            //------------------------------------------------------------
            AtomPublishingEditedSyndicationExtension editedExtension    = this.FindExtension(AtomPublishingEditedSyndicationExtension.MatchByType) as AtomPublishingEditedSyndicationExtension;
            if (editedExtension != null)
            {
                this.EditedOn   = editedExtension.Context.EditedOn;
            }

            AtomPublishingControlSyndicationExtension controlExtension  = this.FindExtension(AtomPublishingControlSyndicationExtension.MatchByType) as AtomPublishingControlSyndicationExtension;
            if (controlExtension != null)
            {
                this.IsDraft    = controlExtension.Context.IsDraft;
            }
        }
예제 #26
0
 /// <summary>
 /// Loads the syndication resource from the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
 /// </summary>
 /// <param name="source">A <see cref="Uri"/> that points to the location of the web resource used to load the syndication resource.</param>
 /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
 /// <remarks>
 ///     <para>
 ///         <list type="bullet">
 ///             <item>
 ///                 <description>
 ///                     After the load operation has successfully completed, the <see cref="GenericSyndicationFeed.Loaded"/> event will be raised.
 ///                 </description>
 ///             </item>
 ///         </list>
 ///     </para>
 /// </remarks>
 /// <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 a supported syndication content format. In this case, the feed remains empty.</exception>
 /// <exception cref="XmlException">There is a load or parse error in the XML. In this case, the feed remains empty.</exception>
 /// <example>
 ///     <code lang="cs" title="The following code example demonstrates the usage of the Load method.">
 ///         <code 
 ///             source="..\..\Documentation\Microsoft .NET 3.5\CodeExamplesLibrary\Core\GenericSyndicationFeedExample.cs" 
 ///             region="Load(Uri source, WebRequestOptions options)" 
 ///         />
 ///     </code>
 /// </example>
 public void Load(Uri source, WebRequestOptions options)
 {
     //------------------------------------------------------------
     //	Load syndication resource using default settings
     //------------------------------------------------------------
     this.Load(source, options, null);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SyndicationResourceLoadedEventArgs"/> class using the supplied <see cref="IXPathNavigable"/>, <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
        /// </summary>
        /// <param name="data">A <see cref="IXPathNavigable"/> object that represents the XML data that was used to load the syndication resource.</param>
        /// <param name="source">
        ///     The <see cref="Uri"/> of the Internet resource that the syndication resource was loaded from. Can be <b>null</b> if syndication resource was not loaded using an Internet resource.
        /// </param>
        /// <param name="credentials">
        ///    The <see cref="ICredentials"/> that were used to authenticate the request to an Internet resource. Can be <b>null</b> if syndication resource was not loaded using an Internet resource.
        /// </param>
        /// <param name="proxy">
        ///     The <see cref="IWebProxy"/> used to access the Internet resource. Can be <b>null</b> if syndication resource was not loaded using an Internet resource.
        /// </param>
        /// <exception cref="ArgumentNullException">The <paramref name="data"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public SyndicationResourceLoadedEventArgs(IXPathNavigable data, Uri source, ICredentials credentials, IWebProxy proxy)
            : this(data)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            eventSource         = source;
            eventOptions        = new WebRequestOptions(credentials, proxy);
        }
예제 #28
0
        /// <summary>
        /// Loads this <see cref="RssFeed"/> instance asynchronously using the specified <see cref="Uri"/>, <see cref="SyndicationResourceLoadSettings"/>, <see cref="ICredentials"/>, and <see cref="IWebProxy"/>.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="RssFeed"/> instance. This value can be <b>null</b>.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <param name="userToken">A user-defined object that is passed to the method invoked when the asynchronous operation completes.</param>
        /// <remarks>
        ///     <para>
        ///         To receive notification when the operation has completed or the operation has been canceled, add an event handler to the <see cref="Loaded"/> event. 
        ///         You can cancel a <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/> operation by calling the <see cref="LoadAsyncCancel()"/> method.
        ///     </para>
        ///     <para>
        ///         After calling <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/>, 
        ///         you must wait for the load operation to complete before attempting to load the syndication resource using the <see cref="LoadAsync(Uri, Object)"/> method.
        ///     </para>
        /// </remarks>
        /// <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 feed remains empty.</exception>
        /// <exception cref="InvalidOperationException">This <see cref="RssFeed"/> has a <see cref="LoadAsync(Uri, SyndicationResourceLoadSettings, ICredentials, IWebProxy, Object)"/> call in progress.</exception>
        public void LoadAsync(Uri source, SyndicationResourceLoadSettings settings, WebRequestOptions options, Object userToken)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            //------------------------------------------------------------
            //	Use default settings if none specified by the caller
            //------------------------------------------------------------
            if (settings == null)
            {
                settings    = new SyndicationResourceLoadSettings();
            }

            //------------------------------------------------------------
            //	Validate syndication resource state
            //------------------------------------------------------------
            if (this.LoadOperationInProgress)
            {
                throw new InvalidOperationException();
            }

            //------------------------------------------------------------
            //	Indicate that a load operation is in progress
            //------------------------------------------------------------
            this.LoadOperationInProgress    = true;

            //------------------------------------------------------------
            //	Reset the asynchronous load operation cancelled indicator
            //------------------------------------------------------------
            this.AsyncLoadHasBeenCancelled  = false;

            //------------------------------------------------------------
            //	Build HTTP web request used to retrieve the syndication resource
            //------------------------------------------------------------
            asyncHttpWebRequest         = SyndicationEncodingUtility.CreateWebRequest(source, options);
            asyncHttpWebRequest.Timeout = Convert.ToInt32(settings.Timeout.TotalMilliseconds, System.Globalization.NumberFormatInfo.InvariantInfo);

            //------------------------------------------------------------
            //	Get the async response to the web request
            //------------------------------------------------------------
            object[] state      = new object[6] { asyncHttpWebRequest, this, source, settings, options, userToken };
            IAsyncResult result = asyncHttpWebRequest.BeginGetResponse(new AsyncCallback(AsyncLoadCallback), state);

            //------------------------------------------------------------
            //  Register the timeout callback
            //------------------------------------------------------------
            ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(AsyncTimeoutCallback), state, settings.Timeout, true);
        }
예제 #29
0
 /// <summary>
 /// Creates a <see cref="XPathNavigator"/> against the supplied <see cref="Uri"/> using the specified <see cref="ICredentials">credentials</see> and <see cref="IWebProxy">proxy</see>.
 /// </summary>
 /// <param name="source">A <see cref="Uri"/> that points to the location of the XML data to be navigated by the created <see cref="XPathNavigator"/>.</param>
 /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
 /// <returns>
 ///     An <see cref="XPathNavigator"/> that provides a cursor model for navigating the supplied <paramref name="source"/>. 
 ///     The supplied <paramref name="source"/> XML data is parsed to remove invalid XML characters that would normally prevent 
 ///     a navigator from being created.
 /// </returns>
 /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
 public static XPathNavigator CreateSafeNavigator(Uri source, WebRequestOptions options)
 {
     //------------------------------------------------------------
     //	Create safe navigator using auto-detection of encoding
     //------------------------------------------------------------
     return SyndicationEncodingUtility.CreateSafeNavigator(source, options, null);
 }