Пример #1
0
        private void ExportPropertiesDictionaryItems(JsonTextWriter writer, JsonSerializer serializer, ExportImportProgressInfo progressInfo, Action <ExportImportProgressInfo> progressCallback)
        {
            progressInfo.Description = "The dictionary items are exporting…";
            progressCallback(progressInfo);

            var criteria = new PropertyDictionaryItemSearchCriteria {
                Take = 0, Skip = 0
            };
            var totalCount = _propertyDictionarySearchService.Search(criteria).TotalCount;

            writer.WritePropertyName("PropertyDictionaryItemsTotalCount");
            writer.WriteValue(totalCount);

            writer.WritePropertyName("PropertyDictionaryItems");
            writer.WriteStartArray();
            for (var i = 0; i < totalCount; i += BatchSize)
            {
                var searchResponse = _propertyDictionarySearchService.Search(new PropertyDictionaryItemSearchCriteria {
                    Take = BatchSize, Skip = i
                });
                foreach (var dictItem in searchResponse.Results)
                {
                    serializer.Serialize(writer, dictItem);
                }
                writer.Flush();
                progressInfo.Description = $"{ Math.Min(totalCount, i + BatchSize) } of { totalCount } dictionary items have been exported";
                progressCallback(progressInfo);
            }
            writer.WriteEndArray();
        }
        public async Task <PropertyDictionaryItemSearchResult> SearchAsync(PropertyDictionaryItemSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }

            using (var repository = _repositoryFactory())
            {
                //Optimize performance and CPU usage
                repository.DisableChangesTracking();

                var result = AbstractTypeFactory <PropertyDictionaryItemSearchResult> .TryCreateInstance();

                var sortInfos = BuildSortExpression(criteria);
                var query     = BuildQuery(repository, criteria);

                result.TotalCount = await query.CountAsync();

                if (criteria.Take > 0)
                {
                    var ids = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
                              .Select(x => x.Id)
                              .Skip(criteria.Skip).Take(criteria.Take)
                              .AsNoTracking()
                              .ToArrayAsync();

                    result.Results = (await _properyDictionaryItemService.GetByIdsAsync(ids)).OrderBy(x => Array.IndexOf(ids, x.Id)).ToList();
                }

                return(result);
            }
        }
        public IHttpActionResult SearchPropertyDictionaryItems(PropertyDictionaryItemSearchCriteria criteria)
        {
            var result = _propertyDictionarySearchService.Search(criteria);
            var retVal = new webModel.PropertyDictionaryItemSearchResult
            {
                Results    = result.Results,
                TotalCount = result.TotalCount
            };

            return(Ok(retVal));
        }
Пример #4
0
        public GenericSearchResult <PropertyDictionaryItem> Search(PropertyDictionaryItemSearchCriteria searchCriteria)
        {
            if (searchCriteria == null)
            {
                throw new ArgumentNullException(nameof(searchCriteria));
            }

            return(_cacheManager.Get($"PropertyDictionaryItemService.Search-{searchCriteria.GetCacheKey()}", CatalogConstants.DictionaryItemsCacheRegion, () =>
            {
                using (var repository = _repositoryFactory())
                {
                    //Optimize performance and CPU usage
                    repository.DisableChangesTracking();

                    var result = new GenericSearchResult <PropertyDictionaryItem>();

                    var query = repository.PropertyDictionaryItems;
                    if (!searchCriteria.CatalogIds.IsNullOrEmpty())
                    {
                        query = query.Where(x => searchCriteria.CatalogIds.Contains(x.Property.CatalogId));
                    }
                    if (!searchCriteria.PropertyIds.IsNullOrEmpty())
                    {
                        query = query.Where(x => searchCriteria.PropertyIds.Contains(x.PropertyId));
                    }
                    if (!string.IsNullOrEmpty(searchCriteria.SearchPhrase))
                    {
                        query = query.Where(x => x.Alias.Contains(searchCriteria.SearchPhrase));
                    }

                    var sortInfos = searchCriteria.SortInfos;
                    if (sortInfos.IsNullOrEmpty())
                    {
                        sortInfos = new[] {
                            new SortInfo {
                                SortColumn = "SortOrder", SortDirection = SortDirection.Ascending
                            },
                            new SortInfo {
                                SortColumn = "Alias", SortDirection = SortDirection.Ascending
                            }
                        };
                    }
                    //Force sorting order by Id to prevent issue with nondeterministic behavior for queries that contains pagination with data that have same values for sorting by columns
                    //https://github.com/VirtoCommerce/vc-platform/issues/1525
                    query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id);

                    result.TotalCount = query.Count();
                    var ids = query.Skip(searchCriteria.Skip).Take(searchCriteria.Take).Select(x => x.Id).ToArray();
                    result.Results = GetByIds(ids).AsQueryable().OrderBySortInfos(sortInfos).ToList();
                    return result;
                }
            }));
        }
        protected override ExportableSearchResult FetchData(PropertyDictionaryItemExportSearchCriteria searchCriteria)
        {
            var criteria = new PropertyDictionaryItemSearchCriteria {
                Take = searchCriteria.Take, Skip = searchCriteria.Skip, CatalogIds = searchCriteria.CatalogIds
            };
            var searchResponse = _propertyDictionarySearchService.Search(criteria);

            return(new ExportableSearchResult
            {
                TotalCount = searchResponse.TotalCount,
                Results = searchResponse.Results.Select(y => AbstractTypeFactory <ExportablePropertyDictionaryItem> .TryCreateInstance().FromModel(y)).Cast <IExportable>().ToList()
            });
        }
