Example #1
0
        public async Task Should_fill_them_even_fuller()
        {
            DateTime currentTime = DateTime.UtcNow;

            var cache = new GreenCache <SimpleValue>(100, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(60), () => currentTime);

            var index = cache.AddIndex("id", x => x.Id);

            for (int i = 0; i < 200; i++)
            {
                SimpleValue simpleValue = await index.Get($"key{i}", SimpleValueFactory.Healthy);

                if (i % 2 == 0)
                {
                    currentTime = currentTime.Add(TimeSpan.FromSeconds(1));
                }
            }

            await Task.Delay(100);

            Assert.That(cache.Statistics.Count, Is.EqualTo(101));

            Assert.That(cache.Statistics.ValidityCheckInterval, Is.EqualTo(TimeSpan.FromMilliseconds(250)));
            Assert.That(cache.Statistics.OldestBucketIndex, Is.EqualTo(50));
            Assert.That(cache.Statistics.CurrentBucketIndex, Is.EqualTo(100));


            var values = cache.GetAll().ToArray();

            Assert.That(values.Length, Is.EqualTo(101));
        }
Example #2
0
        public async Task Should_update_the_second_index_once_removed()
        {
            DateTime currentTime = DateTime.UtcNow;

            var cache = new GreenCache <SimpleValue>(100, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(60), () => currentTime);

            var index      = cache.AddIndex("id", x => x.Id);
            var valueIndex = cache.AddIndex("value", x => x.Value);

            for (int i = 0; i < 100; i++)
            {
                SimpleValue simpleValue = await index.Get($"key{i}", SimpleValueFactory.Healthy);
            }

            await Task.Delay(100);

            Assert.That(cache.Statistics.Count, Is.EqualTo(100));

            var result = await valueIndex.Get("The key is key27");

            Assert.That(result.Id, Is.EqualTo("key27"));

            valueIndex.Remove("The key is key29");

            await Task.Delay(10);

            Assert.That(async() => await index.Get("key29"), Throws.TypeOf <KeyNotFoundException>());

            Assert.That(cache.Statistics.Count, Is.EqualTo(99));
            Assert.That(cache.Statistics.Hits, Is.EqualTo(1));
            Assert.That(cache.Statistics.Misses, Is.EqualTo(101));
        }
Example #3
0
        public SimpleValue FillSimpleValue(SimpleValue simpleValue)
        {
            string  type    = BinderHelper.IsDefault(explicitType) ? returnedClassName : explicitType;
            TypeDef typeDef = mappings.GetTypeDef(type);

            if (typeDef != null)
            {
                type = typeDef.TypeClass;
                simpleValue.TypeParameters = typeDef.Parameters;
            }
            if (typeParameters != null && typeParameters.Count != 0)
            {
                //explicit type params takes precedence over type def params
                simpleValue.TypeParameters = typeParameters;
            }
            simpleValue.TypeName = type;
            if (persistentClassName != null)
            {
                simpleValue.SetTypeUsingReflection(persistentClassName, propertyName, "");
            }
            foreach (Ejb3Column column in columns)
            {
                column.linkWithValue(simpleValue);
            }
            return(simpleValue);
        }
        private static RootClass CreateMappingClasses()
        {
            var classMapping     = new RootClass();
            var componentMapping = new NHibernate.Mapping.Component(classMapping);

            var componentPropertyMapping = new Property(componentMapping);

            componentPropertyMapping.Name = "ComponentPropertyInClass";
            classMapping.AddProperty(componentPropertyMapping);

            var stringValue = new SimpleValue();

            stringValue.TypeName = typeof(string).FullName;

            var stringPropertyInComponentMapping = new Property(stringValue);

            stringPropertyInComponentMapping.Name = "StringPropertyInComponent";
            componentMapping.AddProperty(stringPropertyInComponentMapping);

            var componentType = (IAbstractComponentType)componentMapping.Type;

            Assume.That(CascadeStyle.None == stringPropertyInComponentMapping.CascadeStyle);
            Assume.That(CascadeStyle.None == componentType.GetCascadeStyle(0));
            Assume.That(CascadeStyle.None == componentPropertyMapping.CascadeStyle);

            return(classMapping);
        }
        public void CanConvertToStringWithFormat(SimpleValue value, string format, string expectedValue)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("ru-RU");
            var actualValue = value.ToString(format);

            Assert.AreEqual(expectedValue, actualValue);
        }
