// // 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, long userid, SizeDB sizeDB, ISizeImageUpdated notify) { if (notify == null) { var argNullEx = new ArgumentNullException ("notify"); Util.LogException("notifier is null!", argNullEx); throw argNullEx; } Uri url; lock (requestQueue) url = UrlStore.GetPicUrlFromId (id, userid, sizeDB); if (url == null) return; var pendReq = new Tuple<long, long, SizeDB>(id, userid, sizeDB); lock (requestQueue){ if (pendingRequests.ContainsKey (pendReq)){ Util.Log ("pendingRequest: added new listener for {0}", id); pendingRequests [pendReq].Add (notify); return; } var slot = new List<ISizeImageUpdated> (); slot.Add (notify); pendingRequests [pendReq] = 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); var imgRequest = new ImgRequest() { ID = id, UserId = userid, SizeDb = sizeDB }; requestQueue.Push (imgRequest); } else { ThreadPool.QueueUserWorkItem (delegate { try { StartPicDownload (pendReq, url); } catch (Exception e){ Util.LogException("QueueRequestForPicture", e); } }); } } }
public static UIImage RequestFullPicture (long id, long userid, SizeDB sizeDB, ISizeImageUpdated notify) { var pic = GetLocalFullPicture (id, userid, sizeDB); if (pic == null){ QueueRequestForPicture (id, userid, sizeDB, notify); // return default picture or null while waiting for the high-res version to come return null; } return pic; }