private async Task <SoapGetProductsResponse> GetProductsAsync(int limit) { try { const int maxCheckCount = 2; const int delayBeforeCheck = 1800000; var res = new List <CatalogDataProductInterface>(); var privateClient = this.CreateMagentoCatalogProductRepositoryServiceClient(this.BaseMagentoUrl); catalogProductRepositoryV1GetListResponse1 catalogProductRepositoryV1GetListResponse = null; var currentPage = 0; do { await ActionPolicies.GetAsync.Do(async() => { var statusChecker = new StatusChecker(maxCheckCount); TimerCallback tcb = statusChecker.CheckStatus; if (privateClient.State != CommunicationState.Opened && privateClient.State != CommunicationState.Created && privateClient.State != CommunicationState.Opening) { privateClient = this.CreateMagentoCatalogProductRepositoryServiceClient(this.BaseMagentoUrl); } using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck)) { //var frameworkSearchFilterGroup1 = new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { conditionType = "gt", field = "created_at", value = "2000-01-01 01:01:01" } } }; //var frameworkSearchFilterGroup2 = new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { conditionType = "lt", field = "created_at", value = "2100-01-01 01:01:01" } } }; //var frameworkSearchFilterGroups = new[] { frameworkSearchFilterGroup1, frameworkSearchFilterGroup2 }; var frameworkSearchCriteriaInterface = new FrameworkSearchCriteriaInterface() { currentPage = currentPage, currentPageSpecified = true, pageSize = 100, pageSizeSpecified = true, //filterGroups = frameworkSearchFilterGroups }; var catalogProductRepositoryV1GetListRequest = new CatalogProductRepositoryV1GetListRequest() { searchCriteria = frameworkSearchCriteriaInterface }; catalogProductRepositoryV1GetListResponse = await privateClient.catalogProductRepositoryV1GetListAsync(catalogProductRepositoryV1GetListRequest).ConfigureAwait(false); var catalogDataProductInterfaces = catalogProductRepositoryV1GetListResponse == null ? new List <CatalogDataProductInterface>() : catalogProductRepositoryV1GetListResponse.catalogProductRepositoryV1GetListResponse.result.items.ToList(); res.AddRange(catalogDataProductInterfaces); currentPage++; } }).ConfigureAwait(false); } while(catalogProductRepositoryV1GetListResponse != null && res.Count < limit && res.Count < catalogProductRepositoryV1GetListResponse.catalogProductRepositoryV1GetListResponse.result.totalCount); return(new SoapGetProductsResponse(res.TakeWhile((x, i) => i < limit).ToList())); } catch (Exception exc) { throw new MagentoSoapException(string.Format("An error occured during GetProductsAsync()"), exc); } }
private async Task <CatalogDataProductSearchResultsInterface> GetProductsPageAsync(int currentPage, int pageSize, DateTime?updatedFrom, IReadOnlyCollection <string> skus, Mark mark = null) { var parameters = Tuple.Create(currentPage, pageSize, updatedFrom); var cachedR = this.getProductsPageCache.Get(parameters); if (cachedR != null) { return(cachedR); } var frameworkSearchCriteriaInterface = new FrameworkSearchCriteriaInterface() { currentPage = currentPage, currentPageSpecified = true, pageSize = pageSize, pageSizeSpecified = true, //filterGroups = frameworkSearchFilterGroups }; if (updatedFrom.HasValue) { AddFilter(frameworkSearchCriteriaInterface, updatedFrom.Value.ToSoapParameterString(), "updated_at", "gt"); } if (skus != null && skus.Any()) { AddFilter(frameworkSearchCriteriaInterface, string.Join(",", skus), "sku", "in"); } // filtering by typeId doesn't works for magento2.0.2 //if( productType != null ) //{ // if( frameworkSearchCriteriaInterface.filterGroups == null ) // frameworkSearchCriteriaInterface.filterGroups = new FrameworkSearchFilterGroup[] { }; // var temp = frameworkSearchCriteriaInterface.filterGroups.ToList(); // temp.Add( new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { conditionType = "like", field = "type", value = productType } } } ); // frameworkSearchCriteriaInterface.filterGroups = temp.ToArray(); //} var catalogProductRepositoryV1GetListRequest = new CatalogProductRepositoryV1GetListRequest() { searchCriteria = frameworkSearchCriteriaInterface }; var result = await this.GetWithAsync( res => res?.catalogProductRepositoryV1GetListResponse.result, //res => new SoapGetProductsResponse(res == null? new List<CatalogDataProductSearchResultsInterface>(): new List<CatalogDataProductSearchResultsInterface>() { res.catalogProductRepositoryV1GetListResponse }), //res => new SoapGetProductsResponse( res.catalogProductRepositoryV1GetListResponse.result ), async ( client, session ) => await client.catalogProductRepositoryV1GetListAsync( catalogProductRepositoryV1GetListRequest ).ConfigureAwait(false), 1800000, this._clientFactory.CreateMagentoCatalogProductRepositoryServiceClient, this._clientFactory.RefreshMagentoCatalogProductRepositoryServiceClient, mark : mark).ConfigureAwait(false); this.getProductsPageCache.Add(result, parameters, TimeSpan.FromSeconds(300)); return(result); }
private async Task <SoapGetProductsResponse> GetProductsOldAsync(int limit, string productType, bool productTypeShouldBeExcluded, DateTime?updatedFrom) { try { const int maxCheckCount = 2; const int delayBeforeCheck = 1800000; var res = new List <CatalogDataProductInterface>(); var privateClient = this._clientFactory.CreateMagentoCatalogProductRepositoryServiceClient(); catalogProductRepositoryV1GetListResponse1 catalogProductRepositoryV1GetListResponse = null; var currentPage = 0; do { await ActionPolicies.GetAsync.Do(async() => { var statusChecker = new StatusChecker(maxCheckCount); TimerCallback tcb = statusChecker.CheckStatus; privateClient = this._clientFactory.RefreshMagentoCatalogProductRepositoryServiceClient(privateClient); using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck)) { //var frameworkSearchFilterGroup1 = new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { conditionType = "gt", field = "created_at", value = "2000-01-01 01:01:01" } } }; //var frameworkSearchFilterGroup2 = new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { conditionType = "lt", field = "created_at", value = "2100-01-01 01:01:01" } } }; //var frameworkSearchFilterGroups = new[] { frameworkSearchFilterGroup1, frameworkSearchFilterGroup2 }; var frameworkSearchFilterGroups = new List <FrameworkSearchFilterGroup>(); var frameworkSearchCriteriaInterface = new FrameworkSearchCriteriaInterface() { currentPage = currentPage, currentPageSpecified = true, pageSize = 100, pageSizeSpecified = true, //filterGroups = frameworkSearchFilterGroups }; if (updatedFrom.HasValue) { var filter = new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { conditionType = "gt", field = "updated_at", value = updatedFrom.Value.ToSoapParameterString() } } }; frameworkSearchFilterGroups.Add(filter); } // filtering by typeId doesn't works for magento2.0.2 //if( productType != null ) //{ // if( frameworkSearchCriteriaInterface.filterGroups == null ) // frameworkSearchCriteriaInterface.filterGroups = new FrameworkSearchFilterGroup[] { }; // var temp = frameworkSearchCriteriaInterface.filterGroups.ToList(); // temp.Add( new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { conditionType = "like", field = "type", value = productType } } } ); // frameworkSearchCriteriaInterface.filterGroups = temp.ToArray(); //} if (frameworkSearchFilterGroups.Any()) { frameworkSearchCriteriaInterface.filterGroups = frameworkSearchFilterGroups.ToArray(); } var catalogProductRepositoryV1GetListRequest = new CatalogProductRepositoryV1GetListRequest() { searchCriteria = frameworkSearchCriteriaInterface }; catalogProductRepositoryV1GetListResponse = await privateClient.catalogProductRepositoryV1GetListAsync(catalogProductRepositoryV1GetListRequest).ConfigureAwait(false); var catalogDataProductInterfaces = catalogProductRepositoryV1GetListResponse == null ? new List <CatalogDataProductInterface>() : catalogProductRepositoryV1GetListResponse.catalogProductRepositoryV1GetListResponse.result.items.ToList(); res.AddRange(catalogDataProductInterfaces); currentPage++; } }).ConfigureAwait(false); } while(catalogProductRepositoryV1GetListResponse != null && res.Count < limit && res.Count < catalogProductRepositoryV1GetListResponse.catalogProductRepositoryV1GetListResponse.result.totalCount); if (!string.IsNullOrWhiteSpace(productType)) { res = productTypeShouldBeExcluded ? res.Where(x => !string.Equals(x.typeId, productType, StringComparison.InvariantCultureIgnoreCase)).ToList() : res.Where(x => string.Equals(x.typeId, productType, StringComparison.InvariantCultureIgnoreCase)).ToList(); } return(new SoapGetProductsResponse(res.TakeWhile((x, i) => i < limit).ToList())); } catch (Exception exc) { throw new MagentoSoapException(string.Format("An error occured during GetProductsAsync()"), exc); } }