예제 #1
0
        public IHttpActionResult Get(int id, int mappingid)
        {
            return(WebHandler(() =>
            {
                var request = new GetMappingRequest
                {
                    EntityId = id,
                    MappingId = mappingid
                };

                ContractResponse <MappingResponse> response;
                using (var scope = new TransactionScope(TransactionScopeOption.Required, ReadOptions()))
                {
                    response = this.service.RequestMapping(request);
                    scope.Complete();
                }

                if (response.IsValid)
                {
                    return new ResponseWithETag <MappingResponse>(this.Request, response.Contract, HttpStatusCode.OK,
                                                                  response.Version);
                }

                throw new MdmFaultException(new GetMappingRequestFaultHandler().Create(typeof(TContract).Name,
                                                                                       response.Error, request));
            }));
        }
예제 #2
0
        public async Task <IActionResult> IndexFromAttribute()
        {
            try
            {
                string newIndexName = $"{IndexName}_attribute";
                // delete the index if it exists. Useful for demo purposes so that
                // we can re-run this example.
                if (_elasticClient.Indices.Exists(newIndexName).Exists)
                {
                    _elasticClient.Indices.Delete(newIndexName);
                }

                var createIndexResponse = await _elasticClient.Indices.CreateAsync(newIndexName, c => c
                                                                                   .Map <EmployeeWithAttribute>(m => m.AutoMap()));

                if (createIndexResponse.IsValid)
                {
                    var mappingRequest = new GetMappingRequest();
                    var mapping        = await _elasticClient.Indices.GetMappingAsync(mappingRequest);

                    mapping.Indices.TryGetValue(newIndexName, out IndexMappings indexMappings);
                    return(Ok(JsonConvert.SerializeObject(indexMappings.Mappings.Properties.Keys)));
                }
                else
                {
                    return(BadRequest(createIndexResponse.ServerError.Error));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #3
0
        public GetMappingRequestTests()
        {
            var request  = new GetMappingRequest("my-index", "my-type");
            var response = this._client.GetMapping(request);

            this._status = response.ConnectionStatus;
        }
예제 #4
0
        /// <summary>
        /// Request all availabe algorithms from UCS server
        /// </summary>
        private void _requestAlgorithms()
        {
            var request = new GetMappingRequest()
            {
                ClientId      = _connect.AuthorizeHciResponse.ClientId,
                GetAlgorithms = true
            };
            var response = _connect.Executor.Submit <GetMappingResponse>(request);

            response.Wait();
            _responseAlghoritms = response.Value;
        }
예제 #5
0
        public async Task <IActionResult> IndexWithMappings()
        {
            try
            {
                // delete the index if it exists. Useful for demo purposes so that
                // we can re-run this example.
                if (_elasticClient.Indices.Exists(IndexName).Exists)
                {
                    _elasticClient.Indices.Delete(IndexName);
                }

                var createIndexResponse = await _elasticClient.Indices.CreateAsync(IndexName, c => c
                                                                                   .Map <Company>(m => m
                                                                                                  .Properties(ps => ps
                                                                                                              .Text(s => s
                                                                                                                    .Name(n => n.Name))
                                                                                                              .Object <Employee>(o => o
                                                                                                                                 .Name(n => n.Employees)
                                                                                                                                 .Properties(eps => eps
                                                                                                                                             .Text(s => s.Name(e => e.FirstName))
                                                                                                                                             .Text(s => s.Name(e => e.LastName))
                                                                                                                                             .Number(n => n.Name(e => e.Salary).Type(NumberType.Integer)))
                                                                                                                                 ))));

                if (createIndexResponse.IsValid)
                {
                    var mappingRequest = new GetMappingRequest();
                    var mapping        = await _elasticClient.Indices.GetMappingAsync(mappingRequest);

                    mapping.Indices.TryGetValue(IndexName, out IndexMappings indexMappings);
                    return(Ok(JsonConvert.SerializeObject(indexMappings.Mappings.Properties.Keys)));
                }
                else
                {
                    return(BadRequest(createIndexResponse.ServerError.Error));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #6
0
        /// <summary>
        /// Get a particular mapping
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ContractResponse <MappingResponse> RequestMapping(GetMappingRequest request)
        {
            // Get the entity
            var mapping = this.repository.FindOne <TMapping>(request.MappingId);

            if (mapping == null || request.EntityId != mapping.Entity.Id)
            {
                return(new ContractResponse <MappingResponse>
                {
                    Error = new ContractError
                    {
                        Type = ErrorType.NotFound
                    },
                    IsValid = false
                });
            }
            if (mapping.Entity.Id != request.EntityId)
            {
                return(new ContractResponse <MappingResponse>
                {
                    Error = new ContractError
                    {
                        Type = ErrorType.NotFound
                    },
                    IsValid = false
                });
            }

            var mr = new MappingResponse();

            mr.Mappings.Add(this.MappingEngine.Map <TMapping, MdmId>(mapping));
            var response = new ContractResponse <MappingResponse>
            {
                Contract = mr,
                Version  = mapping.Entity.Version,
                IsValid  = true
            };

            return(response);
        }
예제 #7
0
        public async Task <IActionResult> IndexAutoMapPOCO()
        {
            try
            {
                string newIndexName = $"{IndexName}_poco";
                // delete the index if it exists. Useful for demo purposes so that
                // we can re-run this example.

                if (_elasticClient.Indices.Exists(newIndexName).Exists)
                {
                    _elasticClient.Indices.Delete(newIndexName);
                }

                // create the index, adding the mapping for the Page type to the index
                // at the same time. Automap() will infer the mapping from the POCO
                var createIndexResponse = await _elasticClient.Indices.CreateAsync(newIndexName, c => c
                                                                                   .Map <Document>(m => m
                                                                                                   .AutoMap <Company>()
                                                                                                   .AutoMap(typeof(Employee))));

                if (createIndexResponse.IsValid)
                {
                    var mappingRequest = new GetMappingRequest();
                    var mapping        = await _elasticClient.Indices.GetMappingAsync(mappingRequest);

                    mapping.Indices.TryGetValue(newIndexName, out IndexMappings indexMappings);
                    return(Ok(JsonConvert.SerializeObject(indexMappings.Mappings.Properties.Keys)));
                }
                else
                {
                    return(BadRequest(createIndexResponse.ServerError.Error));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
		public GetMappingRequestTests()
		{
			var request = new GetMappingRequest("my-index", "my-type");
			var response = this._client.GetMapping(request);
			this._status = response.ConnectionStatus;
		}