示例#1
0
 public DownloadTask(Downloader downloader, Uri url, Action<DownloadResult> callback, DownloadOptions options, string key, DownloadResult result)
 {
     this.downloader = downloader;
     this.Url = url;
     this.Callback = callback;
     this.Options = options;
     this.Key = key;
     this.Result = result;
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the DownloadOptions class.
 /// </summary>
 /// <param name="config">The existing configuration to initialize this instance with.</param>
 public DownloadOptions(DownloadOptions config)
 {
     if (config != null)
     {
         this.Credentials = config.Credentials;
         this.Headers = config.Headers.Clone();
         this.UserAgent = config.UserAgent;
     }
     else
     {
         this.Headers = new WebHeaderCollection();
         this.UserAgent = DownloadOptions.DefaultUserAgent;
     }
 }
示例#3
0
        /// <summary>
        /// Initiates a cached + queued download operation.
        /// </summary>
        /// <param name="url">The URL of the resource to download.</param>
        /// <param name="callback">A function to call when the operation is complete.</param>
        /// <param name="options">The options to use when downloading the resource.</param>
        /// <returns>The operation's result.</returns>
        public DownloadResult Download(Uri url, Action<DownloadResult> callback, DownloadOptions options)
        {
            if (this.disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            if (url == null)
            {
                throw new ArgumentNullException("url", "url cannot be null.");
            }

            DownloadResult result;
            string key = url.ToString().ToUpperInvariant();
            byte[] content = this.cache.GetContent(key);

            if (content != null)
            {
                result = new DownloadResult(content, true);
            }
            else
            {
                result = new DownloadResult();
                options = new DownloadOptions(options);
                this.Enqueue(new DownloadTask(this, url, callback, options, key, result));
            }

            return result;
        }