setCookieHeader() public method

public setCookieHeader ( Uri uri, string header ) : void
uri System.Uri
header string
return void
Esempio n. 1
0
        /// <summary>
        /// Retrieve all of a users galleries
        /// </summary>
        /// <param name="cookieHeader">A String representation of the session id cookie</param>
        public void MyGalleries(String cookieHeader)
        {
            if (String.IsNullOrEmpty(cookieHeader))
            {
                throw new ArgumentException("Cookie Header cannot be null or empty");
            }

            CookieAwareWebClient client = this.CreateAndSetupWebClient();

            client.setCookieHeader(new Uri(BASE_URL), cookieHeader);
            client.DownloadStringCompleted += delegate(object sender, DownloadStringCompletedEventArgs e)
            {
                if (e.Error != null)
                {
                    Debug.WriteLine("MyGalleries operation failed: " + e.Error.Message);
                    this.TriggerGetItemsFailed(e.Error);
                    #if !WINDOWS_PHONE
                    client.Dispose();
                    #endif
                    return;
                }

                MyGalleriesResult result = JsonConvert.DeserializeObject <MyGalleriesResult>(e.Result);
                Debug.WriteLine("MyGalleries operation successful: " + result);
                this.TriggerMyGalleriesComplete(result);
                #if !WINDOWS_PHONE
                client.Dispose();
                #endif
            };

            try
            {
                ThreadPool.QueueUserWorkItem((object state) =>
                {
                    try
                    {
                        client.DownloadStringAsync(MY_GALLERIES_URL);
                    }
                    catch (WebException e)
                    {
                        Debug.WriteLine("Failed to access MyGalleries 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
            }
        }
Esempio n. 2
0
        /// <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
            }
        }
Esempio n. 3
0
        private CookieAwareWebClient CreateAndSetupWebClient(String cookieHeader)
        {
            CookieAwareWebClient client = new CookieAwareWebClient();
            #if !WINDOWS_PHONE
                if (this.Proxy != null)
                {
                    client.Proxy = this.Proxy;
                }
            #endif
            client.Headers["User-Agent"] = USER_AGENT;
            if(cookieHeader != null)
            {
                client.setCookieHeader(new Uri(BASE_URL), cookieHeader);
            }

            return client;
        }