Пример #1
0
		private void FetchPageCompleted(object sender, BaseEventArgs e)
		{
			HtmlDocument doc = new HtmlDocument();
			doc.LoadHtml(e.Result as string);
			string txt = doc.DocumentNode.SelectSingleNode("//table").InnerHtml;

			Page page = new Page(board);
			var r = PREV_START_RE.Match(e.Result as string);
			// TODO check PrevStart
			page.PrevStart = int.Parse(PREV_START_RE.Match(e.Result as string).Groups[2].ToString())-1;

			List<Header> headerList = new List<Header>();
			var authorList = AUTHOR_RE.Matches(txt);
			var pidList = PID_RE.Matches(txt);
			var titleList = TITLE_RE.Matches(txt);
			var countList = COUNT_RE.Matches(txt);
			int diff = authorList.Count - countList.Count;
			// skip fixed posts, and append headers in reverse order
			for (int i = authorList.Count-1; i >= diff; i--)
			{
				Header h = new Header();
				h.Author = authorList[i].Groups[1].ToString();
				h.Board = page.Board;
				h.Pid = int.Parse(pidList[i].Groups[2].ToString());
				h.Title = titleList[i].Groups[1].ToString().Remove(0, 2);
				h.ReplyCount = int.Parse(countList[i-diff].Groups[2].ToString());
				h.ViewCount = int.Parse(countList[i-diff].Groups[4].ToString());
				page.HeaderList.Add(h);
			}
			callback(this, new BaseEventArgs(page));
		}
Пример #2
0
		private void FetchGidCompleted(object sender, BaseEventArgs e)
		{
			Utils.HideIndicator();
			if (e.Error != null)
			{
				// TODO Check if the post was deleted.
				MessageBox.Show("无法获取数据,请检查网络情况", "出错啦", MessageBoxButton.OK);
				NavigationService.GoBack();
				return;
			}
			Utils.HideIndicator();
			Post p = e.Result as Post;
			gid = p.Gid;
		}
Пример #3
0
		private void FetchPageCompleted(object sender, BaseEventArgs e)
		{
			IsLoading = false;
			if (e.Error != null)
			{
				LilyToast toast = new LilyToast();
				toast.ShowNetworkError();
				return;
			}
			LilyBBS.API.Page page = e.Result as LilyBBS.API.Page;
			prevStart = page.PrevStart;
			foreach (var i in page.HeaderList)
				itemsSource.Add(i);
		}
Пример #4
0
		private void LoginCompleted(object sender, BaseEventArgs e)
		{
			if (callback == null) return;
			Regex re = new Regex(@"setCookie\('(.*)'\)");
			string s = re.Match(e.Result as string).Groups[1].ToString();
			if (s == "")
			{
				connection.Cookie = null;
				callback(this, new BaseEventArgs(false));
				return;
			}
			StringBuilder sb = new StringBuilder();
			string[] ss = s.Split('+');
			sb.AppendFormat("_U_KEY={0}; ", int.Parse(ss[1]) - 2);
			ss = ss[0].Split('N');
			sb.AppendFormat("_U_UID={0}; ", ss[1]);
			sb.AppendFormat("_U_NUM={0}", int.Parse(ss[0]) + 2);
			String cookie = sb.ToString();
			connection.Cookie = cookie;
			callback(this, new BaseEventArgs(true));
		}
Пример #5
0
		private void FetchHotListCompleted(object sender, BaseEventArgs e)
		{
			if (callback == null) return;
			HtmlDocument doc = new HtmlDocument();
			doc.LoadHtml(e.Result as string);
			List<HeaderGroup> hotList = new List<HeaderGroup>();
			var items = doc.DocumentNode.SelectNodes("//tr");
			HeaderGroup grp = null;
			int sid = 0;

			foreach (var i in items)
			{
				if (i.SelectSingleNode("td/img") != null)
				{
					grp = new HeaderGroup(sid++);
					continue;
				}
				if (i.InnerHtml.StartsWith("<td>\n<tr><td colspan=\"2\">"))
				{
					hotList.Add(grp);
					continue;
				}
				MatchCollection matches = RE.Matches(i.InnerHtml);
				foreach (Match m in matches)
				{
					Header h = new Header();
					h.Board = m.Groups[1].ToString();
					h.Pid = int.Parse(m.Groups[2].ToString());
					h.Title = m.Groups[3].ToString();
					grp.Add(h);
					if (i.InnerHtml[m.Index + m.Length] == 'r')
						break;
				}
			}
			hotList.Add(grp);
			callback(this, new BaseEventArgs(hotList));
		}
Пример #6
0
		private void FetchTopicCompleted(object sender, BaseEventArgs e)
		{
			IsLoading = false;
			if (e.Error != null)
			{
				LilyToast toast = new LilyToast();
				toast.ShowNetworkError();
				return;
			}
			/*
			 * HTMLAgilityPack fails often!
			 */
			try
			{
				Topic t = e.Result as Topic;
				NextStart = t.nextStart;
				foreach (var i in t.PostList)
					items.Add(i);
			}
			catch (Exception exc)
			{
				
			}
		}
Пример #7
0
		private void ValidateLoginCompleted(object sender, BaseEventArgs e)
		{
			Utils.HideIndicator();
			if (e.Error != null)
			{
				ShowError();
				Unlock();
				return;
			}
			bool? successful = e.Result as bool?;
			if (successful.Value)
				SendPost();
			else
				Login();
		}
Пример #8
0
		private void SendPostCompleted(object sender, BaseEventArgs e)
		{
			Utils.HideIndicator();
			if (e.Error != null)
			{
				ShowError();
				Unlock();
				return;
			}
			MessageBox.Show("请手动刷新检查是否发送成功-_-||");
			NavigationService.GoBack();
		}
Пример #9
0
		private void FetchBoardListCompleted(object sender, BaseEventArgs e)
		{
			//int i;
		}
Пример #10
0
		private void FetchTopTenListCompleted(object sender, BaseEventArgs e)
		{
			Utils.HideIndicator();
			if (e.Error != null)
			{
				ShowError(TopTenList, TopTenErrorTextBox);
				isTopTenListLoaded = false;
				return;
			}
			HideError(TopTenList, TopTenErrorTextBox);
			isTopTenListLoaded = true;
			List<Header> topTenList = e.Result as List<Header>;
			TopTenList.ItemsSource = topTenList;
		}
Пример #11
0
		private void FetchHotListCompleted(object sender, BaseEventArgs e)
		{
			Utils.HideIndicator();
			if (e.Error != null)
			{
				ShowError(HotList, HotErrorTextBox);
				isHotListLoaded = false;
				return;
			}
			HideError(HotList, HotErrorTextBox);
			isHotListLoaded = true;
			List<HeaderGroup> hotList = e.Result as List<HeaderGroup>;
			HotList.ItemsSource = hotList;
		}