public async virtual Task <DynamicProperty> GetByNameAsync(string objectType, string propertyName) { if (objectType == null) { throw new ArgumentNullException(nameof(objectType)); } if (propertyName == null) { throw new ArgumentNullException(nameof(propertyName)); } var cacheKey = CacheKey.With(GetType(), nameof(GetByNameAsync)); var dict = await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(DynamicPropertiesCacheRegion.CreateChangeToken()); var result = new List <DynamicProperty>(); var criteria = new DynamicPropertySearchCriteria { Skip = 0, Take = _pageSize }; var searchResult = await _searchService.SearchDynamicPropertiesAsync(criteria); result.AddRange(searchResult.Results); var totalCount = searchResult.TotalCount; for (var skip = _pageSize; skip < totalCount; skip += _pageSize) { criteria.Skip = skip; searchResult = await _searchService.SearchDynamicPropertiesAsync(criteria); result.AddRange(searchResult.Results); } return(result.Distinct().ToDictionary(x => $"{x.ObjectType}__{x.Name}", StringComparer.InvariantCultureIgnoreCase).WithDefaultValue(null)); }); return(dict[$"{objectType}__{propertyName}"]); }
public virtual async Task <GenericSearchResult <DynamicProperty> > SearchDynamicPropertiesAsync(DynamicPropertySearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), "SearchDynamicPropertiesAsync", criteria.GetHashCode().ToString()); return(await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { var result = new GenericSearchResult <DynamicProperty>(); using (var repository = _repositoryFactory()) { //Optimize performance and CPU usage repository.DisableChangesTracking(); var query = repository.DynamicProperties; if (!string.IsNullOrEmpty(criteria.ObjectType)) { query = query.Where(x => x.ObjectType == criteria.ObjectType); } if (!string.IsNullOrEmpty(criteria.Keyword)) { query = query.Where(x => x.Name.Contains(criteria.Keyword)); } var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "Name" } }; } query = query.OrderBySortInfos(sortInfos); result.TotalCount = await query.CountAsync(); var ids = await query.Skip(criteria.Skip) .Take(criteria.Take) .Select(x => x.Id) .ToListAsync(); var properties = await _dynamicPropertyService.GetDynamicPropertiesAsync(ids.ToArray()); result.Results = properties.OrderBy(x => ids.IndexOf(x.Id)) .ToList(); } return result; })); }
public DynamicPropertySearchCriteriaBuilder() { _searchCriteria = AbstractTypeFactory <DynamicPropertySearchCriteria> .TryCreateInstance(); }
public async Task <IActionResult> Search([FromBody] DynamicPropertySearchCriteria criteria) { var result = await _dynamicPropertySearchService.SearchDynamicPropertiesAsync(criteria); return(Ok(result.Results)); }