public static void SetRouteParameters <TParameters, T>(
            IIndexTypePath <TParameters> path,
            IConnectionSettingsValues settings,
            ElasticsearchPathInfo <TParameters> pathInfo)
            where TParameters : IRequestParameters, new()
            where T : class
        {
            var inferrer = new ElasticInferrer(settings);

            if (path.Index == null)
            {
                path.Index = inferrer.IndexName <T>();
            }

            if (path.Type == null)
            {
                path.Type = inferrer.TypeName <T>();
            }

            var index = inferrer.IndexName(path.Index);
            var type  = inferrer.TypeName(path.Type);

            pathInfo.Index = index;
            pathInfo.Type  = type;
        }
        public static void SetRouteParameters <TParameters, T>(
            IIndicesTypePath <TParameters> path,
            IConnectionSettingsValues settings,
            ElasticsearchPathInfo <TParameters> pathInfo)
            where TParameters : IRequestParameters, new()
            where T : class
        {
            var inferrer = new ElasticInferrer(settings);

            if (path.Type == null)
            {
                path.Type = inferrer.TypeName <T>();
            }

            var index = !path.Indices.HasAny()
                                ? inferrer.IndexName <T>()
                                : string.Join(",", path.Indices.Select(inferrer.IndexName));

            if (path.AllIndices.GetValueOrDefault(false))
            {
                index = "_all";
            }

            var type = inferrer.TypeName(path.Type);

            pathInfo.Index = index;
            pathInfo.Type  = type;
        }
Пример #3
0
        public void DefaultTypeNamesTakePrecedenceOverCustomTypeNameInferrer()
        {
            var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex")
                                 .MapDefaultTypeNames(p => p
                                                      .Add(typeof(Developer), "codemonkey")
                                                      )
                                 .SetDefaultTypeNameInferrer(t => t.Name.ToUpperInvariant())
            ;

            var            inferrer = new ElasticInferrer(clientSettings);
            TypeNameMarker marker   = typeof(Developer);

            inferrer.TypeName(marker).Should().Be("codemonkey");

            //Should use the custom type name inferrer that upper cases
            marker = typeof(NoopObject);
            inferrer.TypeName(marker).Should().Be("NOOPOBJECT");
        }
Пример #4
0
        public static void SetRouteParameters <TParameters, T>(
            IQueryPath <TParameters> path,
            IConnectionSettingsValues settings,
            ElasticsearchPathInfo <TParameters> pathInfo)
            where TParameters : IRequestParameters, new()
            where T : class
        {
            //start out with defaults
            var inferrer = new ElasticInferrer(settings);


            var index = inferrer.IndexName <T>();
            var type  = inferrer.TypeName <T>();

            pathInfo.Index = index;
            pathInfo.Type  = type;

            if (path.Types.HasAny())
            {
                pathInfo.Type = inferrer.TypeNames(path.Types);
            }
            else if (path.AllTypes.GetValueOrDefault(false))
            {
                pathInfo.Type = null;
            }
            else
            {
                pathInfo.Type = inferrer.TypeName <T>();
            }

            if (path.Indices.HasAny())
            {
                pathInfo.Index = inferrer.IndexNames(path.Indices);
            }
            else if (path.AllIndices.GetValueOrDefault(false) && !pathInfo.Type.IsNullOrEmpty())
            {
                pathInfo.Index = "_all";
            }
            else
            {
                pathInfo.Index = path.AllIndices.GetValueOrDefault(false) ? null : inferrer.IndexName <T>();
            }
        }
Пример #5
0
        public void AttributeTypeNamesTakePrecedenceOverDefaultTypeNameInferrer()
        {
            var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex")
                                 .SetDefaultTypeNameInferrer(t => t.Name.ToUpperInvariant())
            ;

            var            inferrer = new ElasticInferrer(clientSettings);
            TypeNameMarker marker   = typeof(MyCustomAtrributeName);

            inferrer.TypeName(marker).Should().Be("custotypo");
        }
Пример #6
0
        public void MapTypeIndicesTakesPrecedenceOverAttributeName()
        {
            var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex")
                                 .MapDefaultTypeNames(dt => dt
                                                      .Add(typeof(MyCustomAtrributeName), "micutype")
                                                      )
                                 .SetDefaultTypeNameInferrer(t => t.Name.ToUpperInvariant())
            ;

            var            inferrer = new ElasticInferrer(clientSettings);
            TypeNameMarker marker   = typeof(MyCustomAtrributeName);

            inferrer.TypeName(marker).Should().Be("micutype");
        }
Пример #7
0
        public PutTemplateDescriptor AddMapping <T>(Func <PutMappingDescriptor <T>, PutMappingDescriptor <T> > mappingSelector)
            where T : class
        {
            mappingSelector.ThrowIfNull("mappingSelector");
            var putMappingDescriptor = mappingSelector(new PutMappingDescriptor <T>(this._connectionSettings));

            putMappingDescriptor.ThrowIfNull("rootObjectMappingDescriptor");

            var inferrer = new ElasticInferrer(this._connectionSettings);
            IPutMappingRequest request = putMappingDescriptor;
            var typeName = inferrer.TypeName(request.Type ?? typeof(T));

            if (typeName == null)
            {
                return(this);
            }
            Self.TemplateMapping.Mappings[typeName] = request.Mapping;
            return(this);
        }
        public static void SetRouteParameters <TParameters>(
            IIndexTypePath <TParameters> path,
            IConnectionSettingsValues settings,
            ElasticsearchPathInfo <TParameters> pathInfo)
            where TParameters : IRequestParameters, new()
        {
            var inferrer = new ElasticInferrer(settings);

            if (path.Index == null)
            {
                throw new DslException("Index() not specified");
            }

            if (path.Type == null)
            {
                throw new DslException("Type() not specified");
            }

            var index = inferrer.IndexName(path.Index);
            var type  = inferrer.TypeName(path.Type);

            pathInfo.Index = index;
            pathInfo.Type  = type;
        }
Пример #9
0
        public void ResolveToSepcifiedTypeNames()
        {
            var clientSettings = new ConnectionSettings(Test.Default.Uri, "mydefaultindex")
                                 .MapDefaultTypeNames(p => p
                                                      .Add(typeof(Car), "automobile")
                                                      .Add(typeof(Person), "human")
                                                      .Add(typeof(Organization), "organisation")
                                                      .Add(typeof(Developer), "codemonkey")
                                                      .Add(typeof(MyGeneric <Developer>), "codemonkey-wrapped-in-bacon")
                                                      .Add(typeof(MyGeneric <Organization>), "org-wrapped-in-bacon")
                                                      );
            var inferrer = new ElasticInferrer(clientSettings);

            TypeNameMarker marker = typeof(Car);

            inferrer.TypeName(marker).Should().Be("automobile");

            marker = typeof(Person);
            inferrer.TypeName(marker).Should().Be("human");

            marker = typeof(Organization);
            inferrer.TypeName(marker).Should().Be("organisation");

            marker = typeof(Developer);
            inferrer.TypeName(marker).Should().Be("codemonkey");

            marker = typeof(MyGeneric <Developer>);
            inferrer.TypeName(marker).Should().Be("codemonkey-wrapped-in-bacon");

            marker = typeof(MyGeneric <Organization>);
            inferrer.TypeName(marker).Should().Be("org-wrapped-in-bacon");

            //Should fall back to the default lowercase since
            //it doesn't have an explicit default
            marker = typeof(NoopObject);
            inferrer.TypeName(marker).Should().Be("noopobject");
        }