Пример #6
0
        public async Task <PropertyDictionaryItemSearchResult> SearchAsync(PropertyDictionaryItemSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }

            using (var repository = _repositoryFactory())
            {
                //Optimize performance and CPU usage
                repository.DisableChangesTracking();

                var result = AbstractTypeFactory <PropertyDictionaryItemSearchResult> .TryCreateInstance();

                var query = repository.PropertyDictionaryItems;
                if (!criteria.PropertyIds.IsNullOrEmpty())
                {
                    query = query.Where(x => criteria.PropertyIds.Contains(x.PropertyId));
                }
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    query = query.Where(x => x.Alias.Contains(criteria.Keyword));
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] {
                        new SortInfo {
                            SortColumn = "SortOrder", SortDirection = SortDirection.Ascending
                        },
                        new SortInfo {
                            SortColumn = "Alias", SortDirection = SortDirection.Ascending
                        }
                    };
                }

                query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id);

                result.TotalCount = await query.CountAsync();

                if (criteria.Take > 0)
                {
                    var ids = await query.Skip(criteria.Skip).Take(criteria.Take).Select(x => x.Id).ToArrayAsync();

                    result.Results = (await _properyDictionaryItemService.GetByIdsAsync(ids)).AsQueryable().OrderBySortInfos(sortInfos).ToList();
                }

                return(result);
            }
        }
Пример #7
0
        public GenericSearchResult <PropertyDictionaryItem> Search(PropertyDictionaryItemSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }

            return(_cacheManager.Get($"PropertyDictionaryItemService.Search-{criteria.GetCacheKey()}", CatalogConstants.DictionaryItemsCacheRegion, () =>
            {
                using (var repository = _repositoryFactory())
                {
                    //Optimize performance and CPU usage
                    repository.DisableChangesTracking();

                    var result = new GenericSearchResult <PropertyDictionaryItem>();

                    var query = repository.PropertyDictionaryItems;
                    if (!criteria.PropertyIds.IsNullOrEmpty())
                    {
                        query = query.Where(x => criteria.PropertyIds.Contains(x.PropertyId));
                    }
                    if (!string.IsNullOrEmpty(criteria.SearchPhrase))
                    {
                        query = query.Where(x => x.Alias.Contains(criteria.SearchPhrase));
                    }

                    var sortInfos = criteria.SortInfos;
                    if (sortInfos.IsNullOrEmpty())
                    {
                        sortInfos = new[] {
                            new SortInfo {
                                SortColumn = "SortOrder", SortDirection = SortDirection.Ascending
                            },
                            new SortInfo {
                                SortColumn = "Alias", SortDirection = SortDirection.Ascending
                            }
                        };
                    }

                    query = query.OrderBySortInfos(sortInfos);

                    result.TotalCount = query.Count();
                    var ids = query.Skip(criteria.Skip).Take(criteria.Take).Select(x => x.Id).ToArray();
                    result.Results = GetByIds(ids).AsQueryable().OrderBySortInfos(sortInfos).ToList();
                    return result;
                }
            }));
        }
        protected virtual IList <SortInfo> BuildSortExpression(PropertyDictionaryItemSearchCriteria criteria)
        {
            var sortInfos = criteria.SortInfos;

            if (sortInfos.IsNullOrEmpty())
            {
                sortInfos = new[]
                {
                    new SortInfo {
                        SortColumn = nameof(PropertyDictionaryItemEntity.SortOrder)
                    },
                    new SortInfo {
                        SortColumn = nameof(PropertyDictionaryItemEntity.Alias)
                    }
                };
            }
            return(sortInfos);
        }
Пример #9
0
        public async Task <ActionResult <PropertyDictionaryItemSearchResult> > SearchPropertyDictionaryItems([FromBody] PropertyDictionaryItemSearchCriteria criteria)
        {
            var authorizationResult = await _authorizationService.AuthorizeAsync(User, criteria, new CatalogAuthorizationRequirement(ModuleConstants.Security.Permissions.Read));

            if (!authorizationResult.Succeeded)
            {
                return(Unauthorized());
            }
            var result = await _propertyDictionarySearchService.SearchAsync(criteria);

            return(Ok(result));
        }
        protected virtual IQueryable <PropertyDictionaryItemEntity> BuildQuery(ICatalogRepository repository, PropertyDictionaryItemSearchCriteria criteria)
        {
            var query = repository.PropertyDictionaryItems;

            if (!criteria.CatalogIds.IsNullOrEmpty())
            {
                query = query.Where(x => criteria.CatalogIds.Contains(x.Property.CatalogId));
            }
            if (!criteria.PropertyIds.IsNullOrEmpty())
            {
                query = query.Where(x => criteria.PropertyIds.Contains(x.PropertyId));
            }
            if (!string.IsNullOrEmpty(criteria.Keyword))
            {
                query = query.Where(x => x.Alias.Contains(criteria.Keyword));
            }

            return(query);
        }
Пример #11
0
        public async Task <ActionResult <PropertyDictionaryItem[]> > SearchPropertyDictionaryItems([FromBody] PropertyDictionaryItemSearchCriteria criteria)
        {
            var result = await _propertyDictionarySearchService.SearchAsync(criteria);

            return(Ok(result));
        }
Пример #12
0
        public IHttpActionResult SearchPropertyDictionaryItems(PropertyDictionaryItemSearchCriteria criteria)
        {
            var result = _propertyDictionarySearchService.Search(criteria);

            return(Ok(result));
        }