/// <summary> /// Enables moderator functions if the user is a moderator. /// Enable the possibility to add a thread if the user is a poster. /// Adds sticky threads to the top of the thread list. /// </summary> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (IsModerator && !IsStartPage) { DeleteForumButton.Visible = true; DeleteForumButton.OnClientClick = string.Format("if(!confirm('{0}'))return false;", Translate("/common/messages/confirmdelete")); } ForumList.DataBind(); // Add sticky threads. PageReference stickyThreadContainer = (PageReference)CurrentPage["StickyThreadContainer"]; if (!PageReference.IsNullOrEmpty(stickyThreadContainer)) { ThreadList.DataSource = DataFactory.Instance.GetChildren(stickyThreadContainer); } else if (CurrentPage.Status == VersionStatus.Published) { // If there is no container pages, and we are viewing the published version, show the error panel. SwitchView(ViewMode.ErrorView); return; } if (!IsPostBack) { SwitchView(ViewMode.ListView); } }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState) { var id = parameter == null ? "mainlist" : parameter.ToString(); ForumList.Id = id; if (mode == NavigationMode.New || mode == NavigationMode.Refresh) { await LoadViewModel(parameter?.ToString()); } else { var cache = new FileService(); var cachedForumlist = await cache.TryGetFromCache(ForumList.Id); if (cachedForumlist != null) { ForumList = cachedForumlist; } else { await LoadViewModel(id); } } }
public void ForumListTest() { const string success = @"{""forum_list"":[{""name"":""\u9006\u6218"",""id"":1829631,""is_like"":1,""favo_type"":2,""level_id"":3,""member_count"":null,""avatar"":"""",""slogan"":""""},{""name"":""\u4e03\u96c4\u4e89\u9738"",""id"":2387937,""is_like"":1,""favo_type"":2,""level_id"":133,""member_count"":null,""avatar"":"""",""slogan"":""""},{""name"":""\u5f31\u667a"",""id"":272685,""is_like"":1,""favo_type"":2,""level_id"":13,""member_count"":null,""avatar"":"""",""slogan"":""""},{""name"":""\u5c0f\u5175\u4f20\u5947"",""id"":6688,""is_like"":1,""favo_type"":2,""level_id"":13,""member_count"":null,""avatar"":"""",""slogan"":""""},{""name"":""\u60b2\u60e8\u4e16\u754c"",""id"":362671,""is_like"":1,""favo_type"":2,""level_id"":13,""member_count"":null,""avatar"":"""",""slogan"":""""},{""name"":""\u6b4c\u5267\u9b45\u5f71"",""id"":225536,""is_like"":1,""favo_type"":2,""level_id"":13,""member_count"":null,""avatar"":"""",""slogan"":""""}],""commend_forum_list"":[],""is_login"":1,""page"":{""page_size"":20,""offset"":0,""current_page"":1,""total_count"":0,""total_page"":0,""has_more"":0,""has_prev"":0},""anti"":{""tbs"":""1234""},""server_time"":31003,""time"":1544597962,""ctime"":0,""logid"":3562410370,""error_code"":""0""}"; const string ans = @"[2018/12/12 14:59:22] Info 总共有 6 个贴吧 TBS: 1234 逆战(1829631):3级 七雄争霸(2387937):133级 弱智(272685):13级 小兵传奇(6688):13级 悲惨世界(362671):13级 歌剧魅影(225536):13级 "; var x1 = new ForumList(); x1.Parse(Error); var x2 = new ForumList(); x2.Parse(success); Console.WriteLine(x1.ToString()); Assert.AreEqual(@"[2018/12/11 17:35:33] Error 160002:亲,你之前已经签过了", x1.ToString()); Console.WriteLine(x2.ToString()); Assert.AreEqual(ans, x2.ToString()); }
private async void RunToEnd(Json json) { #region 取得论坛图标和更新信息 json = await TsdmHelper.GetForumAsync("", MainWindowsViewModel.Person.PersonCookie); foreach (var item in json.group) { ForumList forumList = new ForumList() { Title = item.title, Parameter = new Tuple <string, string>(item.gid, "gid") }; MainWindowsViewModel.GroupCollection.Add(forumList); } json = await TsdmHelper.GetForumAsync(MainWindowsViewModel.GroupCollection[0].Parameter.Parameter1, MainWindowsViewModel.Person.PersonCookie); foreach (var item in json.forum) { ForumList forumList = new ForumList() { Title = item.title, Parameter = new Tuple <string, string>(item.fid, "fid") }; MainWindowsViewModel.ForumCollection.Add(forumList); } #endregion MainWindowsViewModel.LoginComplete = true; this.ProgramLoadingFinished(MainWindowsViewModel, new EventArgs()); }
private ForumList CachePrivateForumList(int accountID) { using (var db = new ZkDataContext()) { var account = db.Accounts.Find(accountID); var accessibleThreads = db.ForumThreads.Where(x => x.RestrictedClanID == null || x.RestrictedClanID == account.ClanID); accessibleThreads = accessibleThreads.Where(x => x.ForumCategory.ForumMode != ForumMode.Archive); var threads = (from t in accessibleThreads let read = t.ForumThreadLastReads.FirstOrDefault(x => x.AccountID == account.AccountID) orderby t.LastPost descending select new { Thread = t, Read = (read != null && read.LastRead >= t.LastPost) }).Take(10).ToList(); var list = new ForumList() { ForumItems = threads.Select(x => new ForumItem() { ThreadID = x.Thread.ForumThreadID, Time = x.Thread.LastPost ?? x.Thread.Created, Url = $"{GlobalConst.BaseSiteUrl}/Forum/Thread/{x.Thread.ForumThreadID}", Header = x.Thread.Title, IsRead = x.Read }).ToList() }; cachedAccountForumLists[account.AccountID] = list; return(list); } }
private async Task ExecuteGetCPFeedCommand() { if (IsBusy) { return; } IsBusy = true; GetForumListCommand.ChangeCanExecute(); try { var forums = await cpFeed.GetForumAsync(forumId); foreach (var forum in forums.items) { ForumList.Add(forum); } IsBusy = false; } catch (Exception ex) { } }
public static ForumList GetDefaultForumList() { var forumList = new ForumList { Id = "/f202", Title = "Hockey", ShowNavigation = true, CurrentPage = 1, MaxPages = 378, Items = new ObservableCollection <FbItem> { new FbItem { Name = "Bästa back 2017?", ShowPostCount = true, PostCount = 1234, Type = FbItemType.Thread, ShowForumColor = false, Description = "Senaste inlägg av XXXX 2017-05-01" }, new FbItem { Name = "Bästa back 2017?", ShowPostCount = true, PostCount = 367, Type = FbItemType.Thread, ShowForumColor = false, Description = "Senaste inlägg av XXXX 2017-05-01" }, new FbItem() { Name = "Bästa back 2017?", ShowPostCount = true, PostCount = 12, Type = FbItemType.Thread, ShowForumColor = false, Description = "Senaste inlägg av XXXX 2017-05-01" }, new FbItem() { Name = "Bästa back 2017?", ShowPostCount = true, PostCount = 4, Type = FbItemType.Thread, ShowForumColor = false, Description = "Senaste inlägg av XXXX 2017-05-01" }, new FbItem() { Name = "Ekonomi", ShowForumColor = true, ShowPostCount = false, Type = FbItemType.Forum } } }; return(forumList); }
public ForumMainListViewModel() { ForumList = new ForumList() { Items = new ObservableCollection <FbItem>() }; _forumService = new ForumService(App.CookieContainer); _settings = SettingsService.Instance; if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) { ForumList = SampleData.SampleData.GetDefaultForumList(); } }
public async Task LoadViewModel(string id) { try { FileService fileService = new FileService(); if (string.IsNullOrWhiteSpace(id) || id == "mainlist") { await fileService.ResetCache(); Busy.SetBusy(true, "Laddar forumlistan..."); Error = null; var resultForumList = await _forumService.GetMainForumlist(); var extraForum = await fileService.GetExtraForums(); if (extraForum != null && extraForum.Any()) { resultForumList.Items.AddRange(extraForum); } ForumList = resultForumList; } else { Busy.SetBusy(true, "Laddar..."); Error = null; var resultForumList = await _forumService.GetForums(id); ForumList = resultForumList; } if (ForumList.Items.Count > 0) { await fileService.AddToCacheList(ForumList); } } catch (Exception e) { Error = e.ToString(); } finally { Busy.SetBusy(false); } }
private async void GetForumList(Parameter tuple) { Json json = await TsdmHelper.GetForumAsync(tuple.Parameter1, _data.Person.PersonCookie); _data.ForumCollection.Clear(); foreach (var item in json.forum) { ForumList forumList = new ForumList() { Title = item.title, Parameter = new Parameter() { Parameter1 = item.fid, Parameter2 = "fid" } }; _data.ForumCollection.Add(forumList); } }
/// <summary> /// Creates a new sub forum. Switches back to regular view mode. /// </summary> protected void ForumSubmit_Click(object sender, EventArgs e) { if (!IsValid) { return; } Manager.CreateForum(CurrentPageLink, ForumTitleTextBox.Text, AllowThreadsCheckBox.Checked, AllowForumsCheckBox.Checked, IconDropDown.SelectedValue); _evenForum = true; ForumList.DataBind(); Submenu submenu = Page.FindControl <Submenu>(); if (submenu != null) { submenu.DataBind(); } SwitchView(ViewMode.ListView); }
private async Task SignAll(int retryTime) { var forums = new ForumList(); try { var forumStr = await BaiduNet.GetForum(BDUSS); forums.Parse(forumStr); Console.WriteLine(@"获取贴吧列表成功!"); Console.WriteLine(forums.ToString()); } catch { Console.WriteLine(@"获取贴吧列表失败!"); return; } int success; List <Forum> failList; (success, failList) = await SignAll(forums.Forums, forums.Tbs); if (success != forums.Forums.Count) { Console.WriteLine(@"存在签到失败贴吧,重试开始"); for (var i = 0; i < retryTime; ++i) { Console.WriteLine($@"第 {i + 1} 次重试"); int successT; (successT, failList) = await SignAll(failList, forums.Tbs); success += successT; if (success == forums.Forums.Count) { break; } } } Console.WriteLine($@"签到完成:{success}/{forums.Forums.Count}"); }
private void CachePublicForumList() { using (var db = new ZkDataContext()) { var accessibleThreads = db.ForumThreads.Where(x => x.RestrictedClanID == null && x.ForumCategory.ForumMode != ForumMode.Archive); cachedPublicForumList = new ForumList() { ForumItems = accessibleThreads.OrderByDescending(x => x.LastPost).Take(10).ToList().Select(x => new ForumItem() { ThreadID = x.ForumThreadID, Time = x.LastPost ?? x.Created, Url = $"{GlobalConst.BaseSiteUrl}/Forum/Thread/{x.ForumThreadID}", Header = x.Title, IsRead = false }).ToList() }; } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { var forums = Forums.GetAllForums(); ForumList.DataSource = forums; ForumList.DataBind(); AvForumsList.DataSource = forums; AvForumsList.DataTextField = "Subject"; AvForumsList.DataValueField = "Id"; ArchiveBtn.Enabled = false; Panel2.Visible = false; } else { Panel2.Visible = false; } Page.DataBind(); }
public async Task AddToCacheList(ForumList newForumlist) { FlashbackCacheList <Dictionary <string, ForumList> > fbCache; var dataToAdd = new Dictionary <string, ForumList> { { newForumlist.Id, newForumlist } }; if (!await FileHelper.FileExistsAsync(CACHEFILE)) { fbCache = new FlashbackCacheList <Dictionary <string, ForumList> >(); } else { fbCache = await FileHelper.ReadFileAsync <FlashbackCacheList <Dictionary <string, ForumList> > >(CACHEFILE); } fbCache.Add(dataToAdd); await FileHelper.WriteFileAsync(CACHEFILE, fbCache); }
/// <summary> /// Switches what is displayed in the forum page. /// <remarks> /// The different options are either the regular listing view, the view to add a new thread and the view to add a new sub forum. /// </remarks> /// </summary> /// <param name="mode">The view you want to switch to.</param> private void SwitchView(ViewMode mode) { switch (mode) { case ViewMode.ListView: ListThreadPanel.Visible = (bool)(CurrentPage["AllowThreads"] ?? false) || ThreadList.OfType <PageData>().Count() > 0; AddThreadButton.Visible = ((bool)(CurrentPage["AllowThreads"] ?? false)) && IsPoster; ListForumPanel.Visible = (bool)(CurrentPage["AllowForums"] ?? false) || ForumList.OfType <PageData>().Count() > 0; AddForumButton.Visible = ((bool)(CurrentPage["AllowForums"] ?? false)) && IsModerator; InformationPanel.Visible = !String.IsNullOrEmpty((string)CurrentPage["MainBody"]); ErrorPanel.Visible = NewThreadPanel.Visible = NewForumPanel.Visible = false; ButtonPanel.Visible = true; break; case ViewMode.AddThreadView: TitleTextBox.MaxLength = MAX_URL_LENGHT - Request.Path.Length; ListThreadPanel.Visible = ListForumPanel.Visible = NewForumPanel.Visible = InformationPanel.Visible = false; NewThreadPanel.Visible = true; ButtonPanel.Visible = false; break; case ViewMode.AddForumView: ForumTitleTextBox.MaxLength = 255 - Request.Path.Length; ListThreadPanel.Visible = ListForumPanel.Visible = NewThreadPanel.Visible = InformationPanel.Visible = false; NewForumPanel.Visible = true; ButtonPanel.Visible = false; break; case ViewMode.ErrorView: ListThreadPanel.Visible = ListForumPanel.Visible = NewThreadPanel.Visible = InformationPanel.Visible = false; ButtonPanel.Visible = false; ErrorPanel.Visible = true; break; } }
public void CopyTo(Array array, int index) { ForumList.CopyTo(array, index); }