public ChatRecordPage GetChatRecordPage(ChatRecordTimeScope timeScope, string senderID, string accepterID, int pageSize, int pageIndex) { var totalCount = 0; if (pageSize <= 0 || pageIndex < 0) { return(new ChatRecordPage(totalCount, pageIndex, new List <ChatMessageRecord>())); } if (!this.chatRecordTable.Contains(senderID)) { return(new ChatRecordPage(totalCount, pageIndex, new List <ChatMessageRecord>())); } var friends = this.chatRecordTable.Get(senderID); if (!friends.Contains(accepterID)) { return(new ChatRecordPage(totalCount, pageIndex, new List <ChatMessageRecord>())); } var records = friends.Get(accepterID); totalCount = records.Count; var pageCount = records.Count / pageSize; if (records.Count % pageSize > 0) { ++pageCount; } if (pageIndex == int.MaxValue) { pageIndex = pageCount - 1; } if (pageIndex >= pageCount) { return(new ChatRecordPage(totalCount, pageIndex, new List <ChatMessageRecord>())); } var page = new List <ChatMessageRecord>(); for (var i = pageIndex * pageSize; i < records.Count && page.Count <= pageSize; i++) { page.Add(records[i]); } return(new ChatRecordPage(totalCount, pageIndex, page)); }
public ChatRecordPage GetGroupChatRecordPage(ChatRecordTimeScope timeScope, string groupID, int pageSize, int pageIndex) { int totalCount = 0; if (pageSize <= 0 || pageIndex < 0) { return(new ChatRecordPage(totalCount, pageIndex, new List <ChatMessageRecord>())); } if (!this.groupChatRecordTable.Contains(groupID)) { return(new ChatRecordPage(totalCount, pageIndex, new List <ChatMessageRecord>())); } List <ChatMessageRecord> records = this.groupChatRecordTable.Get(groupID); totalCount = records.Count; int pageCount = records.Count / pageSize; if (records.Count % pageSize > 0) { ++pageCount; } if (pageIndex == int.MaxValue) { pageIndex = pageCount - 1; } if (pageIndex >= pageCount) { return(new ChatRecordPage(totalCount, pageIndex, new List <ChatMessageRecord>())); } List <ChatMessageRecord> page = new List <ChatMessageRecord>(); for (int i = pageIndex * pageSize; i < records.Count && page.Count <= pageSize; i++) { page.Add(records[i]); } return(new ChatRecordPage(totalCount, pageIndex, page));; }
public ChatRecordPage GetGroupChatRecordPage(ChatRecordTimeScope timeScope, string groupID, int pageSize, int pageIndex) { return this.dbPersister.GetGroupChatRecordPage(timeScope, groupID, pageSize, pageIndex); }
public ChatRecordPage GetChatRecordPage(ChatRecordTimeScope timeScope, string senderID, string accepterID, int pageSize, int pageIndex) { return this.dbPersister.GetChatRecordPage(timeScope, senderID, accepterID, pageSize, pageIndex); }
public ChatRecordPage GetGroupNoticeRecordPage(ChatRecordTimeScope timeScope, string groupID, int pageSize, int pageIndex) { return(this.dbPersister.GetGroupNoticeRecordPage(timeScope, groupID, pageSize, pageIndex)); }
public ChatRecordPage GetChatRecordPage(ChatRecordTimeScope timeScope, string senderID, string accepterID, int pageSize, int pageIndex) { return(this.dbPersister.GetChatRecordPage(timeScope, senderID, accepterID, pageSize, pageIndex)); }
private void ShowRecord(int pageIndex, bool allowCache) { if (this.remotePersister == null) //还未完成构造 { return; } if (pageIndex != int.MaxValue) { if (pageIndex + 1 > this.totalPageCount) { pageIndex = this.totalPageCount - 1; } if (pageIndex < 0) { pageIndex = 0; } if (this.currentPageIndex == pageIndex && allowCache) { this.toolStripTextBox_pageIndex.Text = (pageIndex + 1).ToString(); return; } } this.Cursor = Cursors.WaitCursor; try { ChatRecordTimeScope timeScope = ChatRecordTimeScope.All; DateTime now = DateTime.Now; if (this.skinComboBox1.SelectedIndex == 0) //一周 { timeScope = ChatRecordTimeScope.RecentWeek; } else if (this.skinComboBox1.SelectedIndex == 1)//一月 { timeScope = ChatRecordTimeScope.RecentMonth; } else if (this.skinComboBox1.SelectedIndex == 2)//三月 { timeScope = ChatRecordTimeScope.Recent3Month; } else //全部 { } ChatRecordPage page = null; if (this.isGroupChat) { page = this.CurrentPersister.GetGroupNoticeRecordPage(timeScope, this.group.Arg1, this.pageSize, pageIndex); } else { page = this.CurrentPersister.GetChatRecordPage(timeScope, my.Arg1, friend.Arg1, this.pageSize, pageIndex); } this.chatBox_history.Clear(); if (page == null || page.Content.Count == 0) { MessageBoxEx.Show("没有消息记录!"); return; } this.currentPageIndex = page.PageIndex; this.toolStripTextBox_pageIndex.Text = (this.currentPageIndex + 1).ToString(); for (int i = 0; i < page.Content.Count; i++) { ChatMessageRecord record = page.Content[i]; byte[] decrypted = record.Content; if (this.skinRadioButton_Server.Checked) { if (GlobalResourceManager.Des3Encryption != null) { decrypted = GlobalResourceManager.Des3Encryption.Decrypt(decrypted); } } // ChatBoxContent content = CompactPropertySerializer.Default.Deserialize<ChatBoxContent>(decrypted, 0); ChatBoxContent content = null; if (content == null) { content = new ChatBoxContent(); content.Text = System.Text.Encoding.UTF8.GetString(decrypted); } if (this.isGroupChat) { if (record.SpeakerID == this.my.Arg1) { this.AppendChatBoxContent(record.OccureTime, string.Format("{0}({1})", this.my.Arg2, record.SpeakerID), content, Color.Green); } else { string name = this.userNameGetter.GetUserName(record.SpeakerID) ?? record.SpeakerID; this.AppendChatBoxContent(record.OccureTime, string.Format("{0}({1})", name, record.SpeakerID), content, Color.Blue); } } else { if (record.SpeakerID == this.my.Arg1) { this.AppendChatBoxContent(record.OccureTime, this.my.Arg2, content, Color.Green); } else { this.AppendChatBoxContent(record.OccureTime, this.friend.Arg2, content, Color.Blue); } } } this.chatBox_history.SelectionStart = 0; this.chatBox_history.ScrollToCaret(); int pageCount = page.TotalCount / this.pageSize; if (page.TotalCount % this.pageSize > 0) { ++pageCount; } this.totalPageCount = pageCount; this.toolStripLabel_totalCount.Text = string.Format("/ {0}页", this.totalPageCount); this.toolStripTextBox_pageIndex.Focus(); } catch (Exception ee) { MessageBoxEx.Show(ee.Message); } finally { this.Cursor = Cursors.Default; } }
/// <summary> /// 获取一页与好友的聊天记录。 /// </summary> /// <param name="myID">自己的UserID</param> /// <param name="friendID">好友的ID</param> /// <param name="pageSize">页大小</param> /// <param name="pageIndex">页索引</param> /// <returns>聊天记录页</returns> public ChatRecordPage GetChatRecordPage(ChatRecordTimeScope chatRecordTimeScope, string myID, string friendID, int pageSize, int pageIndex) { if (this.transactionScopeFactory == null) { return(new ChatRecordPage(0, 0, new List <ChatMessageRecord>())); } DateTimeScope timeScope = null; DateTime now = DateTime.Now; if (chatRecordTimeScope == ChatRecordTimeScope.RecentWeek) //一周 { timeScope = new DateTimeScope(now.AddDays(-7), now); } else if (chatRecordTimeScope == ChatRecordTimeScope.RecentMonth)//一月 { timeScope = new DateTimeScope(now.AddDays(-31), now); } else if (chatRecordTimeScope == ChatRecordTimeScope.Recent3Month)//三月 { timeScope = new DateTimeScope(now.AddDays(-91), now); } else //全部 { } IFilterTree tree1 = new SimpleFilterTree(new Filter(ChatMessageRecord._SpeakerID, myID), new Filter(ChatMessageRecord._AudienceID, friendID)); IFilterTree tree2 = new SimpleFilterTree(new Filter(ChatMessageRecord._SpeakerID, friendID), new Filter(ChatMessageRecord._AudienceID, myID)); IFilterTree tree = new ComplexFilterTree(LogicType.Or, tree1, tree2); if (timeScope != null) { tree = new ComplexFilterTree(LogicType.And, tree, new Filter(ChatMessageRecord._OccureTime, new DateTime[] { timeScope.StartDate, timeScope.EndDate }, ComparisonOperators.BetweenAnd)); } //最后一页 if (pageIndex == int.MaxValue) { int total = 0; using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope()) { IOrmAccesser <ChatMessageRecord> accesser = scope.NewOrmAccesser <ChatMessageRecord>(); total = (int)accesser.GetCount(tree); scope.Commit(); } int pageCount = total / pageSize; if (total % pageSize > 0) { pageCount += 1; } pageIndex = pageCount - 1; } int totalCount = 0; ChatMessageRecord[] page = null; using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope()) { IOrmAccesser <ChatMessageRecord> accesser = scope.NewOrmAccesser <ChatMessageRecord>(); page = accesser.GetPage(tree, pageSize, pageIndex, ChatMessageRecord._AutoID, true, out totalCount); scope.Commit(); } return(new ChatRecordPage(totalCount, pageIndex, new List <ChatMessageRecord>(page))); }
/// <summary> /// 获取一页群聊天记录。 /// </summary> /// <param name="groupID">群ID</param> /// <param name="pageSize">页大小</param> /// <param name="pageIndex">页索引</param> /// <returns>聊天记录页</returns> public ChatRecordPage GetGroupChatRecordPage(ChatRecordTimeScope chatRecordTimeScope, string groupID, int pageSize, int pageIndex) { if (this.transactionScopeFactory == null) { return(new ChatRecordPage(0, 0, new List <ChatMessageRecord>())); } DateTimeScope timeScope = null; var now = DateTime.Now; if (chatRecordTimeScope == ChatRecordTimeScope.RecentWeek) //一周 { timeScope = new DateTimeScope(now.AddDays(-7), now); } else if (chatRecordTimeScope == ChatRecordTimeScope.RecentMonth)//一月 { timeScope = new DateTimeScope(now.AddDays(-31), now); } else if (chatRecordTimeScope == ChatRecordTimeScope.Recent3Month)//三月 { timeScope = new DateTimeScope(now.AddDays(-91), now); } else //全部 { } var filterList = new List <Filter>(); filterList.Add(new Filter(ChatMessageRecord._AudienceID, groupID)); filterList.Add(new Filter(ChatMessageRecord._IsGroupChat, true)); if (timeScope != null) { filterList.Add(new Filter(ChatMessageRecord._OccureTime, new DateTime[] { timeScope.StartDate, timeScope.EndDate }, ComparisonOperators.BetweenAnd)); } var tree = new SimpleFilterTree(filterList); //最后一页 if (pageIndex == int.MaxValue) { var total = 0; using (var scope = this.transactionScopeFactory.NewTransactionScope()) { var accesser = scope.NewOrmAccesser <ChatMessageRecord>(); total = (int)accesser.GetCount(tree); scope.Commit(); } var pageCount = total / pageSize; if (total % pageSize > 0) { pageCount += 1; } pageIndex = pageCount - 1; } var totalCount = 0; ChatMessageRecord[] page = null; using (var scope = this.transactionScopeFactory.NewTransactionScope()) { var accesser = scope.NewOrmAccesser <ChatMessageRecord>(); page = accesser.GetPage(tree, pageSize, pageIndex, ChatMessageRecord._AutoID, true, out totalCount); scope.Commit(); } return(new ChatRecordPage(totalCount, pageIndex, new List <ChatMessageRecord>(page))); }
public ChatRecordPage GetGroupChatRecordPage(ChatRecordTimeScope timeScope, string groupID, int pageSize, int pageIndex) { ChatRecordPage page = this.globalCache.GetGroupChatRecordPage(timeScope, groupID, pageSize, pageIndex); return(page); }
/// <summary> /// 获取一页群聊天记录。 /// </summary> /// <param name="groupID">群ID</param> /// <param name="pageSize">页大小</param> /// <param name="pageIndex">页索引</param> /// <returns>聊天记录页</returns> public ChatRecordPage GetGroupChatRecordPage(ChatRecordTimeScope chatRecordTimeScope, string groupID, int pageSize, int pageIndex) { if (this.transactionScopeFactory == null) { return new ChatRecordPage(0, 0, new List<ChatMessageRecord>()); } DateTimeScope timeScope = null; DateTime now = DateTime.Now; if (chatRecordTimeScope == ChatRecordTimeScope.RecentWeek) //一周 { timeScope = new DateTimeScope(now.AddDays(-7), now); } else if (chatRecordTimeScope == ChatRecordTimeScope.RecentMonth)//一月 { timeScope = new DateTimeScope(now.AddDays(-31), now); } else if (chatRecordTimeScope == ChatRecordTimeScope.Recent3Month)//三月 { timeScope = new DateTimeScope(now.AddDays(-91), now); } else //全部 { } List<Filter> filterList = new List<Filter>(); filterList.Add(new Filter(ChatMessageRecord._AudienceID, groupID)); filterList.Add(new Filter(ChatMessageRecord._IsGroupChat, true)); if (timeScope != null) { filterList.Add(new Filter(ChatMessageRecord._OccureTime, new DateTime[] { timeScope.StartDate, timeScope.EndDate }, ComparisonOperators.BetweenAnd)); } SimpleFilterTree tree = new SimpleFilterTree(filterList); //最后一页 if (pageIndex == int.MaxValue) { int total = 0; using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope()) { IOrmAccesser<ChatMessageRecord> accesser = scope.NewOrmAccesser<ChatMessageRecord>(); total = (int)accesser.GetCount(tree); scope.Commit(); } int pageCount = total / pageSize; if (total % pageSize > 0) { pageCount += 1; } pageIndex = pageCount - 1; } int totalCount = 0; ChatMessageRecord[] page = null; using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope()) { IOrmAccesser<ChatMessageRecord> accesser = scope.NewOrmAccesser<ChatMessageRecord>(); page = accesser.GetPage(tree, pageSize, pageIndex, ChatMessageRecord._AutoID, true, out totalCount); scope.Commit(); } return new ChatRecordPage(totalCount, pageIndex, new List<ChatMessageRecord>(page)); }
public ChatRecordPage GetGroupChatRecordPage(ChatRecordTimeScope timeScope, string groupID, int pageSize, int pageIndex) { ChatRecordPage page = this.globalCache.GetGroupChatRecordPage(timeScope ,groupID, pageSize, pageIndex); return page; }