コード例 #1
0
        /// <summary>
        /// Basically the same as <seealso cref="Get"/> but more specially and it requires the instance of ScrapeHelper.
        /// </summary>
        /// <param name="uri">Uri to request</param>
        /// <param name="id">Unique id per <seealso cref="ScrapeHelper"/> to keep track of it when the event fires</param>
        /// <param name="arg">Object argument for the for the event</param>
        /// <param name="api">Dataprovider Api which is used</param>
        /// <remarks type="caution">Requires Refactoring</remarks>
        public void CrawlString(String uri, int id, object arg, ITradingPostApi api)
        {
            if (String.IsNullOrEmpty(uri))
            {
                throw new ArgumentException("Uri must be not null or empty");
            }

            if (Finished != null) // it makes no sense to start without attached handlers
            {
                try
                {
                    var    sw           = Stopwatch.StartNew();
                    String response     = "";
                    int    responseCode = 0;
                    try
                    {
                        PrepareScraper(_client); // setting headers and what not...
                        response = _client.DownloadString(uri);
                    }
                    catch (WebException ex)
                    {
                        HttpStatusCode code = (((HttpWebResponse)ex.Response).StatusCode);
                        responseCode = (int)code;
                    }
                    sw.Stop();
                    ScrapeFinishedEventArgs e = new ScrapeFinishedEventArgs(id, uri, response, arg)
                    {
                        ResponseCode = responseCode, TransactionType = this.TransactionType
                    };
                    e.Duration = sw.Elapsed;
                    if (Finished != null) // check again to be sure there was no dettaching in the processing time
                    {
                        Finished(this, e);
                    }
                }
                catch
                {
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Basically the same as <seealso cref="Get"/> but more specially and it requires the instance of ScrapeHelper.
        /// </summary>
        /// <param name="uri">Uri to request</param>
        /// <param name="id">Unique id per <seealso cref="ScrapeHelper"/> to keep track of it when the event fires</param>
        /// <param name="arg">Object argument for the for the event</param>
        /// <param name="api">Dataprovider Api which is used</param>
        /// <remarks type="caution">Requires Refactoring</remarks>
        public void CrawlString(String uri, int id, object arg, ITradingPostApi api)
        {
            if (String.IsNullOrEmpty(uri))
            {
                throw new ArgumentException("Uri must be not null or empty");
            }

            if (Finished != null) // it makes no sense to start without attached handlers
            {
                try
                {
                    var sw = Stopwatch.StartNew();
                    String response = "";
                    int responseCode = 0;
                    try
                    {
                        PrepareScraper(_client); // setting headers and what not...
                        response = _client.DownloadString(uri);
                    }
                    catch (WebException ex)
                    {
                        HttpStatusCode code = (((HttpWebResponse)ex.Response).StatusCode);
                        responseCode = (int)code;
                    }
                    sw.Stop();
                    ScrapeFinishedEventArgs e = new ScrapeFinishedEventArgs(id, uri, response, arg) { ResponseCode = responseCode, TransactionType = this.TransactionType };
                    e.Duration = sw.Elapsed;
                    if (Finished != null) // check again to be sure there was no dettaching in the processing time
                    {
                        Finished(this, e);
                    }
                }
                catch
                {

                }
            }
        }