Exemple #1
0
        public void GetList_Completed(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                if (e.Error != null)
                {
                    throw new Exception(e.Error.Message);
                }
                var o = XDocument.Parse(e.Result);

                if (o.Root.Element("status_code").Value == "200")
                {
                    total = XmlValueParser.ParseInteger(o.Root.Element("album").Element("total"));

                    foreach (var v in o.Descendants("item"))
                    {
                        if (v.Element("album_id") != null)
                        {
                            AlbumItem item = new AlbumItem();
                            item.album_id    = v.Element("album_id").Value;
                            item.album_title = v.Element("album_title").Value;

                            List.Add(item);
                        }
                    }
                }
                else
                {
                    throw new Exception("code is " + o.Root.Element("status_code").Value);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("AlbumPage.xaml.cs : GetList_Completed ; " + ex.Message);
                MessageBox.Show("เกิดเหตุขัดข้อง กรุณาลองใหม่อีกครั้งภายหลัง");
                this.NavigationService.GoBack();
                NavigationService.Navigate(new Uri("/MainPage.xaml?Refresh=true", UriKind.Relative));
            }

            SetLoadingEpisodeListVisibility(false);
        }
Exemple #2
0
        private void GetList_Completed(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                if (e.Error != null)
                {
                    throw new Exception(e.Error.Message);
                }
                //----------
                XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);
                if (xdoc.Root == null)
                {
                    throw new Exception("Root is null");
                }

                if (xdoc.Root.Element("status_code") == null)
                {
                    throw new Exception("status_code is null");
                }

                if (xdoc.Root.Element("data") == null)
                {
                    throw new Exception("data is null");
                }

                if (xdoc.Root.Element("data").Element("contents") == null)
                {
                    throw new Exception("data/contents is null");
                }
                //----------
                if (xdoc.Root.Element("status_code").Value != "200")
                {
                    throw new Exception("code is " + xdoc.Root.Element("status_code").Value + " ~ " + xdoc.Root.Element("status_txt").Value);
                }
                else
                {
                    string tag = "";

                    if ((sender as WebClient).Headers["id"] == "liveTv")
                    {
                        tag = "entry";// item
                        AddChannelAllList.Clear();
                    }
                    //-----
                    var list = xdoc.Root.Element("data").Element("contents").Elements(tag);
                    foreach (var item in list)
                    {
                        MediaHighlightItem tmp_item = new MediaHighlightItem();

                        //parse
                        tmp_item.content_id    = XmlValueParser.ParseInteger(item.Element("content_id"));
                        tmp_item.channel_name  = XmlValueParser.ParseString(item.Element("channel_name"));
                        tmp_item.thumbnail     = XmlValueParser.ParseString(item.Element("thumbnail"));
                        tmp_item.thumbnail_App = XmlValueParser.ParseString(item.Element("thumbnail_app"));
                        tmp_item.category      = XmlValueParser.ParseString(item.Element("category"));
                        tmp_item.rating        = XmlValueParser.ParseString(item.Element("rating"));
                        tmp_item.view          = XmlValueParser.ParseString(item.Element("view"));
                        tmp_item.Share_url     = XmlValueParser.ParseString(item.Element("share_url"));

                        if ((sender as WebClient).Headers["id"] == "liveTv")
                        {
                            selected = false;

                            for (int i = 0; i < (Application.Current as App).FavoriteIndexList.Count; i++)
                            {
                                if ((Application.Current as App).FavoriteIndexList[i].content_id.Equals(tmp_item.content_id))
                                {
                                    selected = true;
                                }
                            }

                            if (selected)
                            {
                                tmp_item.PicSelected = "Assets/btn_select_active.png";
                                SelectCount++;
                            }
                            else
                            {
                                tmp_item.PicSelected = "Assets/btn_select.png";
                            }
                            AddChannelAllList.Add(tmp_item);
                        }
                    }
                    PanoramaItem.Header = "เพิ่มช่องโปรด (" + SelectCount + "/20)";
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("HomePage : MediaHighlightItemList_DownloadStringCompleted ; " + ex.Message);
            }
            HideProgressIndicator();
        }