Example #6
0
        private static void AddColumn(PersistentClass mapping, string columnName, Type accessorType)
        {
            var  typeName   = DICT_TYPE_TO_NAME[accessorType];
            bool isNullable = typeName[typeName.Length - 1] == '?';

            if (isNullable)
            {
                typeName = typeName.Substring(0, typeName.Length - 1);
            }

            // String annotations can be null also
            isNullable = isNullable || Equals(STRING_TYPE_NAME, typeName);

            var column = new Column(columnName)
            {
                IsNullable = isNullable
            };

            mapping.Table.AddColumn(column);
            var value = new SimpleValue(mapping.Table)
            {
                TypeName = typeName
            };

            value.AddColumn(column);
            var property = new Property(value)
            {
                Name = columnName,
                PropertyAccessorName = accessorType.AssemblyQualifiedName
            };

            mapping.AddProperty(property);
        }
Example #7
0
        internal static IEnumerable <KeyValuePair <string, Expression <Func <FindDocument, Filter> > > > GetFacets(this ITypeSearch <FindDocument> search, SearchFilter filter, string locale)
        {
            ISearchConfiguration config = search.Client.GetConfiguration();
            IFieldConfiguration  field;
            int index;

            if (FindProviderExtensions.IsSimpleFacet(filter) && config.TryGetField(filter.field, locale, out field))
            {
                SimpleValue[] simpleValueArray = filter.Values.SimpleValue;
                for (index = 0; index < simpleValueArray.Length; ++index)
                {
                    SimpleValue simpleValue = simpleValueArray[index];
                    yield return(new KeyValuePair <string, Expression <Func <FindDocument, Filter> > >(FindProviderExtensions.EncodeFacetName(field.Name, simpleValue.key), UntypedFilterBuilder.GetMatchFilter(field, simpleValue.value)));
                }
                simpleValueArray = (SimpleValue[])null;
            }
            if (FindProviderExtensions.IsRangeFacet(filter) && config.TryGetField(filter.field, locale, out field))
            {
                RangeValue[] rangeValueArray = filter.Values.RangeValue;
                for (index = 0; index < rangeValueArray.Length; ++index)
                {
                    RangeValue rangeValue = rangeValueArray[index];
                    yield return(new KeyValuePair <string, Expression <Func <FindDocument, Filter> > >(FindProviderExtensions.EncodeFacetName(field.Name, rangeValue.key), UntypedFilterBuilder.GetRangeFilter(field, rangeValue.lowerbound, rangeValue.upperbound, rangeValue.lowerboundincluded, rangeValue.upperboundincluded)));
                }
                rangeValueArray = (RangeValue[])null;
            }
        }
Example #8
0
        public void should_set_null_on_reference_types(Type type)
        {
            var value = new SimpleValue(typeof(string).ToCachedType());

            new ValueNode(CreateContext(Mode.Deserialize), null, value, null, null).Value = null;
            value.Instance.ShouldBeNull();
        }
Example #9
0
        public void should_set_simple_types(Type type, object value)
        {
            var result = new SimpleValue(type.ToCachedType());

            new ValueNode(CreateContext(Mode.Deserialize), null, result, null, null).Value = value;
            result.Instance.ShouldEqual(value);
        }
Example #10
0
        public void should_convert_simple_types_to_string(Type type, object value)
        {
            var result = new SimpleValue(typeof(string).ToCachedType());

            new ValueNode(CreateContext(Mode.Deserialize), null, result, null, null).Value = value;
            result.Instance.ShouldEqual(value.ToString());
        }
Example #11
0
        public void should_convert_simple_numeric_types_to_decimal(Type type, object value)
        {
            var result = new SimpleValue(typeof(decimal).ToCachedType());

            new ValueNode(CreateContext(Mode.Deserialize), null, result, null, null).Value = value;
            result.Instance.ShouldEqual(Convert.ChangeType(value, typeof(decimal)));
        }
