예제 #1
0
        protected override ExportableSearchResult FetchData(PropertySearchCriteria searchCriteria)
        {
            var searchResult = _propertySearchService.SearchPropertiesAsync(searchCriteria).GetAwaiter().GetResult();

            return(new ExportableSearchResult
            {
                TotalCount = searchResult.TotalCount,
                Results = searchResult.Results.ToList <IExportable>(),
            });
        }
예제 #2
0
        public async Task <ActionResult <string[]> > GetPropertyValues(string storeId, string propertyName)
        {
            var result = Array.Empty <string>();
            var store  = await _storeService.GetByIdAsync(storeId, StoreResponseGroup.StoreInfo.ToString());

            if (store != null)
            {
                var catalogPropertiesSearchResult = await _propertySearchService.SearchPropertiesAsync(new PropertySearchCriteria { PropertyNames = new[] { propertyName }, CatalogId = store.Catalog, Take = 1 });

                var property = catalogPropertiesSearchResult.Results.FirstOrDefault(p => p.Name.EqualsInvariant(propertyName) && p.Dictionary);
                if (property != null)
                {
                    var searchResult = await _propDictItemsSearchService.SearchAsync(new PropertyDictionaryItemSearchCriteria { PropertyIds = new[] { property.Id }, Take = int.MaxValue });

                    result = searchResult.Results.Select(x => x.Alias).Distinct().ToArray();
                }
            }
            return(Ok(result));
        }
예제 #3
0
        public async Task <ActionResult <string[]> > GetPropertyValues(string storeId, string propertyName)
        {
            var result = Array.Empty <string>();
            var store  = await _storeService.GetByIdAsync(storeId);

            if (store == null)
            {
                return(NoContent());
            }

            //CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.ReadBrowseFilters, store);
            var catalogPropertiesSearchResult = await _propertySearchService.SearchPropertiesAsync(new PropertySearchCriteria { PropertyNames = new[] { propertyName }, CatalogId = store.Catalog, Take = 1 });

            var property = catalogPropertiesSearchResult.Results.FirstOrDefault(p => p.Name.EqualsInvariant(propertyName) && p.Dictionary);

            if (property != null)
            {
                var searchResult = await _propDictItemsSearchService.SearchAsync(new PropertyDictionaryItemSearchCriteria { PropertyIds = new[] { property.Id }, Take = int.MaxValue });

                result = searchResult.Results.Select(x => x.Alias).Distinct().ToArray();
            }
            return(Ok(result));
        }
예제 #4
0
        public virtual async Task <SearchPropertiesResponse> Handle(SearchPropertiesQuery request, CancellationToken cancellationToken)
        {
            var searchCriteria = new PropertySearchCriteriaBuilder(_searchPhraseParser, _mapper)
                                 .ParseFilters(request.Filter)
                                 .WithCatalogId(request.CatalogId)
                                 .WithPaging(request.Skip, request.Take)
                                 .Build();

            var result = await _propertySearchService.SearchPropertiesAsync(searchCriteria);

            if (request.Types != null)
            {
                result.Results = result.Results.Where(x => request.Types.Contains(x.Type)).ToList();
            }
            return(new SearchPropertiesResponse
            {
                Result = result
            });
        }
