Beispiel #1
0
        public async Task <ActionResult <DynamicContentListEntrySearchResult> > DynamicContentPlaceListEntriesSearch([FromBody] coreModel.DynamicContentPlaceSearchCriteria criteria)
        {
            var result = AbstractTypeFactory <DynamicContentListEntrySearchResult> .TryCreateInstance();

            var folderSearchCriteria = new coreModel.DynamicContentFolderSearchCriteria
            {
                FolderId = criteria.FolderId,
                Keyword  = criteria.Keyword,
                Take     = criteria.Take,
                Skip     = criteria.Skip,
                Sort     = criteria.Sort
            };

            var foldersSearchResult = await _folderSearchService.SearchFoldersAsync(folderSearchCriteria);

            var folderSkip = Math.Min(foldersSearchResult.TotalCount, criteria.Skip);
            var folderTake = Math.Min(criteria.Take, Math.Max(0, foldersSearchResult.TotalCount - criteria.Skip));

            result.TotalCount += foldersSearchResult.TotalCount;
            result.Results.AddRange(foldersSearchResult.Results.Skip(folderSkip).Take(folderTake));

            criteria.Skip -= folderSkip;
            criteria.Take -= folderTake;

            var placesSearchResult = await _contentPlacesSearchService.SearchContentPlacesAsync(criteria);

            result.TotalCount += placesSearchResult.TotalCount;
            result.Results.AddRange(placesSearchResult.Results);

            return(Ok(result));
        }
        public virtual 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();

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

                    await writer.WritePropertyNameAsync("Promotions");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                                                                   (GenericSearchResult <Promotion>) await LoadPromotionsPageAsync(skip, take, options, progressCallback)
                                                                   , (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } promotions have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    progressInfo.Description = "Dynamic content folders exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("DynamicContentFolders");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult        = AbstractTypeFactory <DynamicContentFolderSearchResult> .TryCreateInstance();
                        var result              = await LoadFoldersRecursiveAsync(null);
                        searchResult.Results    = result;
                        searchResult.TotalCount = result.Count;
                        return((GenericSearchResult <DynamicContentFolder>)searchResult);
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } dynamic content folders have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    progressInfo.Description = "Dynamic content items exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("DynamicContentItems");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                                                                   (GenericSearchResult <DynamicContentItem>) await _contentItemsSearchService.SearchContentItemsAsync(new DynamicContentItemSearchCriteria {
                        Skip = skip, Take = take
                    })
                                                                   , (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } dynamic content items have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    progressInfo.Description = "Dynamic content places exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("DynamicContentPlaces");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                                                                   (GenericSearchResult <DynamicContentPlace>) await _contentPlacesSearchService.SearchContentPlacesAsync(new DynamicContentPlaceSearchCriteria {
                        Skip = skip, Take = take
                    })
                                                                   , (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } dynamic content places have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    progressInfo.Description = "Dynamic content publications exporting...";
                    progressCallback(progressInfo);

                    await writer.WritePropertyNameAsync("DynamicContentPublications");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                    {
                        var searchResult = await _contentPublicationsSearchService.SearchContentPublicationsAsync(new DynamicContentPublicationSearchCriteria {
                            Skip = skip, Take = take
                        });
                        return((GenericSearchResult <DynamicContentPublication>)searchResult);
                    }, (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } dynamic content publications have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

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

                    await writer.WritePropertyNameAsync("Coupons");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                                                                   (GenericSearchResult <Coupon>) await _couponSearchService.SearchCouponsAsync(new CouponSearchCriteria {
                        Skip = skip, Take = take
                    }), (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } coupons have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

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

                    await writer.WritePropertyNameAsync("Usages");

                    await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) =>
                                                                   (GenericSearchResult <PromotionUsage>) await _promotionUsageSearchService.SearchUsagesAsync(new PromotionUsageSearchCriteria {
                        Skip = skip, Take = take
                    })
                                                                   , (processedCount, totalCount) =>
                    {
                        progressInfo.Description = $"{ processedCount } of { totalCount } usages have been exported";
                        progressCallback(progressInfo);
                    }, cancellationToken);

                    await writer.WriteEndObjectAsync();

                    await writer.FlushAsync();
                }
        }