private async Task RequestDefaultCategoryData(bool isLoadingMore) { MainData storyData = null; if (isLoadingMore) { storyData = await DataRequester.RequestStories(_currentDate); } else { ResetStorys(); storyData = await DataRequester.RequestLatestStories(); if (storyData != null) { TopStoryList = storyData.top_stories; CurrentStoryId = storyData.stories.First().id.ToString(); } } if (storyData == null) { return; } _currentDate = storyData.date; StoryDataList.Add(new Story() { title = StringUtil.GetStoryGroupName(_currentDate), type = Misc.Group_Name_Type }); StoryDataList.AddRange(storyData.stories); }
private async Task RequestMinorCategoryData(bool isLoadingMore) { MinorData storyData = null; if (isLoadingMore) { storyData = await DataRequester.RequestCategoryStories(CurrentCategoryId.ToString(), _currentDate); } else { ResetStorys(); storyData = await DataRequester.RequestCategoryLatestStories(CurrentCategoryId.ToString()); if (storyData != null) { var firstStoryId = storyData.stories.First().id; TopStoryList = new List <TopStory>() { new TopStory() { image = storyData.background, id = Misc.Unvalid_Image_Id, title = storyData.description } }; CurrentStoryId = firstStoryId.ToString(); } } if (storyData == null || storyData.stories.Count == 0) { return; } _currentDate = storyData.stories.Last().id.ToString(); StoryDataList.AddRange(storyData.stories); }
private async void PostToCirclePage_Loaded(object sender, RoutedEventArgs arg) { LoadingIcon.Display(); OwnCircles = await DataRequester.GetOwnCircles(); if (OwnCircles.Circles != null && OwnCircles.Circles.Count > 0) { CurrentCircle = OwnCircles.Circles[0]; CurrentCircleBtn.Content = CurrentCircle.Name; OwnCircles.Circles.ForEach(circle => { var menuItem = new MenuFlyoutItem() { Text = circle.Name, Tag = circle }; menuItem.Click += (s, e) => { CurrentCircle = ((OwnCircleInfo)((MenuFlyoutItem)s).Tag); CurrentCircleBtn.Content = CurrentCircle.Name; }; CircleMenu.Items.Add(menuItem); }); } else if (_needCreateCircle) { LLQNotifier.Default.Notify(new StoryEvent() { Type = StoryEventType.CreateCircle }); PopupMessage.DisplayMessageInRes("NoCircle"); } LoadingIcon.Hide(); }
private async Task RequestStories(bool isLoadingMore) { TimeLine timeLine = null; if (isLoadingMore) { if (StoryDataList.Count > 0) { timeLine = await DataRequester.RequestNextTimeLine(StoryDataList.Last().Time.ToString()); } } else { ResetStories(); timeLine = await DataRequester.RequestLatestTimeLine(); if (timeLine != null && timeLine.Items != null && timeLine.Items.Count > 0) { CurrentStoryId = timeLine.Items.First().Id.ToString(); } } if (timeLine == null || timeLine.Items == null) { return; } timeLine.Adjust(); StoryDataList.AddRange(timeLine.Items); }
public async Task RefreshStories(bool isLoadingMore) { HotCircleStories hotCircleStories = null; if (isLoadingMore) { if (StoryDataList.Count > 0) { hotCircleStories = await DataRequester.RequestNextStoriesForCircle(CircleId, StoryDataList.Last().Time.ToString()); } } else { ResetStorys(); hotCircleStories = await DataRequester.RequestLatestStoriesForCircle(CircleId); if (hotCircleStories != null && hotCircleStories.Stories != null && hotCircleStories.Stories.Count > 0) { CurrentStoryId = hotCircleStories.Stories.First().Id.ToString(); } } if (hotCircleStories == null || hotCircleStories.Stories == null || hotCircleStories.Stories.Count == 0) { return; } hotCircleStories.Stories.ForEach(story => story.AdjustForHotCircleStory(Circle)); StoryDataList.AddRange(hotCircleStories.Stories); }
private async Task RequestFavorites(bool isLoadingMore) { Favorites favData = null; if (isLoadingMore) { if (!FavoritesLastTime.HasValue) { return; } favData = await DataRequester.RequestFavorites(FavoritesLastTime.Value.ToString()); } else { ResetStories(); favData = await DataRequester.RequestLatestFavorites(); if (favData != null && favData.stories != null && favData.stories.Count > 0) { CurrentStoryId = favData.stories.First().Id.ToString(); } } if (favData == null) { return; } FavoritesLastTime = favData.last_time; StoryDataList.AddRange(favData.stories); }
public async void JoinCircle() { if (!AuthorizationHelper.IsLogin) { PopupMessage.DisplayMessageInRes("NeedLogin"); return; } if (Misc.ZhiHuCircleId.ToString() == CircleId && JoinCircleButtonIcon == _checkIcon) { PopupMessage.DisplayMessageInRes("CannotQuitZhiHuCircle"); return; } if (JoinCircleButtonIcon == _addIcon) { JoinCircleButtonIcon = _checkIcon; await DataRequester.JoinCircle(CircleId); PopupMessage.DisplayMessageInRes("JoinCircleSuccess"); } else { JoinCircleButtonIcon = _addIcon; await DataRequester.QuitCircle(CircleId); PopupMessage.DisplayMessageInRes("QuitCircleSuccess"); } }
public async void RequestStoryExtraInfo() { var currentStoryExtraInfo = await DataRequester.RequestStoryExtraInfo(CurrentStoryId); CurrentStoryExtraInfo = currentStoryExtraInfo ?? DefaultStoryExtraInfo; LLQNotifier.Default.Notify(new StoryExtraEvent() { StoryExtraInfo = CurrentStoryExtraInfo }); }
private async void CheckVersion() { StorageInfo.Instance.HaveNewVersion = false; StorageInfo.Instance.NewVersion = await DataRequester.GetVersion(); if (StringUtil.CompareVersion(StorageInfo.Instance.NewVersion.Version, Package.Current.Id.Version)) { StorageInfo.Instance.HaveNewVersion = true; } }
public async Task PerformXmlHttpRequestSynchronousToDataUrlShouldWork() { var req = new DataRequester(); var cfg = Configuration.Default.With(req).WithJs().WithDefaultLoader(); var script = "var xhr = new XMLHttpRequest(); xhr.open('GET', 'data:plain/text,Hello World!', false);xhr.send();document.querySelector('#result').textContent = xhr.responseText;"; var html = "<!doctype html><div id=result></div><script>" + script + "</script>"; var document = await BrowsingContext.New(cfg).OpenAsync(m => m.Content(html)); var result = document.QuerySelector("#result").TextContent; Assert.AreEqual("Hello World!", result); }
private async Task RequestNormalComments() { if (_currCommentType == CommentType.Recommend) { _currCommentType = CommentType.Normal; } var normalComments = await DataRequester.RequestNormalComments(CurrentStoryId, _currCommentType == CommentType.Recommend?null : LastCommentId); if (normalComments != null) { CommentList.Last().AddRange(normalComments.Comments); } }
private async Task RequestShortComments() { if (_currCommentType == CommentType.Long) { _currCommentType = CommentType.Short; } var shortComment = await DataRequester.RequestShortComment(CurrentStoryId, _currCommentType == CommentType.Long?null : LastCommentId); if (shortComment != null) { CommentList.Last().AddRange(shortComment.comments); } }
private void Subscriber(StoryEvent param) { switch (param.Type) { case StoryEventType.Fav: DataRequester.SetStoryFavorite(CurrentStoryId, param.IsChecked); break; case StoryEventType.Like: DataRequester.SetStoryLike(CurrentStoryId, param.IsChecked); break; } }
public override async Task Login(ZhiHuLoginInfo info, Action <RiBaoAuthoInfo> loginCallback) { if (IsAuthorized) { loginCallback?.Invoke(await DataRequester.LoginUsingZhiHu(TokenInfo)); return; } if (info == null) { loginCallback?.Invoke(null); return; } if (info.Captcha != null && !await CheckCaptcha(info.Captcha)) { loginCallback?.Invoke(null); return; } var signInfo = await DataRequester.ZhiHuLogin(info.UserName, info.Password); if (!CheckError(signInfo)) { loginCallback?.Invoke(null); return; } var zhiHuAutoInfo = await DataRequester.GetZhiHuAuthorization(signInfo); if (!CheckError(zhiHuAutoInfo)) { loginCallback?.Invoke(null); return; } TokenInfo = await DataRequester.GetZhiHuToken(zhiHuAutoInfo); if (TokenInfo == null || string.IsNullOrEmpty(TokenInfo.access_token)) { PopupMessage.DisplayMessage(StringUtil.GetString("LoginFailed") + TokenInfo?.Data ?? ""); loginCallback?.Invoke(null); return; } TokenInfo.LastAuthoDate = DateTime.Now; TokenInfo.source = LoginType.ZhiHu.Convert(); StoreTokenInfo(); var autoInfo = await DataRequester.LoginUsingZhiHu(TokenInfo); loginCallback?.Invoke(autoInfo); }
public async void RequestStoryExtraInfo() { CurrentStoryExtraInfo = await DataRequester.RequestStoryExtraInfo(CurrentStoryId); if (CurrentStoryExtraInfo == null) { return; } LLQNotifier.Default.Notify(new StoryExtraEvent() { StoryExtraInfo = CurrentStoryExtraInfo }); }
private void Subscriber(DefaultEvent param) { if (!AuthorizationHelper.IsLogin) { //TODO: please login return; } switch (param.EventType) { case EventType.ClickFav: DataRequester.SetStoryFavorite(CurrentStoryId, param.IsChecked); break; } }
private async Task RequestLongComments(bool isLoadingMore) { var longComment = await DataRequester.RequestLongComment(CurrentStoryId, LastCommentId); if (longComment == null) { return; } CommentList.First().AddRange(longComment.comments); if (longComment == null || longComment.comments.Count < Misc.Page_Count) { await RequestShortComments(); } }
public async void InitCategories() { var categories = await DataRequester.RequestCategory(); if (categories == null) { return; } CategoryList.AddRange(categories.others); if (CategoryList.Count > 0) { CategoryName = CategoryList[0].name; } }
private async Task RequestRecommendComments() { var recommendComments = await DataRequester.RequestRecommendComments(CurrentStoryId, LastCommentId); if (recommendComments == null) { return; } CommentList.First().AddRange(recommendComments.Comments); if (recommendComments == null || recommendComments.Comments == null || recommendComments.Comments.Count < Misc.Page_Count) { await RequestNormalComments(); } }
public async void RequestMainContent() { if (string.IsNullOrEmpty(CurrentStoryId)) { return; } IsRefreshContent = true; var content = await DataRequester.RequestStoryContent(CurrentStoryId); if (content != null) { Html.ArrangeMainContent(content); MainHtmlContent = content; } IsRefreshContent = false; }
async void UpdateCircles(string text) { if (_updateStatus.ContainsKey(0) && _updateStatus[0]) { return; } _updateStatus[0] = true; var circles = await DataRequester.SearchCircles(text); if (circles != null && circles.Circles != null) { var list = circles.Circles.ToList(); list.ForEach(o => o.Adjust()); SearchCircles = list; } }
async void UpdateStories(string text) { if (_updateStatus.ContainsKey(1) && _updateStatus[1]) { return; } _updateStatus[1] = true; var stories = await DataRequester.SearchStories(text); if (stories != null && stories.Stories != null) { var list = stories.Stories.ToList(); list.ForEach(o => o.Adjust()); SearchStories = list; } }
private static async void LoginZhiHu(LoginType loginType, Action <bool, object> loginCallback) { var zhiHuAuthoData = await DataRequester.Login(Authorizations[loginType].LoginData); if (zhiHuAuthoData == null) { loginCallback(false, StringUtil.GetString("LoginZhiHuFailed")); return; } StorageUtil.StorageInfo.LoginType = loginType; StorageUtil.StorageInfo.ZhiHuAuthoInfo = zhiHuAuthoData; StorageUtil.UpdateStorageInfo(); IsLogin = true; SetHttpAuthorization(); loginCallback(true, StringUtil.GetString("LoginSuccess")); }
public static async Task <bool> AnonymousLogin() { var key = LoginKeyProvider.GetAnonymousLoginKey(); LoginToken loginToken = await DataRequester.AnonymousLogin(key); if (loginToken == null) { return(false); } StorageInfo.Instance.ZhiHuAuthoInfo = new RiBaoAuthoInfo() { AnonymousLoginToken = loginToken.Access_Token }; SetHttpAuthorization(); return(true); }
public async Task DataGetRequestForSmallImageBase64Encoded() { var http = new DataRequester(); var request = new Request(); var content = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; request.Address = new Url(content); request.Method = HttpMethod.Get; using (var response = await http.RequestAsync(request, CancellationToken.None)) { Assert.IsNotNull(response); Assert.AreEqual(200, (int)response.StatusCode); Assert.IsTrue(response.Content.CanRead); Assert.IsTrue(response.Headers.Count > 0); Assert.AreEqual("image/png", response.Headers[HeaderNames.ContentType]); } }
public async Task DataGetRequestForMiddleImageBase64Encoded() { var http = new DataRequester(); var request = new Request(); var content = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC"; request.Address = new Url(content); request.Method = HttpMethod.Get; using (var response = await http.RequestAsync(request, CancellationToken.None)) { Assert.IsNotNull(response); Assert.AreEqual(200, (int)response.StatusCode); Assert.IsTrue(response.Content.CanRead); Assert.IsTrue(response.Headers.Count > 0); Assert.AreEqual("image/png", response.Headers[HeaderNames.ContentType]); } }
public async Task DataGetRequestForPlainText() { var http = new DataRequester(); var request = new Request { Address = new Url("data:,Hello+there"), Method = HttpMethod.Get }; using (var response = await http.RequestAsync(request, CancellationToken.None)) { Assert.IsNotNull(response); Assert.AreEqual(200, (int)response.StatusCode); Assert.IsTrue(response.Content.CanRead); Assert.IsTrue(response.Headers.Count > 0); Assert.AreEqual("text/plain", response.Headers[HeaderNames.ContentType]); var content = new StreamReader(response.Content); Assert.AreEqual("Hello there", content.ReadToEnd()); } }
private async Task <bool> CheckCaptcha(string captcha) { var captchaChecked = await DataRequester.CheckCaptcha(captcha); if (captchaChecked != null && captchaChecked.Success) { return(true); } if (captchaChecked != null && captchaChecked.Error != null && !string.IsNullOrEmpty(captchaChecked.Error.Message)) { PopupMessage.DisplayMessage(captchaChecked.Error.Message); } else { PopupMessage.DisplayMessageInRes("CaptchaCheckFailed"); } return(false); }
private void Subscriber(StoryEvent param) { switch (param.Type) { case StoryEventType.Fav: DataRequester.SetFavoriteStory(CurrentStoryId, param.IsChecked); break; case StoryEventType.Like: DataRequester.SetStoryLike(CurrentStoryId, param.IsChecked); break; case StoryEventType.Night: if (VM != null) { VM.RequestMainContent(); } break; } }
public async void RequestMainContent() { if (string.IsNullOrEmpty(CurrentStoryId)) { return; } IsRefreshContent = true; var content = await DataRequester.RequestStoryContent(CurrentStoryId); if (content != null) { Html.ArrangeMainContent(content); MainHtmlContent = content; LLQNotifier.Default.Notify(new ShareEvent() { ShareUrl = content.share_url }); } IsRefreshContent = false; }