Ejemplo n.º 1
0
        public void GetCommentClient_DownloadStringCompleted(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("data") != null)
                {
                    commentList.Clear();

                    Debug.WriteLine("Comment = " + o.Root.Element("data").Value.ToString());

                    foreach (var v in o.Root.Element("data").Elements("items"))
                    {
                        CommentAmount++;
                        CommentItem item = new CommentItem();

                        item.Username = v.Element("display_name").Value;
                        item.ImagePath = v.Element("avatar").Value;
                        item.Comment = v.Element("message").Value;

                        CommentCount.Text = "จำนวนคอมเม้นท์ " + CommentAmount + " คอมเม้นท์";
                        commentList.Add(item);

                        //postData();
                    }

                    Debug.WriteLine("Comment List Count : " + commentList.Count());
                }
                else
                {
                    Debug.WriteLine("GetComment : No Data Comment !");
                    CommentCount.Text = "จำนวนคอมเม้นท์ 0 คอมเม้นท์";
                    commentList.Clear();
                    //this.commentList.Clear();
                    //commentListBox.ItemsSource = null;
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine("InCinemaDetailPage.xaml.cs : GetCommentWebClient_DownloadStringCompleted ; " + ex.Message);
            }

            //SetLoadingPanelVisibility(false);
        }
Ejemplo n.º 2
0
        public void GetResponsetStreamCallback(IAsyncResult callbackResult)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {

                HttpWebRequest request = (HttpWebRequest)callbackResult.AsyncState;
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(callbackResult);
                using (StreamReader httpWebStreamReader = new StreamReader(response.GetResponseStream()))
                {
                    string result = httpWebStreamReader.ReadToEnd();
                    //For debug: show results
                    Debug.WriteLine("Add comment result" + result);

                    if (result != null)
                    {

                        CommentItem item = new CommentItem();

                        item.Username = Username;
                        item.ImagePath = UserImage;
                        item.Comment = CommentText;

                        //Clear TextBox Comment
                        TextBoxName.Text = "";

                        MessageBox.Show("ขอบคุณสำหรับข้อความคะ");
                        CommentAmount += 1;
                        CommentCount.Text = "จำนวนคอมเม้นท์ " + (CommentAmount) + " คอมเม้นท์";
                        this.commentList.Insert(0, item);

                    }
                }

                //SetLoadingPanelVisibility(false);

            });
        }