BiasedBit.MinusEngine.MinusApi.GetItems C# (CSharp) Метод

GetItems() публичный Метод

Retrieve all items in a gallery, along with some other info (url and title).
public GetItems ( String cookieHeader, String galleryReaderId ) : void
cookieHeader String
galleryReaderId String The reader id (public) of the gallery.
Результат void
        public void GetItems(String cookieHeader, String galleryReaderId)
        {
            if (String.IsNullOrEmpty(galleryReaderId))
            {
                throw new ArgumentException("Gallery Reader Id cannot be null or empty");
            }

            WebClient client = this.CreateAndSetupWebClient(cookieHeader);
            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
            }
        }

Usage Example

Пример #1
0
        /// <summary>
        /// This method
        /// </summary>
        private static void TestGetItems()
        {
            // create the API
            MinusApi api = new MinusApi(API_KEY);

            // setup the success handler for GetItems operation
            api.GetItemsComplete += delegate(MinusApi sender, GetItemsResult result)
            {
                Console.WriteLine("Gallery items successfully retrieved!\n---");
                Console.WriteLine("Read-only URL: " + result.ReadonlyUrl);
                Console.WriteLine("Title: " + result.Title);
                Console.WriteLine("Items:");
                foreach (String item in result.Items)
                {
                    Console.WriteLine(" - " + item);
                }
            };

            // setup the failure handler for the GetItems operation
            api.GetItemsFailed += delegate(MinusApi sender, Exception e)
            {
                // don't do anything else...
                Console.WriteLine("Failed to get items from gallery...\n" + e.Message);
            };

            // trigger the GetItems operation - notice the extra "m" in there.
            // while the REAL reader id is "vgkRZC", the API requires you to put the extra "m" in there
            api.GetItems("mvgkRZC");
        }