Ejemplo n.º 1
0
        /// <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)));
        }
Ejemplo n.º 2
0
        /// <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));
        }