Example #12
0
        public void should_set_decimal_enum_type()
        {
            var result = new SimpleValue(typeof(UriFormat).ToCachedType());

            new ValueNode(CreateContext(Mode.Deserialize), null, result, null, null).Value = 3.0;
            result.Instance.ShouldEqual(UriFormat.SafeUnescaped);
        }
        public static void DataFormatBody <T>(this BrowserContext browserContext, DataFormat format, T model)
        {
            switch (format)
            {
            case DataFormat.Json:
                browserContext.JsonBody(model);
                break;

            case DataFormat.Proto:
                var    descriptor = ProtobufResponse.GetDescriptor(typeof(T));
                object value      = SimpleValue.FromValue(model);
                if (value == null)
                {
                    value = model;
                }

                var bytes = descriptor.Write(value);
                browserContext.Body(new MemoryStream(bytes), "application/x-protobuf");
                browserContext.Header("Content-Length", bytes.Length.ToString());
                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #14
0
        public ProtobufResponse(object model)
        {
            ContentType = ContentType_Protobuf;
            StatusCode  = HttpStatusCode.OK;
            Contents    = model == null ? NoBody : (stream =>
            {
                var descriptor = GetDescriptor(model.GetType());

                byte[] bytes;
                if (model is IEnumerable collection)
                {
                    bytes = descriptor.WriteLenDelimitedStream(collection);
                }
                else
                {
                    var simpleModel = SimpleValue.FromValue(model);
                    if (simpleModel != null)
                    {
                        bytes = descriptor.Write(simpleModel);
                    }
                    else
                    {
                        bytes = descriptor.Write(model);
                    }
                }

                stream.Write(bytes, 0, bytes.Length);
            });
        }
Example #15
0
        public void CheckArithmetic()
        {
            var a1 = _fixture.Create <sbyte>();
            var b1 = _fixture.Create <byte>();
            var c1 = _fixture.Create <short>();
            var d1 = _fixture.Create <ushort>();
            var e1 = _fixture.Create <int>();
            var f1 = _fixture.Create <uint>();
            var g1 = _fixture.Create <long>();
            var h1 = _fixture.Create <ulong>();
            var i1 = _fixture.Create <float>();
            var j1 = _fixture.Create <double>();
            var k1 = _fixture.Create <decimal>();

            SimpleValue a2 = a1;
            SimpleValue b2 = b1;
            SimpleValue c2 = c1;
            SimpleValue d2 = d1;
            SimpleValue e2 = e1;
            SimpleValue f2 = f1;
            SimpleValue g2 = g1;
            SimpleValue h2 = h1;
            SimpleValue i2 = i1;
            SimpleValue j2 = j1;
            SimpleValue k2 = k1;

            //Just some arbitrary computation
            var expectedResult = k1 - (decimal)(j1 * i1) + h1 / (ulong)g1 + f1 * e1 + d1 / c1 - b1 * a1;
            var actualResult   = k2 - (decimal)(j2 * i2) + h2 / (ulong)g2 + f2 * e2 + d2 / c2 - b2 * a2;

            Assert.AreEqual(expectedResult, (decimal)actualResult);
        }
Example #16
0
        public void BindId(HbmId idSchema, PersistentClass rootClass, Table table)
        {
            if (idSchema != null)
            {
                var id = new SimpleValue(table);
                new TypeBinder(id, Mappings).Bind(idSchema.Type);

                rootClass.Identifier = id;

                Func <HbmColumn> defaultColumn = () => new HbmColumn
                {
                    name   = idSchema.name ?? RootClass.DefaultIdentifierColumnName,
                    length = idSchema.length
                };

                new ColumnsBinder(id, Mappings).Bind(idSchema.Columns, false, defaultColumn);

                CreateIdentifierProperty(idSchema, rootClass, id);
                VerifiyIdTypeIsValid(id.Type, rootClass.EntityName);

                new IdGeneratorBinder(Mappings).BindGenerator(id, GetIdGenerator(idSchema));

                id.Table.SetIdentifierValue(id);

                BindUnsavedValue(idSchema, id);
            }
        }
        public async Task Should_honor_the_clear()
        {
            var settings = new TestCacheSettings(100, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(60));

            var cache = new GreenCache <SimpleValue>(settings);

            var index      = cache.AddIndex("id", x => x.Id);
            var valueIndex = cache.AddIndex("value", x => x.Value);

            for (int i = 0; i < 100; i++)
            {
                SimpleValue simpleValue = await index.Get($"key{i}", SimpleValueFactory.Healthy);
            }

            await Task.Delay(100);

            Assert.That(cache.Statistics.Count, Is.EqualTo(100));

            var result = await valueIndex.Get("The key is key27");

            Assert.That(result.Id, Is.EqualTo("key27"));

            cache.Clear();

            Assert.That(async() => await index.Get("key27"), Throws.TypeOf <KeyNotFoundException>());
            Assert.That(async() => await valueIndex.Get("The key is key27"), Throws.TypeOf <KeyNotFoundException>());
        }
Example #18
0
        /**
         * Create a {@link SimpleValue} object
         *
         * @param sValue
         *        The value to assign
         * @return Never <code>null</code>.
         */
        public static SimpleValue CreateSimpleValue(string value)
        {
            SimpleValue simpleValue = new SimpleValue();

            simpleValue.Value = value;
            return(simpleValue);
        }
Example #19
0
        public void should_return_object_if_it_implements_ilist()
        {
            var    list  = new List <string>();
            IValue value = new SimpleValue(list, typeof(List <string>).ToCachedType());

            ArrayAdapter.Create(value).ShouldBeSameAs(list);
        }
Example #20
0
        public async Task Should_fill_up_a_bunch_of_buckets()
        {
            var addedObserver   = new NodeAddedCountObserver(100);
            var removedObserver = new NodeRemovedCountObserver <SimpleValue>(40);

            var settings = new TestCacheSettings(100, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(60));

            var cache = new GreenCache <SimpleValue>(settings);

            var index = cache.AddIndex("id", x => x.Id);

            cache.Connect(addedObserver);
            cache.Connect(removedObserver);

            for (int i = 0; i < 100; i++)
            {
                SimpleValue simpleValue = await index.Get($"key{i}", SimpleValueFactory.Healthy);

                settings.CurrentTime += TimeSpan.FromSeconds(1);
            }

            await addedObserver.Completed;
            await removedObserver.Completed;

            Assert.That(cache.Statistics.Count, Is.EqualTo(60));

            var values = cache.GetAll().ToArray();

            Assert.That(values.Length, Is.EqualTo(60));
        }
Example #21
0
        public async Task Should_fill_up_the_buckets_over_time_and_remove_old_entries()
        {
            var settings = new TestCacheSettings(100, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(300));

            var cache = new GreenCache <SimpleValue>(settings);

            var index = cache.AddIndex("id", x => x.Id);

            var observer = new NodeAddedCountObserver(200);

            cache.Connect(observer);

            var removed = new NodeRemovedCountObserver <SimpleValue>(100);

            cache.Connect(removed);

            for (int i = 0; i < 200; i++)
            {
                SimpleValue simpleValue = await index.Get($"key{i}", SimpleValueFactory.Healthy);

                settings.CurrentTime += TimeSpan.FromSeconds(1);
            }

            await observer.Completed;
            await removed.Completed;

            Assert.That(cache.Statistics.Count, Is.EqualTo(100));
        }
Example #22
0
        private void BindColumns(HbmTimestamp timestampSchema, SimpleValue model, string propertyPath)
        {
            Table table = model.Table;

            if (timestampSchema.column != null)
            {
                Column col = new Column();
                col.Value = model;
                BindColumn(col, false);
                col.Name = mappings.NamingStrategy.ColumnName(timestampSchema.column);

                if (table != null)
                {
                    table.AddColumn(col);
                }

                model.AddColumn(col);
            }

            if (model.ColumnSpan == 0)
            {
                Column col = new Column();
                col.Value = model;
                BindColumn(col, false);
                col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath);
                model.Table.AddColumn(col);
                model.AddColumn(col);
            }
        }
Example #23
0
        private void BindVersion(HbmVersion versionSchema, PersistentClass rootClass, Table table, IDictionary <string, MetaAttribute> inheritedMetas)
        {
            if (versionSchema == null)
            {
                return;
            }

            string      propertyName = versionSchema.name;
            SimpleValue simpleValue  = new SimpleValue(table);

            BindVersionType(versionSchema.type, simpleValue);
            BindColumns(versionSchema, simpleValue, false, propertyName);
            if (!simpleValue.IsTypeSpecified)
            {
                simpleValue.TypeName = NHibernateUtil.Int32.Name;
            }

            var property = new Property(simpleValue);

            BindProperty(versionSchema, property, inheritedMetas);

            // for version properties marked as being generated, make sure they are "always"
            // generated; "insert" is invalid. This is dis-allowed by the schema, but just to make
            // sure...

            if (property.Generation == PropertyGeneration.Insert)
            {
                throw new MappingException("'generated' attribute cannot be 'insert' for versioning property");
            }

            simpleValue.NullValue = versionSchema.unsavedvalue;
            rootClass.Version     = property;
            rootClass.AddProperty(property);
        }
Example #24
0
        private Property CreateProperty(SimpleValue value, string propertyName, System.Type parentClass,
                                        HbmKeyProperty keyPropertySchema)
        {
            if (parentClass != null && value.IsSimpleValue)
            {
                value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName,
                                             keyPropertySchema.access ?? mappings.DefaultAccess);
            }

            // This is done here 'cos we might only know the type here (ugly!)
            var toOne = value as ToOne;

            if (toOne != null)
            {
                string propertyRef = toOne.ReferencedPropertyName;
                if (propertyRef != null)
                {
                    mappings.AddUniquePropertyReference(toOne.ReferencedEntityName, propertyRef);
                }
            }

            value.CreateForeignKey();
            var prop = new Property {
                Value = value
            };

            BindProperty(keyPropertySchema, prop);

            return(prop);
        }
