private void TriggerCreateGalleryComplete(CreateGalleryResult result) { if (this.CreateGalleryComplete != null) { this.CreateGalleryComplete.Invoke(this, result); } }
/// <summary> /// Creates an empty new gallery. /// </summary> public void CreateGallery(String cookieHeader) { CookieAwareWebClient client = this.CreateAndSetupWebClient(); if (!String.IsNullOrEmpty(cookieHeader)) { client.setCookieHeader(new Uri(BASE_URL), cookieHeader); } client.DownloadStringCompleted += delegate(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) { Debug.WriteLine("CreateGallery operation failed: " + e.Error.Message); this.TriggerCreateGalleryFailed(e.Error); #if !WINDOWS_PHONE client.Dispose(); #endif return; } CreateGalleryResult result = JsonConvert.DeserializeObject <CreateGalleryResult>(e.Result); Debug.WriteLine("CreateGallery operation successful: " + result); this.TriggerCreateGalleryComplete(result); #if !WINDOWS_PHONE client.Dispose(); #endif }; try { ThreadPool.QueueUserWorkItem((object state) => { try { client.DownloadStringAsync(CREATE_GALLERY_URL); } catch (WebException e) { Debug.WriteLine("Failed to access CreateGallery API: " + e.Message); this.TriggerCreateGalleryFailed(e); #if !WINDOWS_PHONE client.Dispose(); #endif } }); } catch (Exception e) { Debug.WriteLine("Failed to submit task to thread pool: " + e.Message); this.TriggerCreateGalleryFailed(e); #if !WINDOWS_PHONE client.Dispose(); #endif } }