private void ApplicationBarIconButton_Click(object sender, EventArgs e) { if (pivot.SelectedIndex != 0) { pivot.SelectedIndex = 0; } pageToken = AppGlobalStatic.ConvertLocalToTimestamp(DateTime.Now).ToString(); GetUserTimeline(); }
private void SendNoteCallback(IAsyncResult asynchronousResult) { try { HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response; // End the get response operation response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult); response.Headers[HttpRequestHeader.ContentType] = "application/json; charset=UTF-8"; Stream streamResponse = response.GetResponseStream(); StreamReader streamReader = new StreamReader(streamResponse); var Response = streamReader.ReadToEnd(); dynamic json = JsonConvert.DeserializeObject(Response); LoveNote = new Trend(); if (json != null) { LoveNote.ID = (string)json["id"]; LoveNote.IsLoveNotes = (bool)json["isLoveNotes"]; LoveNote.Timestamp = (string)json["timestamp"]; if (LoveNote.IsLoveNotes) { LoveNote.Content = (string)json["letterContent"]; } else { LoveNote.Content = (string)json["richContent"]; } LoveNote.Source = AppGlobalStatic.Source((string)json["source"], LoveNote.Content); //LoveNote.IsLoveNotes = (bool)json["isLoveNotes"]; //LoveNote.IsLoveNotes = (bool)json["isLoveNotes"]; } streamResponse.Close(); streamReader.Close(); response.Close(); } catch (WebException e) { } Dispatcher.BeginInvoke(() => { progressBar1.IsIndeterminate = false; //Popup_WriteNote.IsOpen = false; ApplicationBar.Mode = ApplicationBarMode.Default; }); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); NavigationContext.QueryString.TryGetValue("userid", out UserID); NavigationContext.QueryString.TryGetValue("username", out UserName); NavigationContext.QueryString.TryGetValue("userurl", out UserUrl); NavigationContext.QueryString.TryGetValue("usersex", out UserSex); //这里要先于pageLoad执行,所以,在这里初始化pageToken pageToken = AppGlobalStatic.ConvertLocalToTimestamp(DateTime.Now).ToString(); if (!UserID.Equals(App.MyID)) { if (pivot.Items.Count > 2) { pivot.Items.RemoveAt(2); } } }
private void GetHTMLCallback(IAsyncResult asynchronousResult) { HttpWebRequest webRequest = null; HttpWebResponse response = null; try { webRequest = (HttpWebRequest)asynchronousResult.AsyncState; response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult); //response.Headers[HttpRequestHeader.ContentType] = "application/json; charset=UTF-8"; Stream streamResponse = response.GetResponseStream(); StreamReader streamReader = new StreamReader(streamResponse); Response = streamReader.ReadToEnd(); MatchCollection mc = Regex.Matches(Response, "<span class=\"profile-label\">(.|\n)*?</span>(.|\n)*?</li>", RegexOptions.IgnoreCase); InfoListCollection = new ObservableCollection <Profile>(); foreach (Match mcc in mc) { string[] arr = Regex.Split(mcc.Value, "</span>"); var pro = new Profile(); if (arr.Length >= 1) { pro.Title = arr[0].Replace("<span class=\"profile-label\">", ""); } if (arr.Length >= 2) { pro.Value = AppGlobalStatic.ClearAhref(arr[1].Replace("\r\n", "").Replace("</li>", "")); } InfoListCollection.Add(pro); } Dispatcher.BeginInvoke(() => { list_info.ItemsSource = InfoListCollection; }); streamResponse.Close(); streamReader.Close(); response.Close(); } catch (WebException e) { } finally { if (webRequest != null) { webRequest.Abort(); } if (response != null) { response.Close(); } } Dispatcher.BeginInvoke(() => { progressBar1.IsIndeterminate = false; }); }
private void GetUserTimelineCallback(IAsyncResult asynchronousResult) { try { HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response; // End the get response operation response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult); response.Headers[HttpRequestHeader.ContentType] = "application/json; charset=UTF-8"; Stream streamResponse = response.GetResponseStream(); StreamReader streamReader = new StreamReader(streamResponse); var Response = streamReader.ReadToEnd(); dynamic json = JsonConvert.DeserializeObject(Response); TrendListCollection = new ObservableCollection <Trend>(); foreach (var item in json["list"]) { var trend = new Trend(); trend.ID = Convert.ToString(item["id"]); //trend.Content = Convert.ToString(item["richContent"]); trend.Timestamp = AppGlobalStatic.DateStringFromNow(AppGlobalStatic.ConvertLocalFromTimestamp(long.Parse((string)item["timestamp"])).ToString()); trend.DiggCount = Convert.ToInt32((string)item["diggCount"]); trend.User = new User(); trend.User.ID = Convert.ToString(item["user"]["id"]); trend.User.NickName = Convert.ToString(item["user"]["nickName"]); trend.User.Url = Convert.ToString(item["user"]["url"]); trend.User.Sex = ("人妖,他,她").Split(',')[(int)item["user"]["sex"]]; trend.User.Avatar = Convert.ToString(item["user"]["avatar"]); trend.User.IsOnline = ((string)item["user"]["isOnline"]).Equals("1") ? "在线" : "离线"; trend.User.Age = Convert.ToString(item["user"]["age"]) + " " + Love.Resources.AppGlobalStatic.AgeToAnimal((string)item["user"]["age"]); trend.User.Height = Convert.ToString(item["user"]["height"]); trend.User.Education = AppGlobalStatic.Xueli[int.Parse((string)item["user"]["education"])]; if (item["isLoveNotes"] != null) { trend.IsLoveNotes = true; trend.Content = (string)item["letterContent"]; trend.LetterTemplateId = (string)item["letterTemplateId"]; } else if (item["isQaTrend"] != null) { trend.IsQaTrend = true; trend.Content = (string)item["content"]; trend.QA = new Question(); trend.QA.ID = (string)item["mediaInfo"]["question"]["id"]; trend.QA.Title = (string)item["mediaInfo"]["question"]["title"]; trend.QA.AnswerID = (int)item["mediaInfo"]["question"]["answerId"]; trend.QA.Options = new List <QuestionOption>(); int _index = 1; foreach (var ss in item["mediaInfo"]["question"]["options"]) { QuestionOption qo = new QuestionOption(); qo.Checked = (_index == trend.QA.AnswerID); qo.Text = (string)ss["text"]; trend.QA.Options.Add(qo); _index++; } } else { trend.IsPhotoTrend = true; trend.Content = (string)item["richContent"]; trend.Photolist = new List <Photo>(); foreach (var ss in item["mediaInfo"]["photoList"]) { trend.Photolist.Add(new Photo() { ID = (string)ss["id"], URL = (string)ss["url"] }); } } trend.Source = AppGlobalStatic.Source((string)item["source"], trend.Content); trend.Content = AppGlobalStatic.ClearAhref(trend.Content); TrendListCollection.Add(trend); } if (TrendListCollection.Count > 0) { pageToken = (string)json["page"]["pageToken"]; TrendListCollection.Add(new Trend() { IsMoreButtonTrend = true }); } Dispatcher.BeginInvoke(() => { list_trend.ItemsSource = TrendListCollection; //textblock1.Text = Response; }); streamResponse.Close(); streamReader.Close(); response.Close(); } catch (WebException e) { } Dispatcher.BeginInvoke(() => { progressBar1.IsIndeterminate = false; ApplicationBar.Mode = ApplicationBarMode.Default; }); }
private void GetMessageCallback(IAsyncResult asynchronousResult) { try { HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response; // End the get response operation response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult); response.Headers[HttpRequestHeader.ContentType] = "application/json; charset=UTF-8"; Stream streamResponse = response.GetResponseStream(); StreamReader streamReader = new StreamReader(streamResponse); var Response = streamReader.ReadToEnd(); dynamic json = JsonConvert.DeserializeObject(Response); MessageListCollection = new ObservableCollection <Message>(); foreach (var item in json["list"]) { var message = new Message(); message.ID = Convert.ToString(item["id"]); message.RichContent = AppGlobalStatic.ImgToEmotion((string)item["richContent"]); message.PrettyTime = AppGlobalStatic.DateStringFromNow(((string)item["prettyTime"]).Replace("今天", DateTime.Now.ToString("yyyy-MM-dd"))); message.Type = (string)item["type"]; switch (message.Type.ToLower()) { case "visitor": case "heed": case "digg": message.User = new User(); message.User.Avatar = "/Assets/Image/" + message.Type + ".png"; message.NewUsersCount = Convert.ToInt32((string)item["newUsersCount"]); break; case "message": case "admin": message.NewCount = Convert.ToInt32((string)item["newCount"]); message.TotalCount = Convert.ToInt32((string)item["totalCount"]); message.User = new User(); message.User.ID = Convert.ToString(item["user"]["id"]); message.User.NickName = Convert.ToString(item["user"]["nickName"]); message.User.Url = Convert.ToString(item["user"]["url"]); message.User.Sex = ("人妖,他,她").Split(',')[(int)item["user"]["sex"]]; message.User.Avatar = Convert.ToString(item["user"]["avatar"]); message.User.IsOnline = ((string)item["user"]["isOnline"]).Equals("1") ? "在线" : "离线"; message.User.Age = Convert.ToString(item["user"]["age"]) + " " + Love.Resources.AppGlobalStatic.AgeToAnimal((string)item["user"]["age"]); break; } MessageListCollection.Add(message); } if (MessageListCollection.Count > 0) { MessageListCollection.Add(new Message() { IsMoreButtonTrend = true }); } PageIndex_Message++; Dispatcher.BeginInvoke(() => { list_message.ItemsSource = MessageListCollection; }); streamResponse.Close(); streamReader.Close(); response.Close(); } catch (WebException e) { } Dispatcher.BeginInvoke(() => { progressBar1.IsIndeterminate = false; ApplicationBar.Mode = ApplicationBarMode.Default; }); }
private void GetMessageCallback(IAsyncResult asynchronousResult) { try { HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response; // End the get response operation response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult); if (!MessageType.Equals("visitor")) { response.Headers[HttpRequestHeader.ContentType] = "application/json; charset=UTF-8"; } Stream streamResponse = response.GetResponseStream(); StreamReader streamReader = new StreamReader(streamResponse); var Response = streamReader.ReadToEnd(); if (MessageType.Equals("visitor")) { Match mc = Regex.Match(Response, "<script id=\"data_visitorList\" type=\"application/json\">(.|\n)*?</script>", RegexOptions.IgnoreCase); if (mc.Success) { Response = mc.Value.Replace("<script id=\"data_visitorList\" type=\"application/json\">", "").Replace("</script>", ""); } else { Response = "{list:[],page:{pageCount:0,pageNo:0}}"; } } dynamic json = JsonConvert.DeserializeObject(Response); MessageListCollection = new ObservableCollection <Message>(); foreach (var item in json["list"]) { var message = new Message(); message.ID = Convert.ToString(item["id"]); message.User = new User(); message.User.ID = Convert.ToString(item["user"]["id"]); message.User.Avatar = (string)(item["user"]["avatar"]); message.User.NickName = Convert.ToString(item["user"]["nickName"]); message.User.Sex = ("人妖,他,她").Split(',')[(int)item["user"]["sex"]]; message.User.Height = (string)item["user"]["height"]; if (item["user"]["education"] != null) { message.User.Education = AppGlobalStatic.Xueli[int.Parse((string)item["user"]["education"])]; } message.User.Url = Convert.ToString(item["user"]["url"]); message.User.Age = Convert.ToString(item["user"]["age"]) + " " + Love.Resources.AppGlobalStatic.AgeToAnimal((string)item["user"]["age"]); message.Type = (string)item["type"]; switch (MessageType) { case "visitor": message.RichContent = message.User.Sex + "来看过你"; message.PrettyTime = AppGlobalStatic.DateStringFromNow(((string)item["visitTime"]).Replace("今天", DateTime.Now.ToString("yyyy-MM-dd"))); message.Source = message.User.Age + " " + message.User.Height + " " + message.User.Education; break; case "heed": message.RichContent = (string)item["content"]; message.PrettyTime = AppGlobalStatic.DateStringFromNow(((string)item["followTime"]).Replace("今天", DateTime.Now.ToString("yyyy-MM-dd"))); message.Source = message.User.Age + " " + message.User.Height + " " + message.User.Education;// + " " + message.User.Sex + "收藏了你"; break; case "digg": message.RichContent = (string)item["richContent"]; message.PrettyTime = AppGlobalStatic.DateStringFromNow(((string)item["praiseTime"]).Replace("今天", DateTime.Now.ToString("yyyy-MM-dd"))); message.Source = message.User.Age + " " + message.User.Height + " " + message.User.Education;//message.User.Sex + " 赞了你"; break; } MessageListCollection.Add(message); } int pageCount = (int)json["page"]["pageCount"]; int pageNo = (int)json["page"]["pageNo"]; if (!MessageType.Equals("visitor")) { if (MessageListCollection.Count > 0) { if (pageCount != pageNo) { MessageListCollection.Add(new Message() { IsMoreButtonTrend = true }); } } } PageIndex_Message++; Dispatcher.BeginInvoke(() => { list_message.ItemsSource = MessageListCollection; }); streamResponse.Close(); streamReader.Close(); response.Close(); } catch (WebException e) { } Dispatcher.BeginInvoke(() => { progressBar1.IsIndeterminate = false; ApplicationBar.Mode = ApplicationBarMode.Default; }); }
private void GetMessageCallback(IAsyncResult asynchronousResult) { try { HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response; // End the get response operation response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult); response.Headers[HttpRequestHeader.ContentType] = "application/json; charset=UTF-8"; Stream streamResponse = response.GetResponseStream(); StreamReader streamReader = new StreamReader(streamResponse); var Response = streamReader.ReadToEnd(); dynamic json = JsonConvert.DeserializeObject(Response); MessageListCollection = new ObservableCollection <Message>(); foreach (var item in json["list"]) { var message = new Message(); message.ID = Convert.ToString(item["id"]); message.RichContent = (string)item["richContent"]; message.Source = AppGlobalStatic.Source((string)item["source"]); message.PrettyTime = AppGlobalStatic.DateStringFromNow(((string)item["prettyTime"]).Replace("今天", DateTime.Now.ToString("yyyy-MM-dd"))); message.User = new User(); message.User.ID = Convert.ToString(item["user"]["id"]); message.User.NickName = Convert.ToString(item["user"]["nickName"]); message.User.Sex = ("人妖,他,她").Split(',')[(int)item["user"]["sex"]]; message.ToUser = new User(); message.ToUser.Url = Convert.ToString(item["toUser"]["url"]); message.ToUser.NickName = Convert.ToString(item["toUser"]["nickName"]); message.ToUser.Sex = ("人妖,他,她").Split(',')[(int)item["toUser"]["sex"]]; message.RelatedData = item["relatedData"] as JObject; message.Type = (string)item["type"]; if (message.Type.Equals("1")) { if (message.User.ID.Equals(App.MyLove["id"].ToString())) { message.RichContent = "我赞了" + message.ToUser.Sex + "发布的动态"; } else { message.RichContent = message.User.Sex + " 赞了我发布的动态"; } } else { message.RichContent = AppGlobalStatic.ImgToEmotion(message.RichContent); } if (message.RelatedData["trend"] != null) { message.RichContent += "\n- - - - - - - - -\n" + AppGlobalStatic.ImgToEmotion(Convert.ToString(message.RelatedData["trend"]["richContent"])); } message.RichContent = AppGlobalStatic.ClearAhref(message.RichContent); message.User.Url = Convert.ToString(item["user"]["url"]); message.User.Age = Convert.ToString(item["user"]["age"]) + " " + Love.Resources.AppGlobalStatic.AgeToAnimal((string)item["user"]["age"]); MessageListCollection.Add(message); } int pageCount = (int)json["page"]["pageCount"]; int pageNo = (int)json["page"]["pageNo"]; if (MessageListCollection.Count > 0) { if (pageCount != pageNo) { MessageListCollection.Add(new Message() { IsMoreButtonTrend = true }); } } PageIndex_Message++; Dispatcher.BeginInvoke(() => { list_message.ItemsSource = MessageListCollection; }); streamResponse.Close(); streamReader.Close(); response.Close(); } catch (WebException e) { } Dispatcher.BeginInvoke(() => { progressBar1.IsIndeterminate = false; ApplicationBar.Mode = ApplicationBarMode.Default; }); }