public static PurchasedList GetFromServer(string url) { try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Headers.Add(HttpRequestHeader.Authorization, Shared._AUTHORIATION); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (HttpStatusCode.OK != response.StatusCode) { MessageManager.INSTANCE.ShowImageMessage(Messages.ERROR_UNABLE_TO_OBTAIN_BOOK_LIST); } else { StreamReader reader = new StreamReader(response.GetResponseStream()); string jsonResponse = reader.ReadToEnd(); PurchasedList newList = new PurchasedList(); newList.FromJSON(jsonResponse); return(newList); } } catch (Exception e) { MessageManager.INSTANCE.ShowImageMessage(Messages.ERROR_NETWORK); } return(null); }
public void GetFromServer(string url) { // 1. Get purchased books. Shared._PURCHASED = PurchasedList.GetFromServer(url); if (null == Shared._PURCHASED || 0 == Shared._PURCHASED.Purchased.Count) { return; } // 2. Get information for each book. Shared._BOOK_INFO = Book.GetBooksFromServer(_URL_BASE, Shared._PURCHASED.Purchased); // 3. Remove old display items. while (0 < ContentPanel.transform.childCount) { Transform child = ContentPanel.transform.GetChild(0); child.transform.parent = null; Destroy(child.gameObject); } // 4. Sort books. Dropdown sortPreference = SortOrder.GetComponent <Dropdown>(); Shared._PURCHASED.SortByKey(); if (1 == sortPreference.value) { Shared._PURCHASED.SortByDate(); } // 5. Show books. foreach (Purchased purchased in Shared._PURCHASED.Purchased) { string bookKey = purchased.MakeKey(); if (!Shared._BOOK_INFO.ContainsKey(bookKey)) { Debug.Log("Not found: " + bookKey); continue; } Book book = Shared._BOOK_INFO[bookKey]; ImageHelper imageHelper = new ImageHelper(); GameObject newCover = Instantiate(ListItemPrefab) as GameObject; PurchasedController controller = newCover.GetComponent <PurchasedController>(); controller.Title.text = book.title + " #" + book.issue; controller.Id = book.id; controller.Issue = book.issue; newCover.transform.SetParent(ContentPanel.transform, false); newCover.transform.localScale = Vector3.one; string coverURL = _URL_BASE + book.id + "/" + book.issue + "/" + book.pages[0]; RawImage image = controller.Cover.GetComponent <RawImage>(); StartCoroutine(imageHelper.SetImageFromURL(image, coverURL)); } }