Exemple #1
0
        public Filter <TKey, TValue> Where(string FieldOrPropertyName, Comparer comparer, DateTime CompareValue, DateTimeScope scope)
        {
            FilterItem item = new FilterItem();

            item.Compare = comparer;

            item.TimeScope = scope;

            item.FieldOrProperty = FieldOrPropertyName;
            item.FieldType       = typeof(DateTime);

            item.Length = 8;

            IByteConverter <DateTime> x = ObjectContainer.GetConverter <DateTime>();

            item.Value = x.ToByte(CompareValue);

            this.items.Add(item);

            return(this);
        }
Exemple #2
0
        /// <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)));
        }
Exemple #3
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)));
        }
        private static (DateTimeOperation, int) GetDateTimeOperation(string parameter, DateTimeScope scope, DayOfWeek firstDayOfWeek, DateTime referenceDate)
        {
            if (string.IsNullOrWhiteSpace(parameter))
            {
                return(DateTimeOperation.None, 0);
            }

            if (parameter[0] == '+' || parameter[0] == '-')
            {
                if (!int.TryParse(parameter, out int result))
                {
                    throw new ArgumentException($"The value following the sign must be an integer. {parameter} given.");
                }

                return(DateTimeOperation.Add, result);
            }

            if (int.TryParse(parameter, out int result2))
            {
                return(DateTimeOperation.SetValue, result2);
            }


            if (parameter.Equals(Previous, StringComparison.OrdinalIgnoreCase))
            {
                return(DateTimeOperation.Add, -1);
            }

            if (parameter.Equals(Next, StringComparison.OrdinalIgnoreCase))
            {
                return(DateTimeOperation.Add, 1);
            }

            if (parameter.Equals(First, StringComparison.OrdinalIgnoreCase))
            {
                switch (scope)
                {
                case DateTimeScope.Year:
                    return(DateTimeOperation.SetValue, FirstYear);

                case DateTimeScope.Month:
                    return(DateTimeOperation.SetValue, FirstMonth);

                case DateTimeScope.Day:
                    return(DateTimeOperation.SetValue, FirstDay);

                case DateTimeScope.Hour:
                    return(DateTimeOperation.SetValue, FirstHour);

                case DateTimeScope.Minute:
                    return(DateTimeOperation.SetValue, FirstMinute);

                case DateTimeScope.Second:
                    return(DateTimeOperation.SetValue, FirstSecond);

                case DateTimeScope.Millisecond:
                    return(DateTimeOperation.SetValue, FirstMillisecond);
                }
            }

            if (parameter.Equals(Last, StringComparison.OrdinalIgnoreCase))
            {
                switch (scope)
                {
                case DateTimeScope.Year:
                    return(DateTimeOperation.SetValue, LastYear);

                case DateTimeScope.Month:
                    return(DateTimeOperation.SetValue, LastMonth);

                case DateTimeScope.Day:
                    return(DateTimeOperation.SetValue, DateTime.DaysInMonth(referenceDate.Year, referenceDate.Month));

                case DateTimeScope.Hour:
                    return(DateTimeOperation.SetValue, LastHour);

                case DateTimeScope.Minute:
                    return(DateTimeOperation.SetValue, LastMinute);

                case DateTimeScope.Second:
                    return(DateTimeOperation.SetValue, LastSecond);

                case DateTimeScope.Millisecond:
                    return(DateTimeOperation.SetValue, LastMillisecond);
                }
            }


            switch (scope)
            {
            case DateTimeScope.Month:
                return(GetDateTimeMonthOperation(parameter, referenceDate));

            case DateTimeScope.Day:
                return(GetDateTimeDayOperation(parameter, firstDayOfWeek, referenceDate));
            }

            throw new ArgumentException($"Date time {scope} operation '{parameter}' is not supported.");
        }