示例#1
0
        /// <summary>
        /// Asynchronous download method implementation.
        /// </summary>
        /// <param name="task">The DownloadTask to process.</param>
        public void BeginDownload(DownloadTask task)
        {
            currentTask = task;

            // If we resume way too often, just return
            if (CheckForResumeAndProceed(currentTask))
            {
                return;
            }

            Uri reqUri   = new Uri(task.DownloadItem.Enclosure.Url);
            int priority = 10;

            RequestParameter reqParam = RequestParameter.Create(reqUri, FeedSource.UserAgentString(String.Empty),
                                                                task.DownloadItem.Proxy, task.DownloadItem.Credentials,
                                                                DateTime.MinValue, null);

            // global cookie handling:
            reqParam.SetCookies = FeedSource.SetCookies;


            state = BackgroundDownloadManager.AsyncWebRequest.QueueRequest(reqParam,
                                                                           OnRequestStart,
                                                                           OnRequestComplete,
                                                                           OnRequestException,
                                                                           OnRequestProgress,
                                                                           priority);
        }
示例#2
0
        /// <summary>
        /// Synchronous download method implementation.
        /// </summary>
        /// <param name="task">The DownloadTask to process.</param>
        /// <param name="maxWaitTime">The maximum wait time.</param>
        public void Download(DownloadTask task, TimeSpan maxWaitTime)
        {
            currentTask = task;

            // If we resume way too often, just return
            if (CheckForResumeAndProceed(currentTask))
            {
                return;
            }

            WebResponse response = SyncWebRequest.GetResponse(HttpMethod.Get, task.DownloadItem.Enclosure.Url,
                                                              task.DownloadItem.Credentials,
                                                              FeedSource.UserAgentString(String.Empty),
                                                              task.DownloadItem.Proxy,
                                                              DateTime.MinValue,
                                                              null /* eTag */,
                                                              Convert.ToInt32(maxWaitTime.TotalSeconds),
                                                              null /* cookie */, null /* body */, null /* newsGatorAPIToken */);

            OnRequestComplete(new Uri(task.DownloadItem.Enclosure.Url), response.GetResponseStream(), response, null, null,
                              DateTime.MinValue, RequestResult.OK, 0);
        }
示例#3
0
 /// <summary>
 /// Build a full user agent string (template + <paramref name="userAgent"/> or get the global default one.
 /// </summary>
 /// <param name="userAgent">Can be null</param>
 /// <returns></returns>
 protected static string FullUserAgent(string userAgent)
 {
     return(FeedSource.UserAgentString(userAgent));
 }