Example #25
0
        private void BindComponent(System.Type reflectedClass, string path, HbmCompositeId idSchema)
        {
            if (idSchema.@class != null)
            {
                compositeId.ComponentClass = ClassForNameChecked(idSchema.@class, mappings, "component class not found: {0}");

                compositeId.IsEmbedded = false;
            }
            else if (reflectedClass != null)
            {
                compositeId.ComponentClass = reflectedClass;
                compositeId.IsEmbedded     = false;
            }
            else
            {
                // an "embedded" component (ids only)
                if (compositeId.Owner.HasPocoRepresentation)
                {
                    compositeId.ComponentClass = compositeId.Owner.MappedClass;
                    compositeId.IsEmbedded     = true;
                }
                else
                {
                    // if not - treat compositeid as a dynamic-component
                    compositeId.IsDynamic = true;
                }
            }

            foreach (object item in idSchema.Items ?? new object[0])
            {
                var keyManyToOneSchema = item as HbmKeyManyToOne;
                var keyPropertySchema  = item as HbmKeyProperty;

                if (keyManyToOneSchema != null)
                {
                    var manyToOne = new ManyToOne(compositeId.Table);

                    string propertyName = keyManyToOneSchema.name == null ? null : StringHelper.Qualify(path, keyManyToOneSchema.name);

                    BindManyToOne(keyManyToOneSchema, manyToOne, propertyName, false);

                    Property property = CreateProperty(manyToOne, keyManyToOneSchema.name, compositeId.ComponentClass,
                                                       keyManyToOneSchema);

                    compositeId.AddProperty(property);
                }
                else if (keyPropertySchema != null)
                {
                    var value = new SimpleValue(compositeId.Table);

                    string propertyName = keyPropertySchema.name == null ? null : StringHelper.Qualify(path, keyPropertySchema.name);

                    BindSimpleValue(keyPropertySchema, value, false, propertyName);

                    Property property = CreateProperty(value, keyPropertySchema.name, compositeId.ComponentClass, keyPropertySchema);

                    compositeId.AddProperty(property);
                }
            }
        }