예제 #5
0
        public async Task DoExportAsync(Stream outStream, ExportImportOptions options, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var progressInfo = new ExportImportProgressInfo {
                Description = "loading data..."
            };

            progressCallback(progressInfo);

            using (var sw = new StreamWriter(outStream))
                using (var writer = new JsonTextWriter(sw))
                {
                    await writer.WriteStartObjectAsync();

                    #region Export catalogs
                    progressInfo.Description = "Catalogs exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Catalogs");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = (await _catalogService.GetCatalogsListAsync()).ToArray();
                        return(new GenericSearchResult <Catalog> {
                            Results = searchResult, TotalCount = searchResult.Length
                        });
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } catalogs have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion

                    #region Export categories
                    progressInfo.Description = "Categories exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Categories");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _categorySearchService.SearchCategoriesAsync(new CategorySearchCriteria {
                            Skip = skip, Take = take
                        });
                        var categories = searchResult.Results;
                        if (options.HandleBinaryData)
                        {
                            LoadImages(categories.OfType <IHasImages>().ToArray(), progressInfo);
                        }

                        return(new GenericSearchResult <Category> {
                            Results = categories, TotalCount = searchResult.TotalCount
                        });
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } Categories have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion

                    #region Export properties
                    progressInfo.Description = "Properties exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Properties");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _propertySearchService.SearchPropertiesAsync(new PropertySearchCriteria {
                            Skip = skip, Take = take
                        });
                        return(new GenericSearchResult <Property> {
                            Results = searchResult.Results, TotalCount = searchResult.TotalCount
                        });
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } properties have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion

                    #region Export propertyDictionaryItems
                    progressInfo.Description = "PropertyDictionaryItems exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("PropertyDictionaryItems");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _propertyDictionarySearchService.SearchAsync(new PropertyDictionaryItemSearchCriteria {
                            Skip = skip, Take = take
                        });
                        return(new GenericSearchResult <PropertyDictionaryItem> {
                            Results = searchResult.Results, TotalCount = searchResult.TotalCount
                        });
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } property dictionary items have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion

                    #region Export products
                    progressInfo.Description = "Products exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Products");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _productSearchService.SearchProductsAsync(new ProductSearchCriteria {
                            Skip = skip, Take = take
                        });
                        if (options.HandleBinaryData)
                        {
                            LoadImages(searchResult.Results.OfType <IHasImages>().ToArray(), progressInfo);
                        }
                        return(new GenericSearchResult <CatalogProduct> {
                            Results = searchResult.Results, TotalCount = searchResult.TotalCount
                        });
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } Products have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion

                    await writer.WriteEndObjectAsync();

                    await writer.FlushAsync();
                }
        }
예제 #6
0
        public async Task DoExportAsync(Stream outStream, ExportImportOptions options, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var progressInfo = new ExportImportProgressInfo {
                Description = "loading data..."
            };

            progressCallback(progressInfo);

            using (var sw = new StreamWriter(outStream))
                using (var writer = new JsonTextWriter(sw))
                {
                    await writer.WriteStartObjectAsync();

                    #region Export properties

                    progressInfo.Description = "Properties exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Properties");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _propertySearchService.SearchPropertiesAsync(new PropertySearchCriteria {
                            Skip = skip, Take = take
                        });
                        foreach (var item in searchResult.Results)
                        {
                            ResetRedundantReferences(item);
                        }
                        return((GenericSearchResult <Property>)searchResult);
                    }
                                                                   , (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } properties have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion Export properties

                    #region Export propertyDictionaryItems

                    progressInfo.Description = "PropertyDictionaryItems exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("PropertyDictionaryItems");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                                                                   (GenericSearchResult <PropertyDictionaryItem>) await _propertyDictionarySearchService.SearchAsync(new PropertyDictionaryItemSearchCriteria {
                        Skip = skip, Take = take
                    })
                                                                   , (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } property dictionary items have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion Export propertyDictionaryItems

                    #region Export catalogs

                    progressInfo.Description = "Catalogs exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Catalogs");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                                                                   (GenericSearchResult <Catalog>) await _catalogSearchService.SearchCatalogsAsync(new CatalogSearchCriteria {
                        Skip = skip, Take = take
                    })
                                                                   , (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } catalogs have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion Export catalogs

                    #region Export categories

                    progressInfo.Description = "Categories exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Categories");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _categorySearchService.SearchCategoriesAsync(new CategorySearchCriteria {
                            Skip = skip, Take = take
                        });
                        LoadImages(searchResult.Results.OfType <IHasImages>().ToArray(), progressInfo, options.HandleBinaryData);
                        foreach (var item in searchResult.Results)
                        {
                            ResetRedundantReferences(item);
                        }

                        return((GenericSearchResult <Category>)searchResult);
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } Categories have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion Export categories

                    #region Export products

                    progressInfo.Description = "Products exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("Products");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _productSearchService.SearchProductsAsync(new ProductSearchCriteria {
                            Skip = skip, Take = take, ResponseGroup = ItemResponseGroup.Full.ToString()
                        });
                        LoadImages(searchResult.Results.OfType <IHasImages>().ToArray(), progressInfo, options.HandleBinaryData);
                        foreach (var item in searchResult.Results)
                        {
                            ResetRedundantReferences(item);
                        }
                        return((GenericSearchResult <CatalogProduct>)searchResult);
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } Products have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    #endregion Export products

                    await writer.WriteEndObjectAsync();

                    await writer.FlushAsync();
                }
        }