private void TriggerGetItemsComplete(GetItemsResult result) { if (this.GetItemsComplete != null) { this.GetItemsComplete.Invoke(this, result); } }
/// <summary> /// Retrieve all items in a gallery, along with some other info (url and title). /// </summary> /// <param name="galleryReaderId">The reader id (public) of the gallery.</param> public void GetItems(String galleryReaderId) { if (String.IsNullOrEmpty(galleryReaderId)) { throw new ArgumentException("Gallery Reader Id cannot be null or empty"); } WebClient client = this.CreateAndSetupWebClient(); client.DownloadStringCompleted += delegate(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { Debug.WriteLine("GetItems operation failed: " + e.Error.Message); this.TriggerGetItemsFailed(e.Error); #if !WINDOWS_PHONE client.Dispose(); #endif return; } GetItemsResult result = JsonConvert.DeserializeObject <GetItemsResult>(e.Result); Debug.WriteLine("GetItems operation successful: " + result); this.TriggerGetItemsComplete(result); #if !WINDOWS_PHONE client.Dispose(); #endif }; try { ThreadPool.QueueUserWorkItem((object state) => { try { client.DownloadStringAsync(new Uri(GET_ITEMS_URL + galleryReaderId)); } catch (WebException e) { Debug.WriteLine("Failed to access GetItems API: " + e.Message); this.TriggerGetItemsFailed(e); #if !WINDOWS_PHONE client.Dispose(); #endif } }); } catch (Exception e) { Debug.WriteLine("Failed to submit task to thread pool: " + e.Message); this.TriggerGetItemsFailed(e); #if !WINDOWS_PHONE client.Dispose(); #endif } }