public static UIImage RequestImage(Uri uri, IImageUpdated notify) { UIImage ret; lock (cache){ ret = cache [uri]; if (ret != null) { return(ret); } } lock (requestQueue){ if (pendingRequests.ContainsKey(uri)) { return(null); } } string picfile = PicDir + md5(uri.AbsoluteUri); if (File.Exists(picfile)) { ret = UIImage.FromFileUncached(picfile); if (ret != null) { lock (cache) cache [uri] = ret; return(ret); } } QueueRequest(uri, picfile, notify); return(null); }
public bool RequestImage(string url, IImageUpdated receiver) { var local = RequestLocalImage(url); if (local != null) { receiver.UpdatedImage(url, local); return(true); } if (pendingRequests.ContainsKey(url)) { pendingRequests[url].Add(receiver); } else { pendingRequests.Add(url, new List <IImageUpdated>() { receiver }); } NSUrlRequest req = new NSUrlRequest(new NSUrl(url), NSUrlRequestCachePolicy.ReturnCacheDataElseLoad, 10); new UrlConnection("img" + url, req, (UIImage img) => { var surl = url; cache[surl] = img; var imgreq = pendingRequests[surl]; foreach (var v in imgreq) { v.UpdatedImage(surl, img); } pendingRequests.Remove(surl); }); return(false); }
static void QueueRequest(Uri uri, IImageUpdated notify) { if (notify == null) { throw new ArgumentNullException("notify"); } lock (requestQueue){ if (pendingRequests.ContainsKey(uri)) { //Util.Log ("pendingRequest: added new listener for {0}", id); pendingRequests [uri].Add(notify); return; } var slot = new List <IImageUpdated> (4); slot.Add(notify); pendingRequests [uri] = slot; if (picDownloaders >= MaxRequests) { requestQueue.Push(uri); } else { ThreadPool.QueueUserWorkItem(delegate { try { StartPicDownload(uri); } catch (Exception e) { Console.WriteLine(e); } }); } } }
public bool RequestImage(string url, IImageUpdated receiver) { var local = RequestLocalImage(url); if (local != null) { receiver.UpdatedImage(url, local); return true; } if (pendingRequests.ContainsKey(url)){ pendingRequests[url].Add(receiver); } else { pendingRequests.Add(url, new List<IImageUpdated>(){receiver}); } NSUrlRequest req = new NSUrlRequest(new NSUrl(url), NSUrlRequestCachePolicy.ReturnCacheDataElseLoad, 10); new UrlConnection("img"+url, req, (UIImage img)=>{ var surl = url; cache[surl] = img; var imgreq = pendingRequests[surl]; foreach (var v in imgreq) v.UpdatedImage(surl, img); pendingRequests.Remove(surl); }); return false; }
/// <summary> /// Requests an image to be loaded using the default image loader /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> public static UIImage DefaultRequestImage(Uri uri, IImageUpdated notify, IDictionary <string, string> headers = null) { if (DefaultLoader == null) { DefaultLoader = new ImageLoader(50, 4 * 1024 * 1024); } return(DefaultLoader.RequestImage(uri, notify, headers)); }
/// <summary> /// Requests an image to be loaded using the default image loader /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> public static UIImage DefaultRequestImage(Uri uri, IImageUpdated notify) { if (DefaultLoader == null) { DefaultLoader = new ImageLoader(50, 4 * 1024 * 1024); } return(DefaultLoader.RequestImage(uri, notify)); }
/// <summary> /// Requests an image to be loaded using the default image loader /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> public static UIImage DefaultRequestImage(string uri, IImageUpdated notify, Action <HttpWebRequest> webRequestInit = null) { if (DefaultLoader == null) { DefaultLoader = new ImageDownloader(50, 4 * 1024 * 1024); } return(DefaultLoader.RequestImage(uri, notify, webRequestInit)); }
public static UIImage RequestImage(long id, string optionalUrl, IImageUpdated notify) { var pic = GetImage(id); if (pic == null) { QueueRequestForImage(id, optionalUrl, notify); return(DefaultImage); } return(pic); }
/// <summary> /// Requests an image to be loaded from the network /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> public UIImage RequestImage(Uri uri, IImageUpdated notify) { try { UIImage ret; lock (cache){ ret = cache [uri]; if (ret != null) { return(ret); } } lock (requestQueue){ if (pendingRequests.ContainsKey(uri)) { if (!pendingRequests [uri].Contains(notify)) { pendingRequests [uri].Add(notify); } return(null); } } string picfile = uri.IsFile ? uri.LocalPath : PicDir + md5(uri.AbsoluteUri); if (File.Exists(picfile)) { ret = UIImage.FromFile(picfile); if (ret != null) { lock (cache) cache [uri] = ret; return(ret); } } if (uri.IsFile) { return(null); } QueueRequest(uri, notify); return(null); } catch (Exception e) { Debug.WriteLine("Unable to request image: " + e.Message); return(null); } }
/// <summary> /// Requests an image to be loaded using the default image loader /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a Drawable. /// </returns> public static Drawable /*UIImage*/ DefaultRequestImage(Uri uri, IImageUpdated notify) { var maxMemory = (int)(Java.Lang.Runtime.GetRuntime().MaxMemory() / 1024); // Use 1/8th of the available memory for this memory cache. int cacheSize = maxMemory / 8; //_memoryCache = new MemoryLimitedLruCache(cacheSize); if (DefaultLoader == null) { Console.WriteLine("cache size limieted" + cacheSize.ToString()); //DefaultLoader = new ImageLoader(5, 4 * 1024 * 1024); DefaultLoader = new ImageLoader(20, cacheSize); } return(DefaultLoader.RequestImage(uri, notify)); }
// // Requests that the picture for "id" be downloaded, the optional url prevents // one lookup, it can be null if not known // public static void QueueRequestForPicture(long id, string optionalUrl, IImageUpdated notify) { if (notify == null) { throw new ArgumentNullException("notify"); } Uri url; lock (requestQueue) url = GetPicUrlFromId(id, optionalUrl); if (url == null) { return; } lock (requestQueue){ if (pendingRequests.ContainsKey(id)) { //Util.Log ("pendingRequest: added new listener for {0}", id); pendingRequests [id].Add(notify); return; } var slot = new List <IImageUpdated> (4); slot.Add(notify); pendingRequests [id] = slot; #if DEBUGIMAGE pendingTimes [id] = DateTime.UtcNow.Ticks; #endif if (picDownloaders > MaxRequests) { Util.Log("Queuing Image request because {0} >= {1} {2}", requestQueue.Count, MaxRequests, picDownloaders); requestQueue.Push(id); } else { ThreadPool.QueueUserWorkItem(delegate { try { StartPicDownload(id, url); } catch (Exception e) { Console.WriteLine(e); } }); } } }
/// <summary> /// Requests an image to be loaded from the network /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a Drawable. /// </returns> public Drawable /*UIImage*/ RequestImage(Uri uri, IImageUpdated notify) { LogDebug("..requ " + ImageName(uri.AbsoluteUri)); Drawable /*UIImage*/ ret; lock (cache) { ret = cache[uri]; if (ret != null) { return(ret); } } lock (requestQueue) { if (pendingRequests.ContainsKey(uri)) { return(null); } } string picfile = uri.IsFile ? uri.LocalPath : PicDir + md5(uri.AbsoluteUri); if (File.Exists(picfile)) { ret = Drawable.CreateFromPath(picfile); /* UIImage.FromFileUncached(picfile);*/ if (ret != null) { lock (cache) cache[uri] = ret; return(ret); } } if (uri.IsFile) // so there is no point queueing a request for it :) { return(null); } if (notify != null) // if notify is null, we won't bother retrieving again... assume this is a hit-and-hope query { QueueRequest(uri, picfile, notify); } return(null); }
/// <summary> /// Requests an image to be loaded from the network /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> public UIImage RequestImage(Uri uri, IImageUpdated notify, IDictionary <string, string> headers = null) { UIImage ret; lock (cache) { ret = cache[uri]; if (ret != null) { return(ret); } } lock (requestQueue) { if (pendingRequests.ContainsKey(uri)) { return(null); } } string picfile = uri.IsFile ? uri.LocalPath : PicDir + md5(uri.AbsoluteUri); if (File.Exists(picfile)) { ret = UIImage.FromFileUncached(picfile); if (ret != null) { lock (cache) { cache[uri] = ret; } return(ret); } } if (uri.IsFile) { return(null); } QueueRequest(uri, picfile, notify, headers); return(null); }
// // Requests that the picture for "id" be downloaded, the optional url prevents // one lookup, it can be null if not known // public static void QueueRequestForImage(long id, string optionalUrl, IImageUpdated notify) { if (notify == null) { throw new ArgumentNullException("notify"); } Uri url = GetImageUrlFromId(id, optionalUrl); if (url == null) { return; } if (pendingRequests.ContainsKey(id)) { pendingRequests [id].Add(notify); } else { var slot = new List <IImageUpdated>(); slot.Add(notify); pendingRequests.Add(id, slot); } if (ThreadCount >= MaxRequests) { lock (requestQueue) { requestQueue.Enqueue(id); } } else { ThreadPool.QueueUserWorkItem(delegate { try { StartImageDownload(id, url); } catch (Exception e) { Console.WriteLine(e); } }); } }
/// <summary> /// Requests an image to be loaded from the network /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> private UIImage RequestImage(string uri, IImageUpdated notify, Action <HttpWebRequest> webRequestInit) { UIImage ret; lock (cache){ ret = cache [uri]; if (ret != null) { return(ret); } } lock (requestQueue){ if (pendingRequests.ContainsKey(uri)) { if (!pendingRequests [uri].Contains(notify)) { pendingRequests [uri].Add(notify); } return(null); } } string picfile = PicDir + md5(uri); if (File.Exists(picfile)) { ret = UIImage.FromFile(picfile); if (ret != null) { lock (cache) cache [uri] = ret; return(ret); } } QueueRequest(uri, notify, webRequestInit); return(null); }
// // Fetches a profile picture, the ID is used internally public static UIImage RequestProfilePicture(long id, string optionalUrl, IImageUpdated notify) { var pic = GetLocalProfilePicture(id); if (pic == null) { QueueRequestForPicture(id, optionalUrl, notify); // return low-res version of the picture while waiting for the high-res version to come if (id < 0) { pic = GetLocalProfilePicture(-id); } if (pic != null) { return(pic); } return(DefaultImage); } return(pic); }
static void QueueRequest(Uri uri, string target, IImageUpdated notify) { if (notify == null) { throw new ArgumentNullException("notify"); } lock (requestQueue) { if (pendingRequests.ContainsKey(uri)) { LogDebug("-------- pendingRequest: added new listener for " + ImageName(uri.AbsoluteUri)); pendingRequests[uri].Add(notify); return; } var slot = new List <IImageUpdated>(4); slot.Add(notify); pendingRequests[uri] = slot; if (picDownloaders >= MaxRequests) { requestQueue.Push(uri); LogDebug("----push " + ImageName(uri.AbsoluteUri)); } else { ThreadPool.QueueUserWorkItem(delegate { try { LogDebug("----dwnl " + ImageName(uri.AbsoluteUri)); StartPicDownload(uri, target); } catch (Exception e) { LogDebug(e.Message); } }); } } }
public static UIImage RequestProfilePicture(string id, string optionalUrl, IImageUpdated notify) { return RequestProfilePicture ( id, optionalUrl, false, notify); }
// // Requests that the picture for "id" be downloaded, the optional url prevents // one lookup, it can be null if not known // public static void QueueRequestForPicture(string id, string optionalUrl, IImageUpdated notify) { //if (notify == null) // throw new ArgumentNullException ("notify"); Uri url; lock (requestQueue) url = GetPicUrlFromId (id, optionalUrl); if (url == null) return; lock (requestQueue){ if (pendingRequests.ContainsKey (id)){ pendingRequests [id].Add (notify); return; } var slot = new List<IImageUpdated> (4); slot.Add (notify); pendingRequests [id] = slot; if (pendingRequests.Count >= MaxRequests){ requestQueue.Enqueue (id); } else { ThreadPool.QueueUserWorkItem (delegate { try { StartPicDownload (id, url); } catch (Exception e){ Console.WriteLine (e); // lock (queuedUpdates){ queuedUpdates.Add (id); // If this is the first queued update, must notify if (queuedUpdates.Count == 1) nsDispatcher.BeginInvokeOnMainThread (NotifyImageListeners); } // } }); } } }
/// <summary> /// Requests an image to be loaded from the network /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> public UIImage RequestImage (Uri uri, IImageUpdated notify) { UIImage ret; lock (cache){ ret = cache [uri]; if (ret != null) return ret; } lock (requestQueue){ if (pendingRequests.ContainsKey (uri)) { if (!pendingRequests [uri].Contains(notify)) pendingRequests [uri].Add (notify); return null; } } string picfile = uri.IsFile ? uri.LocalPath : PicDir + md5 (uri.AbsoluteUri); if (File.Exists (picfile)){ ret = UIImage.FromFile (picfile); if (ret != null){ lock (cache) cache [uri] = ret; return ret; } } if (uri.IsFile) return null; QueueRequest (uri, notify); return null; }
static void QueueRequest (Uri uri, IImageUpdated notify) { if (notify == null) throw new ArgumentNullException ("notify"); lock (requestQueue){ if (pendingRequests.ContainsKey (uri)){ //Util.Log ("pendingRequest: added new listener for {0}", id); pendingRequests [uri].Add (notify); return; } var slot = new List<IImageUpdated> (4); slot.Add (notify); pendingRequests [uri] = slot; if (picDownloaders >= MaxRequests) requestQueue.Push (uri); else { ThreadPool.QueueUserWorkItem (delegate { try { StartPicDownload (uri); } catch (Exception e){ Console.WriteLine (e); } }); } } }
public static UIImage RequestImage (long id, string optionalUrl, IImageUpdated notify) { var pic = GetImage (id); if (pic == null){ QueueRequestForImage (id, optionalUrl, notify); return DefaultImage; } return pic; }
/// <summary> /// Requests an image to be loaded using the default image loader /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> public static UIImage DefaultRequestImage (Uri uri, IImageUpdated notify) { if (DefaultLoader == null) DefaultLoader = new ImageLoader (50, 4*1024*1024); return DefaultLoader.RequestImage (uri, notify); }
/// <summary> /// Requests an image to be loaded using the default image loader /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a Drawable. /// </returns> public static Drawable /*UIImage*/ DefaultRequestImage(Uri uri, IImageUpdated notify) { var maxMemory = (int)(Java.Lang.Runtime.GetRuntime().MaxMemory() / 1024); // Use 1/8th of the available memory for this memory cache. int cacheSize = maxMemory /8; //_memoryCache = new MemoryLimitedLruCache(cacheSize); if (DefaultLoader == null) { Console.WriteLine ("cache size limieted" + cacheSize.ToString ()); //DefaultLoader = new ImageLoader(5, 4 * 1024 * 1024); DefaultLoader = new ImageLoader(20, cacheSize); } return DefaultLoader.RequestImage(uri, notify); }
/// <summary> /// Requests an image to be loaded from the network /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> public UIImage RequestImage(Uri uri, IImageUpdated notify, IDictionary<string, string> headers = null) { UIImage ret; lock (cache) { ret = cache[uri]; if (ret != null) { return ret; } } lock (requestQueue) { if (pendingRequests.ContainsKey(uri)) { return null; } } string picfile = uri.IsFile ? uri.LocalPath : PicDir + md5(uri.AbsoluteUri); if (File.Exists(picfile)) { ret = UIImage.FromFileUncached(picfile); if (ret != null) { lock (cache) { cache[uri] = ret; } return ret; } } if (uri.IsFile) { return null; } QueueRequest(uri, picfile, notify, headers); return null; }
// // Requests that the picture for "id" be downloaded, the optional url prevents // one lookup, it can be null if not known // public static void QueueRequestForPicture(long id, string optionalUrl, IImageUpdated notify) { if (notify == null) throw new ArgumentNullException ("notify"); Uri url; lock (requestQueue) url = GetPicUrlFromId (id, optionalUrl); if (url == null) return; lock (requestQueue){ if (pendingRequests.ContainsKey (id)){ //Util.Log ("pendingRequest: added new listener for {0}", id); pendingRequests [id].Add (notify); return; } var slot = new List<IImageUpdated> (4); slot.Add (notify); pendingRequests [id] = slot; #if DEBUGIMAGE pendingTimes [id] = DateTime.UtcNow.Ticks; #endif if (picDownloaders > MaxRequests){ Util.Log ("Queuing Image request because {0} >= {1} {2}", requestQueue.Count, MaxRequests, picDownloaders); requestQueue.Push (id); } else { ThreadPool.QueueUserWorkItem (delegate { try { StartPicDownload (id, url); } catch (Exception e){ Console.WriteLine (e); } }); } } }
// // Fetches a profile picture, the ID is used internally public static UIImage RequestProfilePicture(long id, string optionalUrl, IImageUpdated notify) { var pic = GetLocalProfilePicture (id); if (pic == null){ QueueRequestForPicture (id, optionalUrl, notify); // return low-res version of the picture while waiting for the high-res version to come if (id < 0) pic = GetLocalProfilePicture (-id); if (pic != null) return pic; return DefaultImage; } return pic; }
// // Fetches a profile picture, the ID is used internally public static UIImage RequestProfilePicture(string id, string optionalUrl,bool replaceFile, IImageUpdated notify) { UIImage pic = replaceFile ? null : GetLocalProfilePicture (id); if (pic == null){ QueueRequestForPicture (id, optionalUrl, notify); //if (id < 0) // pic = GetLocalProfilePicture (-id); if (pic != null) return pic; return DefaultImage; } return pic; }
/// <summary> /// Requests an image to be loaded using the default image loader /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> public static UIImage DefaultRequestImage(string uri, IImageUpdated notify, Action<HttpWebRequest> webRequestInit = null) { if (DefaultLoader == null) DefaultLoader = new ImageDownloader (50, 4*1024*1024); return DefaultLoader.RequestImage (uri, notify, webRequestInit); }
/// <summary> /// Requests an image to be loaded from the network /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> private UIImage RequestImage(string uri, IImageUpdated notify, Action<HttpWebRequest> webRequestInit) { UIImage ret; lock (cache){ ret = cache [uri]; if (ret != null) return ret; } lock (requestQueue){ if (pendingRequests.ContainsKey (uri)) { if (!pendingRequests [uri].Contains(notify)) pendingRequests [uri].Add (notify); return null; } } string picfile = PicDir + md5 (uri); if (File.Exists (picfile)){ ret = UIImage.FromFile (picfile); if (ret != null){ lock (cache) cache [uri] = ret; return ret; } } QueueRequest (uri, notify, webRequestInit); return null; }
// // Fetches a profile picture, the ID is used internally public static UIImage RequestProfilePicture(long id, string optionalUrl, IImageUpdated notify) { var pic = GetLocalProfilePicture (id); if (pic == null){ QueueRequestForPicture (id, optionalUrl, notify); if (id < 0) pic = GetLocalProfilePicture (-id); if (pic != null) return pic; return DefaultImage; } return pic; }
/// <summary> /// Requests an image to be loaded from the network /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a Drawable. /// </returns> public Drawable /*UIImage*/ RequestImage(Uri uri, IImageUpdated notify) { LogDebug("..requ " + ImageName(uri.AbsoluteUri)); Drawable /*UIImage*/ ret; lock (cache) { ret = cache[uri]; if (ret != null) return ret; } lock (requestQueue) { if (pendingRequests.ContainsKey(uri)) return null; } string picfile = uri.IsFile ? uri.LocalPath : PicDir + md5(uri.AbsoluteUri); if (File.Exists(picfile)) { ret = Drawable.CreateFromPath(picfile); /* UIImage.FromFileUncached(picfile);*/ if (ret != null) { lock (cache) cache[uri] = ret; return ret; } } if (uri.IsFile) // so there is no point queueing a request for it :) return null; if (notify != null) // if notify is null, we won't bother retrieving again... assume this is a hit-and-hope query QueueRequest(uri, picfile, notify); return null; }
/// <summary> /// Requests an image to be loaded using the default image loader /// </summary> /// <param name="uri"> /// The URI for the image to load /// </param> /// <param name="notify"> /// A class implementing the IImageUpdated interface that will be invoked when the image has been loaded /// </param> /// <returns> /// If the image has already been downloaded, or is in the cache, this will return the image as a UIImage. /// </returns> public static UIImage DefaultRequestImage(Uri uri, IImageUpdated notify, IDictionary<string, string> headers = null) { if (DefaultLoader == null) { DefaultLoader = new ImageLoader(50, 4 * 1024 * 1024); } return DefaultLoader.RequestImage(uri, notify, headers); }
static void QueueRequest(Uri uri, string target, IImageUpdated notify) { if (notify == null) throw new ArgumentNullException("notify"); lock (requestQueue) { if (pendingRequests.ContainsKey(uri)) { LogDebug("-------- pendingRequest: added new listener for " + ImageName(uri.AbsoluteUri)); pendingRequests[uri].Add(notify); return; } var slot = new List<IImageUpdated>(4); slot.Add(notify); pendingRequests[uri] = slot; if (picDownloaders >= MaxRequests) { requestQueue.Push(uri); LogDebug("----push " + ImageName(uri.AbsoluteUri)); } else { ThreadPool.QueueUserWorkItem(delegate { try { LogDebug("----dwnl " + ImageName(uri.AbsoluteUri)); StartPicDownload(uri, target); } catch (Exception e) { LogDebug(e.Message); } }); } } }
static void QueueRequest(Uri uri, string target, IImageUpdated notify, IDictionary<string, string> headers = null) { if (notify == null) { throw new ArgumentNullException("notify"); } lock (requestQueue) { if (pendingRequests.ContainsKey(uri)) { //Util.Log ("pendingRequest: added new listener for {0}", id); pendingRequests[uri].Add(notify); return; } var slot = new List<IImageUpdated>(4); slot.Add(notify); pendingRequests[uri] = slot; if (requestQueue.Count >= MaxRequests) { requestQueue.Push(uri); } else { ThreadPool.QueueUserWorkItem(state => { try { StartPicDownload(uri, target, headers); } catch (Exception e) { Console.WriteLine(e); } }); } } }
// // Requests that the picture for "id" be downloaded, the optional url prevents // one lookup, it can be null if not known // public static void QueueRequestForImage (long id, string optionalUrl, IImageUpdated notify) { if (notify == null) throw new ArgumentNullException ("notify"); Uri url = GetImageUrlFromId (id, optionalUrl); if (url == null) return; if (pendingRequests.ContainsKey (id)){ pendingRequests [id].Add (notify); } else { var slot = new List<IImageUpdated>(); slot.Add (notify); pendingRequests.Add(id,slot); } if (ThreadCount >= MaxRequests){ lock (requestQueue) { requestQueue.Enqueue (id); } } else { ThreadPool.QueueUserWorkItem (delegate { try { StartImageDownload (id, url); } catch (Exception e){ Console.WriteLine (e); } }); } }