コード例 #1
0
ファイル: ColumnEvaluator.cs プロジェクト: weedkiller/Kooboo
        private int maxColumnLength; // the setting defined column length.

        public ColumnEvaluator(Type datatype, Comparer comparertype, IComparer <byte[]> bytecompare, byte[] valuebytes, int columnlength, int maxcolumnlength)
        {
            this.DataType        = datatype;
            this.compareType     = comparertype;
            this.byteCompare     = bytecompare;
            this.ValueBytes      = valuebytes;
            this.columnLength    = columnlength;
            this.maxColumnLength = maxcolumnlength;

            if (this.DataType == typeof(DateTime))
            {
                this.TargetDate = DateTimeUtcHelper.ToDateTime(this.ValueBytes);
                this.IsDateTime = true;
            }

            if (this.DataType == typeof(string))
            {
                this.TargetString = System.Text.Encoding.UTF8.GetString(this.ValueBytes);
                if (this.TargetString != null)
                {
                    this.TargetString = this.TargetString.Trim('\0');
                    this.TargetString = this.TargetString.Trim();
                }

                this.IsString = true;
            }
        }
コード例 #2
0
ファイル: ColumnEvaluator.cs プロジェクト: weedkiller/Kooboo
        /// <summary>
        /// test column value match the condition.
        /// </summary>
        /// <param name="columnbytes"></param>
        /// <returns></returns>
        public virtual bool isMatch(byte[] columnbytes)
        {
            if (columnbytes == null)
            {
                return(false);
            }
            if (this.IsDateTime)
            {
                var coltime = DateTimeUtcHelper.ToDateTime(columnbytes);
                return(DateTimeUtcHelper.Compare(compareType, coltime, this.TargetDate));
            }
            else if (this.IsString)
            {
                var currentValue = System.Text.Encoding.UTF8.GetString(columnbytes);
                if (currentValue != null)
                {
                    currentValue = currentValue.Trim('\0');
                    currentValue = currentValue.Trim();
                }
                return(Helper.StringHelper.Compare(this.compareType, currentValue, this.TargetString));
            }
            else
            {
                switch (compareType)
                {
                case Comparer.EqualTo:
                    return(this.byteCompare.Compare(columnbytes, this.ValueBytes) == 0);

                case Comparer.GreaterThan:
                    return(this.byteCompare.Compare(columnbytes, this.ValueBytes) > 0);

                case Comparer.GreaterThanOrEqual:
                    return(this.byteCompare.Compare(columnbytes, this.ValueBytes) >= 0);

                case Comparer.LessThan:
                    return(this.byteCompare.Compare(columnbytes, this.ValueBytes) < 0);

                case Comparer.LessThanOrEqual:
                    return(this.byteCompare.Compare(columnbytes, this.ValueBytes) <= 0);

                case Comparer.NotEqualTo:

                    return(!Btree.Comparer.ByteEqualComparer.isEqual(columnbytes, this.ValueBytes, columnLength));

                case Comparer.StartWith:
                    return(Btree.Comparer.MoreComparer.StartWith(columnbytes, this.ValueBytes, this.columnLength));

                case Comparer.Contains:
                    return(Btree.Comparer.MoreComparer.Contains(columnbytes, this.ValueBytes, this.columnLength, this.maxColumnLength));

                default:
                    return(false);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// test column value match the condition.
        /// </summary>
        /// <param name="columnbytes"></param>
        /// <returns></returns>
        public virtual bool isMatch(byte[] columnbytes)
        {
            if (columnbytes == null)
            {
                return(false);
            }
            if (this.DataType == typeof(DateTime))
            {
                var coltime = DateTimeUtcHelper.ToDateTime(columnbytes);

                return(DateTimeUtcHelper.Compare(compareType, coltime, this.DateTimeValue));
            }
            else
            {
                switch (compareType)
                {
                case Comparer.EqualTo:
                    return(this.byteCompare.Compare(columnbytes, this.ValueBytes) == 0);

                case Comparer.GreaterThan:
                    return(this.byteCompare.Compare(columnbytes, this.ValueBytes) > 0);

                case Comparer.GreaterThanOrEqual:
                    return(this.byteCompare.Compare(columnbytes, this.ValueBytes) >= 0);

                case Comparer.LessThan:
                    return(this.byteCompare.Compare(columnbytes, this.ValueBytes) < 0);

                case Comparer.LessThanOrEqual:
                    return(this.byteCompare.Compare(columnbytes, this.ValueBytes) <= 0);

                case Comparer.NotEqualTo:

                    return(!Btree.Comparer.ByteEqualComparer.isEqual(columnbytes, this.ValueBytes, columnLength));


                case Comparer.StartWith:
                    return(Btree.Comparer.MoreComparer.StartWith(columnbytes, this.ValueBytes, this.columnLength));

                case Comparer.Contains:
                    return(Btree.Comparer.MoreComparer.Contains(columnbytes, this.ValueBytes, this.columnLength, this.maxColumnLength));

                default:
                    return(false);
                }
            }
        }
コード例 #4
0
 public static object FromDateTimeBytes(byte[] bytes)
 {
     return(DateTimeUtcHelper.ToDateTime(bytes));
 }
コード例 #5
0
        public static byte[] DateTimeToBytes(object value)
        {
            DateTime datetime = Convert.ToDateTime(value);

            return(DateTimeUtcHelper.ToBytes(datetime));
        }
コード例 #6
0
 public static DateTime ToDateTime(byte[] bytes)
 {
     return(DateTimeUtcHelper.ToDateTime(bytes));
 }
コード例 #7
0
 public static byte[] ToBytes(DateTime value)
 {
     return(DateTimeUtcHelper.ToBytes(value));
 }