Ejemplo n.º 1
0
        public void Insert(T obj, uint recordId, IEnumerable <string> propertyNames = null)
        {
            var indexTrees = this.indexTrees;

            if (propertyNames != null)
            {
                indexTrees = this.indexTrees
                             .Where(x => propertyNames.Contains(x.Key))
                             .ToDictionary(k => k.Key, v => v.Value);
            }

            var objProperties = obj
                                .GetType()
                                .GetProperties()
                                .ToList();

            foreach (var indexTree in indexTrees)
            {
                var jsonProperty = objProperties
                                   .Where(prop => prop.Name == indexTree.Key)
                                   .SingleOrDefault();

                if (jsonProperty != default(PropertyInfo))
                {
                    IndexTree indexForProperty = indexTree.Value;
                    object    value            = jsonProperty.GetValue(obj);
                    byte[]    byteValue        = ByteArrayHelper.GetBytes(value, jsonProperty.PropertyType);
                    indexForProperty.Insert(byteValue, recordId);
                }
            }
        }
Ejemplo n.º 2
0
        private IndexTree GetIndex(string propertyName)
        {
            IndexTree value = null;

            this.indexTrees.TryGetValue(propertyName, out value);
            return(value);
        }
Ejemplo n.º 3
0
        private Tuple <string, bool> CreateIndexOn(IndexDefinition definition, string pathToJsonDb)
        {
            bool indexExists = File.Exists(pathToJsonDb + "." + definition.PropertyName + ".idx");

            // Create Db file
            var dbFile = new FileStream(pathToJsonDb + "." + definition.PropertyName + ".idx", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 4096);

            this.indexFiles.Add(definition.PropertyName, dbFile);

            var indexTree = new IndexTree(
                new TreeDiskNodeManager <byte[], uint>(
                    new TreeByteArraySerializer(),
                    new TreeUIntSerializer(),
                    new RecordStorage(new BlockStorage(dbFile, 4096)),
                    ByteArrayComparer
                    ),
                definition.AllowDuplicateKeys
                );

            this.indexTrees.Add(definition.PropertyName, indexTree);

            return(new Tuple <string, bool>(definition.PropertyName, indexExists));
        }