Example #26
0
 protected void BindForeignKey(string foreignKey, SimpleValue value)
 {
     if (!string.IsNullOrEmpty(foreignKey))
     {
         value.ForeignKeyName = foreignKey;
     }
 }
Example #27
0
        public void BindGenerator(SimpleValue id, HbmGenerator generatorMapping)
        {
            if (generatorMapping != null)
            {
                if (generatorMapping.@class == null)
                {
                    throw new MappingException("no class given for generator");
                }

                // NH Differen behavior : specific feature NH-1817
                TypeDef typeDef = mappings.GetTypeDef(generatorMapping.@class);
                if (typeDef != null)
                {
                    id.IdentifierGeneratorStrategy = typeDef.TypeClass;
                    // parameters on the property mapping should override parameters in the typedef
                    var allParameters = new Dictionary <string, string>(typeDef.Parameters);
                    ArrayHelper.AddAll(allParameters, GetGeneratorProperties(generatorMapping, id.Table.Schema));

                    id.IdentifierGeneratorProperties = allParameters;
                }
                else
                {
                    id.IdentifierGeneratorStrategy   = generatorMapping.@class;
                    id.IdentifierGeneratorProperties = GetGeneratorProperties(generatorMapping, id.Table.Schema);
                }
            }
        }
        private void BindSimpleValue(HbmDiscriminator discriminatorSchema, SimpleValue discriminator)
        {
            if (discriminatorSchema.type != null)
            {
                discriminator.TypeName = discriminatorSchema.type;
            }

            if (discriminatorSchema.formula != null)
            {
                var f = new Formula {
                    FormulaString = discriminatorSchema.formula
                };
                discriminator.AddFormula(f);
            }
            else
            {
                new ColumnsBinder(discriminator, Mappings).Bind(discriminatorSchema.Columns, false,
                                                                () =>
                                                                new HbmColumn
                {
                    name =
                        mappings.NamingStrategy.PropertyToColumnName(
                            RootClass.DefaultDiscriminatorColumnName),
                    length           = discriminatorSchema.length,
                    notnull          = discriminatorSchema.notnull,
                    notnullSpecified = true
                });
            }
        }
