Exemplo n.º 1
0
        public BtreeIndex(string fieldname, bool unique, int keylength, string fullIndexFileName, int MaxCacheLevel = 0)
        {
            this.fieldname = fieldname;
            this.unique    = unique;
            Type keytype = typeof(T);

            this.keylength = Helper.KeyHelper.GetKeyLen(keytype, keylength);

            this.fullindexfilename = fullIndexFileName;

            this.MaxCacheLevel = MaxCacheLevel;

            this.fullduplicatefilename = fullindexfilename + ".duplicate";

            Helper.IndexHelper.VerifyIndexType(keytype);

            this.Converter        = ObjectContainer.GetConverter <T>();
            this.EqualityComparer = new EqualityComparer(this.keylength);
            this.Comparer         = ObjectContainer.getComparer(keytype, keylength);

            if (keytype == typeof(string))
            {
                isString = true;
            }
            else
            {
                isString = false;
            }
        }
Exemplo n.º 2
0
        private void init(string FieldName, int len)
        {
            if (len <= 0)
            {
                throw new Exception("Len must be at least 1");
            }

            this.FieldName = FieldName;
            this.Length    = len;

            this.FieldNameHash = Helper.ObjectHelper.GetHashCode(this.FieldName);
            var fieldnamehashbytes = BitConverter.GetBytes(FieldNameHash);

            this.Get      = Helper.ObjectHelper.GetGetValue <TValue, TColumn>(FieldName);
            this.Set      = Helper.ObjectHelper.GetSetValue <TValue, TColumn>(FieldName);
            ByteConverter = ObjectContainer.GetConverter <TColumn>();

            this.IsString = this.DataType == typeof(string);

            this.FieldNameLengthBytes = new byte[8];
            var lenbytes = BitConverter.GetBytes(this.Length);

            System.Buffer.BlockCopy(fieldnamehashbytes, 0, this.FieldNameLengthBytes, 0, 4);
            System.Buffer.BlockCopy(lenbytes, 0, this.FieldNameLengthBytes, 4, 4);
        }
Exemplo n.º 3
0
        /// <summary>
        /// If column's type is datetime,the block data will store datetime.ticks in byte array
        /// but the compare value(this.ValueBytes) store (datetime-DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc)) in byte array
        /// so we need change datetime to the same byte array format.
        /// </summary>
        /// <param name="columnbytes"></param>
        /// <returns></returns>
        private static byte[] ConvertDatetimeBytes(byte[] columnbytes)
        {
            var datetime  = Helper.DateTimeUtcHelper.ToDateTime(columnbytes);
            var converter = ObjectContainer.GetConverter <DateTime>();

            columnbytes = converter.ToByte(datetime);
            return(columnbytes);
        }
Exemplo n.º 4
0
        public RepeatTask(string FolderName)
        {
            this.RecordFile  = FileNameGenerator.GetRepeatRecordFileName(FolderName);
            this.ContentFile = FileNameGenerator.GetRepeatContentFileName(FolderName);


            this.ValueConverter = ObjectContainer.GetConverter <TValue>();

            Verify();
        }
Exemplo n.º 5
0
        public ScheduleContent(int DayInt, ISchedule schedule)
        {
            this._schedule = schedule;

            this.FileName     = FileNameGenerator.GetContentFileName(DayInt);
            this.DayInt       = DayInt;
            this.FullFileName = FileNameGenerator.GetContentFullFileName(DayInt, schedule);

            if (!File.Exists(this.FullFileName))
            {
                File.WriteAllText(this.FullFileName, "schedule content file, do not modify\r\n");
            }

            this.ValueConverter = ObjectContainer.GetConverter <TValue>();
        }
