public IActionResult OnGet() { // now I do have an http context // back at index page, so forget any previous path PageStack.Clear(HttpContext.Session); var user = HttpContext.User; IsAdmin = user?.IsInRole(RoleNames.Administrators) ?? false; IsEditor = user?.IsInRole(RoleNames.Editors) ?? false; return(Page()); }
public UserInfoFragment() { InitializeComponent(); async Task <PersonCenterModel> loadData() { var html = await ApiClient.GetMainPage(); var right = new HtmlParser().ParseDocument(html).GetElementById("Rightbar"); var tables = right.QuerySelectorAll("table"); var spans = tables[1].QuerySelectorAll("span.bigger"); return(new PersonCenterModel { Member = new MemberModel { Image = tables[0].QuerySelector("img").GetAttribute("src"), Username = tables[0].QuerySelector("span.bigger").TextContent }, CollectedNodes = spans[0].TextContent, CollectedTopics = spans[1].TextContent, NoticePeople = spans[2].TextContent, Money = right.QuerySelector("div#money").QuerySelector("a").InnerHtml, Notifications = right.QuerySelector("a[href='/notifications']").TextContent.Split(' ') .FirstOrDefault(), IsNotChecked = right.QuerySelector("a[href='/mission/daily']") != null }); } var checkIn = Observable.FromEventPattern <TappedRoutedEventArgs>(CheckInItem, nameof(CheckInItem.Tapped)) .Select(async x => { var html = await ApiClient.GetCheckInInformation(); var href = new HtmlParser().ParseDocument(html).GetElementById("Main").QuerySelector("input") .GetAttribute("onclick").Replace("location.href = '", "").Replace("';", "").Trim(); if (href.Contains("/balance")) { return(CheckInStatus.Gone); } var r = await ApiClient.CheckIn($"https://www.v2ex.com{href}", $"https://www.v2ex.com{href}"); return(CheckInStatus.Success); }) .ObserveOnCoreDispatcher() .Subscribe(async x => { switch (await x) { case CheckInStatus.Gone: Toast.ShowTips("已经签到"); break; case CheckInStatus.Success: Toast.ShowTips("签到成功"); Observable.FromAsync(y => loadData()) .Retry(10) .ObserveOnCoreDispatcher() .Subscribe(y => People = y); break; case CheckInStatus.Failure: Toast.ShowTips("签到失败"); break; } }, ex => Toast.ShowTips("签到失败")); var cancel = Observable.FromEventPattern <TappedRoutedEventArgs>(CancelItem, nameof(CancelItem.Tapped)) .ObserveOnCoreDispatcher() .Subscribe(x => { if (Window.Current.Content is ActivityContainer frame) { PageStack.Clear(); frame.ClearBackStack(); frame.Navigate(typeof(UserLoginView)); } }); var write = Observable.FromEventPattern <TappedRoutedEventArgs>(WriteItem, nameof(WriteItem.Tapped)) .Subscribe(x => PageStack.Next("Left", "Right", typeof(WriteTopicView), null)); var user = Observable.FromEventPattern <TappedRoutedEventArgs>(UserItem, nameof(UserItem.Tapped)) .Subscribe(x => PageStack.Next("Left", "Right", typeof(MemberView), People.Member.Username)); var money = Observable.FromEventPattern <TappedRoutedEventArgs>(MoneyItem, nameof(MoneyItem.Tapped)) .Subscribe(x => PageStack.Next("Left", "Right", typeof(MoneyDetailView), null)); var collectTopic = Observable .FromEventPattern <TappedRoutedEventArgs>(CollectTopicItem, nameof(CollectTopicItem.Tapped)) .Subscribe(x => PageStack.Next("Left", "Right", typeof(PeopleTopicView), Convert.ToInt32(People.CollectedTopics))); var collectNode = Observable.FromEventPattern <TappedRoutedEventArgs>(CollectNodeItem, nameof(CollectNodeItem.Tapped)) .Subscribe(x => PageStack.Next("Left", "Right", typeof(PeopleNodeView), null)); var message = Observable.FromEventPattern <TappedRoutedEventArgs>(MessageItem, nameof(MessageItem.Tapped)) .Subscribe(x => PageStack.Next("Left", "Right", typeof(PeopleNotificationView), null)); var follower = Observable.FromEventPattern <TappedRoutedEventArgs>(FollowerItem, nameof(FollowerItem.Tapped)) .Subscribe(x => PageStack.Next("Left", "Right", typeof(PeopleFollowerView), null)); var loadInformation = Observable .FromEventPattern <RoutedEventArgs>(UserInformationFragment, nameof(UserInformationFragment.Loaded)) .SelectMany(x => loadData()) .Retry(10) .ObserveOnCoreDispatcher() .Subscribe(x => People = x); var refresh = Observable.FromEventPattern <TappedRoutedEventArgs>(Refresh, nameof(Refresh.Tapped)) .SelectMany(x => loadData()) .Retry(10) .ObserveOnCoreDispatcher() .Subscribe(x => People = x); this.Unloaded += (s, e) => { checkIn.Dispose(); cancel.Dispose(); write.Dispose(); user.Dispose(); money.Dispose(); collectTopic.Dispose(); collectNode.Dispose(); message.Dispose(); follower.Dispose(); loadInformation.Dispose(); refresh.Dispose(); }; }
void WebEvents_OnEndHttpRequest() { PageStack.Clear(); requestedPage = null; }