Example #29
0
        private void BindCollectionIndex(IIndexedCollectionMapping listMapping, IndexedCollection model)
        {
            SimpleValue iv = null;

            if (listMapping.ListIndex != null)
            {
                iv = new SimpleValue(model.CollectionTable);
                new ValuePropertyBinder(iv, Mappings).BindSimpleValue(listMapping.ListIndex,
                                                                      IndexedCollection.DefaultIndexColumnName, model.IsOneToMany);
            }
            else if (listMapping.Index != null)
            {
                iv = new SimpleValue(model.CollectionTable);
                listMapping.Index.type = NHibernateUtil.Int32.Name;
                new ValuePropertyBinder(iv, Mappings).BindSimpleValue(listMapping.Index, IndexedCollection.DefaultIndexColumnName,
                                                                      model.IsOneToMany);
            }
            if (iv != null)
            {
                if (iv.ColumnSpan > 1)
                {
                    log.Error("This shouldn't happen, check BindIntegerValue");
                }
                model.Index = iv;
            }
        }
Example #30
0
        private void txtNatrueColorDir_TextChanged(object sender, EventArgs e)
        {
            string dir = txtNatrueColorDir.Text;

            ClearFileLst();
            if (!Directory.Exists(dir))
            {
                return;
            }

            var filter = "*.ldf";
            var files  = Directory.GetFiles(dir, filter);

            foreach (var file in files)
            {
                var         filename = Path.GetFileNameWithoutExtension(file);
                SimpleValue sv       = new SimpleValue {
                    ID = filename, Name = filename
                };
                lstFiles.Items.Add(sv);
            }
            if (lstFiles.Items.Count > 0)
            {
                lstFiles.SelectedIndex = 0;
            }
        }
		public void BinaryBlob_mapping_to_SqlCe_types()
		{
			SimpleValue sv = new SimpleValue();
			sv.TypeName = NHibernateUtil.BinaryBlob.Name;
			Column column = new Column();
			column.Value = sv;

			// no length, should produce maximum
			Assert.AreEqual("VARBINARY(8000)", column.GetSqlType(dialect, null));

			// maximum varbinary length is 8000
			column.Length = 8000;
			Assert.AreEqual("VARBINARY(8000)", column.GetSqlType(dialect,null));

			column.Length = 8001;
			Assert.AreEqual("IMAGE", column.GetSqlType(dialect, null));
		}
Example #32
0
        public SearchFilter GetSearchFilterForNode(NodeContent nodeContent)
        {
            var configFilter = new SearchFilter
            {
                field = BaseCatalogIndexBuilder.FieldConstants.Node,
                Descriptions = new Descriptions
                {
                    defaultLocale = _preferredCulture.Name
                },
                Values = new SearchFilterValues()
            };

            var desc = new Description
            {
                locale = "en",
                Value = _localizationService.GetString("/Facet/Category")
            };
            configFilter.Descriptions.Description = new[] { desc };  

            var nodes = _contentLoader.GetChildren<NodeContent>(nodeContent.ContentLink).ToList();
            var nodeValues = new SimpleValue[nodes.Count];
            var index = 0;
            foreach (var node in nodes)
            {
                var val = new SimpleValue
                {
                    key = node.Code,
                    value = node.Code,
                    Descriptions = new Descriptions
                    {
                        defaultLocale = _preferredCulture.Name
                    }
                };
                var desc2 = new Description
                {
                    locale = _preferredCulture.Name,
                    Value = node.DisplayName
                };
                val.Descriptions.Description = new[] { desc2 };

                nodeValues[index] = val;
                index++;
            }
            configFilter.Values.SimpleValue = nodeValues;
            return configFilter;
        }