Exemplo n.º 6
0
        public List <LogEntry> GetLogItems(SiteCluster cluster)
        {
            if (cluster == null)
            {
                return(new List <LogEntry>());
            }

            var keyconverter = ObjectContainer.GetConverter <Guid>();

            var currentlogid = cluster.Version;

            List <LogEntry> result = new List <LogEntry>();

            var alllogs = this.SiteDb.Log.Store.Where(o => o.Id > currentlogid).SelectAll();

            foreach (var item in alllogs.OrderByDescending(o => o.Id))
            {
                if (item.KeyBytes == null)
                {
                    continue;
                }
                Guid key           = keyconverter.FromByte(item.KeyBytes);
                var  currentrecord = result.Find(o => o.KeyHash == item.KeyHash);
                if (currentrecord == null)
                {
                    result.Add(item);
                }
                else
                {
                    if (item.EditType == EditType.Add)
                    {
                        if (currentrecord.EditType == EditType.Delete)
                        {
                            // new added item also get deleted at the end...==> should not push to it.
                            result.Remove(currentrecord);
                        }
                        else if (currentrecord.EditType == EditType.Update)
                        {
                            currentrecord.EditType = EditType.Add;
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        public Filter <TKey, TValue> WhereEqual(string FieldOrPropertyName, Guid Value)
        {
            FilterItem item = new FilterItem();

            item.Compare = Comparer.EqualTo;

            item.FieldOrProperty = FieldOrPropertyName;
            item.FieldType       = typeof(Guid);
            IByteConverter <Guid> x = ObjectContainer.GetConverter <Guid>();

            item.Value = x.ToByte(Value);

            item.Length = 16;

            this.items.Add(item);

            return(this);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public DateTimeColumn(string FieldName)
        {
            this.FieldName = FieldName;
            this.Get       = Helper.ObjectHelper.GetGetValue <TValue, DateTime>(FieldName);
            this.Set       = Helper.ObjectHelper.GetSetValue <TValue, DateTime>(FieldName);

            byteConverter = ObjectContainer.GetConverter <Int64>();

            this.DataType = typeof(DateTime);

            this.FieldNameHash = Helper.ObjectHelper.GetHashCode(this.FieldName);
            var fieldnamehashbytes = BitConverter.GetBytes(FieldNameHash);

            this.IsString = false;

            this.FieldNameLengthBytes = new byte[8];
            var lenbytes = BitConverter.GetBytes(this.Length);

            System.Buffer.BlockCopy(fieldnamehashbytes, 0, this.FieldNameLengthBytes, 0, 4);
            System.Buffer.BlockCopy(lenbytes, 0, this.FieldNameLengthBytes, 4, 4);
        }
Exemplo n.º 10
0
        public EnumColumn(string FieldName, Type EnumClassType)
        {
            this.FieldName = FieldName;
            this.Get       = ObjectHelper.GetGetEnumObjectValue <TValue>(FieldName);
            this.Set       = ObjectHelper.GetSetObjectValue <TValue>(FieldName, EnumClassType);

            byteConverter = ObjectContainer.GetConverter <Int32>();

            this.DataType = EnumClassType;

            this.FieldNameHash = Helper.ObjectHelper.GetHashCode(this.FieldName);
            var fieldnamehashbytes = BitConverter.GetBytes(FieldNameHash);

            this.IsString = false;

            this.FieldNameLengthBytes = new byte[8];
            var lenbytes = BitConverter.GetBytes(this.Length);

            System.Buffer.BlockCopy(fieldnamehashbytes, 0, this.FieldNameLengthBytes, 0, 4);
            System.Buffer.BlockCopy(lenbytes, 0, this.FieldNameLengthBytes, 4, 4);
        }
Exemplo n.º 11
0
        private byte[] getByteValue(Type datatype, object objectvalue)
        {
            if (datatype == typeof(Int32))
            {
                int value = Convert.ToInt32(objectvalue);
                IByteConverter <Int32> x = ObjectContainer.GetConverter <Int32>();
                return(x.ToByte(value));
            }
            else if (datatype == typeof(Int16))
            {
                Int16 value = Convert.ToInt16(objectvalue);
                IByteConverter <Int16> x = ObjectContainer.GetConverter <Int16>();
                return(x.ToByte(value));
            }
            else if (datatype == typeof(string))
            {
                string value = Convert.ToString(objectvalue);
                IByteConverter <string> x = ObjectContainer.GetConverter <string>();

                return(x.ToByte(value));
            }
            else if (datatype == typeof(Int64))
            {
                Int64 value = Convert.ToInt64(objectvalue);
                IByteConverter <Int64> x = ObjectContainer.GetConverter <Int64>();
                return(x.ToByte(value));
            }
            else if (datatype == typeof(float))
            {
                float value = Convert.ToSingle(objectvalue);
                IByteConverter <float> x = ObjectContainer.GetConverter <float>();
                return(x.ToByte(value));
            }
            else if (datatype == typeof(double))
            {
                double value = Convert.ToDouble(objectvalue);
                IByteConverter <double> x = ObjectContainer.GetConverter <double>();
                return(x.ToByte(value));
            }
            else if (datatype == typeof(decimal))
            {
                double value = Convert.ToDouble(objectvalue);
                IByteConverter <double> x = ObjectContainer.GetConverter <double>();
                return(x.ToByte(value));
            }

            else if (datatype == typeof(Guid))
            {
                Guid value = Guid.Parse(Convert.ToString(objectvalue));

                if (value == null)
                {
                    return(null);
                }
                else
                {
                    IByteConverter <Guid> x = ObjectContainer.GetConverter <Guid>();
                    return(x.ToByte(value));
                }
            }

            else if (datatype == typeof(bool))
            {
                bool value = Convert.ToBoolean(objectvalue);

                byte[] valuebyte = new byte[1];
                if (value)
                {
                    valuebyte[0] = 1;
                }
                else
                {
                    valuebyte[0] = 0;
                }

                return(valuebyte);
            }

            else if (datatype == typeof(DateTime))
            {
                DateTime datevalue = (DateTime)objectvalue;

                IByteConverter <DateTime> x = ObjectContainer.GetConverter <DateTime>();
                return(x.ToByte(datevalue));
            }

            else if (datatype == typeof(byte))
            {
                byte[] valuebyte = new byte[1];
                valuebyte[0] = Convert.ToByte(objectvalue);

                return(valuebyte);
            }

            else if (datatype.IsEnum)
            {
                int intvalue             = (int)objectvalue;
                IByteConverter <Int32> x = ObjectContainer.GetConverter <Int32>();
                return(x.ToByte(intvalue));
            }
            else
            {
                throw new Exception("data type not supported for filter");
            }
        }
Exemplo n.º 12
0
 public QueueContent(string fullfilename)
 {
     this.FullFileName = fullfilename;
     _initialize();
     this.ValueConverter = ObjectContainer.GetConverter <TValue>();
 }