public async Task <IEnumerable <string> > GetFilteredSkusAsync(ItemsFilter filter, Mark mark = null) { if (mark.IsBlank()) { mark = Mark.CreateNew(); } try { ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson())); filter.Criteria.PageSize = 100; filter.Criteria.PageNumber = 0; var skus = new List <string>(); while (true) { filter.Criteria.PageNumber += 1; var itemResponse = await AP.CreateQueryAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(async() => { ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : filter.ToJson())); var getFilteredSkuListResponse = await this._client.GetFilteredSkuListAsync (this._credentials, this.AccountId, filter.Criteria, filter.SortField, filter.SortDirection).ConfigureAwait(false); ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : getFilteredSkuListResponse.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : filter.ToJson())); return(getFilteredSkuListResponse); }).ConfigureAwait(false); ChannelAdvisorLogger.LogTrace(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndReturnsForTrace) ? null : itemResponse.ToJson(), additionalInfo: this.AdditionalLogInfo())); if (!this.IsRequestSuccessful(itemResponse.GetFilteredSkuListResult)) { continue; } var pageSkus = itemResponse.GetFilteredSkuListResult.ResultData; if (pageSkus == null) { ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: skus.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson())); return(skus); } skus.AddRange(pageSkus); if (pageSkus.Length == 0 || pageSkus.Length < filter.Criteria.PageSize) { ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: skus.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson())); return(skus); } } } catch (Exception exception) { var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception); ChannelAdvisorLogger.LogTraceException(channelAdvisorException); throw channelAdvisorException; } }
/// <summary> /// Gets the items matching filter. /// </summary> /// <param name="filter">The filter.</param> /// <param name="startPage">The first page number to query.</param> /// <param name="pageLimit">The max number of pages to query.</param> /// <param name="mark">use it to simplify navigation inside log, allows to view call ierarchy</param> /// <returns>Items matching supplied filter.</returns> /// <seealso href="http://developer.channeladvisor.com/display/cadn/GetFilteredInventoryItemList"/> public async Task< PagedApiResponse< InventoryItemResponse > > GetFilteredItemsAsync( ItemsFilter filter, int startPage, int pageLimit, Mark mark = null ) { if( mark.IsBlank() ) mark = Mark.CreateNew(); try { ChannelAdvisorLogger.LogStarted( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo(), methodParameters : filter.ToJson() ) ); filter.Criteria.PageSize = 100; filter.Criteria.PageNumber = ( startPage > 0 ) ? startPage - 1 : 1; var items = new List< InventoryItemResponse >(); for( var iteration = 0; iteration < pageLimit; iteration++ ) { filter.Criteria.PageNumber += 1; var itemResponse = await AP.CreateQueryAsync( ExtensionsInternal.CreateMethodCallInfo( this.AdditionalLogInfo ) ).Get( async () => { ChannelAdvisorLogger.LogTraceRetryStarted( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo(), methodParameters : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndResultForRetry ) ? null : filter.ToJson() ) ); var getFilteredInventoryItemListResponse = await this._client.GetFilteredInventoryItemListAsync( this._credentials, this.AccountId, filter.Criteria, filter.DetailLevel, filter.SortField, filter.SortDirection ) .ConfigureAwait( false ); ChannelAdvisorLogger.LogTraceRetryEnd( this.CreateMethodCallInfo( mark : mark, methodResult : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndResultForRetry ) ? null : getFilteredInventoryItemListResponse.ToJson(), additionalInfo : this.AdditionalLogInfo(), methodParameters : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndResultForRetry ) ? null : filter.ToJson() ) ); return getFilteredInventoryItemListResponse; } ).ConfigureAwait( false ); if( !this.IsRequestSuccessful( itemResponse.GetFilteredInventoryItemListResult ) ) continue; var pageItems = itemResponse.GetFilteredInventoryItemListResult.ResultData; if( pageItems == null ) { var pagedApiResponse = new PagedApiResponse< InventoryItemResponse >( items, filter.Criteria.PageNumber, true ); ChannelAdvisorLogger.LogEnd( this.CreateMethodCallInfo( mark : mark, notes : "PageResponse", methodResult : pagedApiResponse.ToJson(), additionalInfo : this.AdditionalLogInfo(), methodParameters : filter.ToJson() ) ); return pagedApiResponse; } items.AddRange( pageItems ); if( pageItems.Length == 0 || pageItems.Length < filter.Criteria.PageSize ) { var pagedApiResponse = new PagedApiResponse< InventoryItemResponse >( items, filter.Criteria.PageNumber, true ); ChannelAdvisorLogger.LogEnd( this.CreateMethodCallInfo( mark : mark, notes : "PageResponse", methodResult : pagedApiResponse.ToJson(), additionalInfo : this.AdditionalLogInfo(), methodParameters : filter.ToJson() ) ); return pagedApiResponse; } } var apiResponse = new PagedApiResponse< InventoryItemResponse >( items, filter.Criteria.PageNumber, false ); ChannelAdvisorLogger.LogEnd( this.CreateMethodCallInfo( mark : mark, methodResult : apiResponse.ToJson(), additionalInfo : this.AdditionalLogInfo(), methodParameters : filter.ToJson() ) ); return apiResponse; } catch( Exception exception ) { var channelAdvisorException = new ChannelAdvisorException( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo() ), exception ); ChannelAdvisorLogger.LogTraceException( channelAdvisorException ); throw channelAdvisorException; } }
/// <summary> /// Gets the items matching filter. /// </summary> /// <param name="filter">The filter.</param> /// <param name="mark">use it to simplify navigation inside log, allows to view call ierarchy</param> /// <returns>Items matching supplied filter.</returns> /// <seealso href="http://developer.channeladvisor.com/display/cadn/GetFilteredInventoryItemList"/> public async Task< IEnumerable< InventoryItemResponse > > GetFilteredItemsAsync( ItemsFilter filter, Mark mark = null ) { if( mark.IsBlank() ) mark = Mark.CreateNew(); try { ChannelAdvisorLogger.LogStarted( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo(), methodParameters : filter.ToJson() ) ); filter.Criteria.PageSize = 100; filter.Criteria.PageNumber = 0; var items = new List< InventoryItemResponse >(); while( true ) { filter.Criteria.PageNumber += 1; var itemResponse = await AP.CreateQueryAsync( ExtensionsInternal.CreateMethodCallInfo( this.AdditionalLogInfo ), this.AccountId, this._cacheManager ).Get( async () => { if( HandleError429.HasError429ForAccountId( this.AccountId, this._cacheManager ) ) await HandleError429.DoDelayAsync().ConfigureAwait( false ); ChannelAdvisorLogger.LogTraceRetryStarted( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo(), methodParameters : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndResultForRetry ) ? null : filter.ToJson() ) ); var getFilteredInventoryItemListResponse = await this._client.GetFilteredInventoryItemListAsync ( this._credentials, this.AccountId, filter.Criteria, filter.DetailLevel, filter.SortField, filter.SortDirection ).ConfigureAwait( false ); ChannelAdvisorLogger.LogTraceRetryEnd( this.CreateMethodCallInfo( mark : mark, methodResult : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndResultForRetry ) ? null : getFilteredInventoryItemListResponse.ToJson(), additionalInfo : this.AdditionalLogInfo(), methodParameters : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndResultForRetry ) ? null : filter.ToJson() ) ); return getFilteredInventoryItemListResponse; } ).ConfigureAwait( false ); if( !this.IsRequestSuccessful( itemResponse.GetFilteredInventoryItemListResult ) ) continue; var pageItems = itemResponse.GetFilteredInventoryItemListResult.ResultData; if( pageItems == null ) { ChannelAdvisorLogger.LogEnd( this.CreateMethodCallInfo( mark : mark, methodResult : items.ToJson(), additionalInfo : this.AdditionalLogInfo(), methodParameters : filter.ToJson() ) ); return items; } items.AddRange( pageItems ); if( pageItems.Length == 0 || pageItems.Length < filter.Criteria.PageSize ) { ChannelAdvisorLogger.LogEnd( this.CreateMethodCallInfo( mark : mark, methodResult : items.ToJson(), additionalInfo : this.AdditionalLogInfo(), methodParameters : filter.ToJson() ) ); return items; } } } catch( Exception exception ) { var channelAdvisorException = new ChannelAdvisorException( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo() ), exception ); ChannelAdvisorLogger.LogTraceException( channelAdvisorException ); throw channelAdvisorException; } }
private IEnumerable< InventoryItemResponse > DownloadAllItems( Mark mark = null ) { ChannelAdvisorLogger.LogTraceStarted( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo() ) ); var filter = new ItemsFilter { DetailLevel = { IncludeClassificationInfo = true, IncludePriceInfo = true, IncludeQuantityInfo = true } }; var inventoryItemResponses = this.GetFilteredItems( filter, mark ); ChannelAdvisorLogger.LogTraceEnd( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo(), methodResult : inventoryItemResponses.ToJson() ) ); return inventoryItemResponses; }
public IEnumerable <string> GetFilteredSkus(ItemsFilter filter, Mark mark = null) { if (mark.IsBlank()) { mark = Mark.CreateNew(); } try { ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson())); filter.Criteria.PageSize = 100; filter.Criteria.PageNumber = 0; filter.DetailLevel.IncludeClassificationInfo = true; filter.DetailLevel.IncludePriceInfo = true; filter.DetailLevel.IncludeQuantityInfo = true; var filteredSkus = new List <string>(); while (true) { filter.Criteria.PageNumber += 1; var itemResponse = AP.CreateQuery(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get( () => { ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : filter.ToJson())); var apiResultOfArrayOfString = this._client.GetFilteredSkuList ( this._credentials, this.AccountId, filter.Criteria, filter.SortField, filter.SortDirection); ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: apiResultOfArrayOfString.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : filter.ToJson())); return(apiResultOfArrayOfString); }); ChannelAdvisorLogger.LogTrace(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndReturnsForTrace) ? null : itemResponse.ToJson(), additionalInfo: this.AdditionalLogInfo())); if (!this.IsRequestSuccessful(itemResponse)) { filteredSkus.Add(null); continue; } var items = itemResponse.ResultData; if (items == null) { ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: filteredSkus.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson())); return(filteredSkus); } filteredSkus.AddRange(items); if (items.Length == 0 || items.Length < filter.Criteria.PageSize) { ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: filteredSkus.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: filter.ToJson())); return(filteredSkus); } } } catch (Exception exception) { var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception); ChannelAdvisorLogger.LogTraceException(channelAdvisorException); throw channelAdvisorException; } }
public IEnumerable< string > GetFilteredSkus( ItemsFilter filter, Mark mark = null ) { if( mark.IsBlank() ) mark = Mark.CreateNew(); try { ChannelAdvisorLogger.LogStarted( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo(), methodParameters : filter.ToJson() ) ); filter.Criteria.PageSize = 100; filter.Criteria.PageNumber = 0; filter.DetailLevel.IncludeClassificationInfo = true; filter.DetailLevel.IncludePriceInfo = true; filter.DetailLevel.IncludeQuantityInfo = true; var filteredSkus = new List< string >(); while( true ) { filter.Criteria.PageNumber += 1; var itemResponse = AP.CreateQuery( ExtensionsInternal.CreateMethodCallInfo( this.AdditionalLogInfo ) ).Get( () => { ChannelAdvisorLogger.LogTraceRetryStarted( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo(), methodParameters : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndResultForRetry ) ? null : filter.ToJson() ) ); var apiResultOfArrayOfString = this._client.GetFilteredSkuList ( this._credentials, this.AccountId, filter.Criteria, filter.SortField, filter.SortDirection ); ChannelAdvisorLogger.LogTraceRetryEnd( this.CreateMethodCallInfo( mark : mark, methodResult : apiResultOfArrayOfString.ToJson(), additionalInfo : this.AdditionalLogInfo(), methodParameters : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndResultForRetry ) ? null : filter.ToJson() ) ); return apiResultOfArrayOfString; } ); ChannelAdvisorLogger.LogTrace( this.CreateMethodCallInfo( mark : mark, methodResult : !this.LogDetailsEnum.HasFlag( LogDetailsEnum.LogParametersAndReturnsForTrace ) ? null : itemResponse.ToJson(), additionalInfo : this.AdditionalLogInfo() ) ); if( !this.IsRequestSuccessful( itemResponse ) ) { filteredSkus.Add( null ); continue; } var items = itemResponse.ResultData; if( items == null ) { ChannelAdvisorLogger.LogEnd( this.CreateMethodCallInfo( mark : mark, methodResult : filteredSkus.ToJson(), additionalInfo : this.AdditionalLogInfo(), methodParameters : filter.ToJson() ) ); return filteredSkus; } filteredSkus.AddRange( items ); if( items.Length == 0 || items.Length < filter.Criteria.PageSize ) { ChannelAdvisorLogger.LogEnd( this.CreateMethodCallInfo( mark : mark, methodResult : filteredSkus.ToJson(), additionalInfo : this.AdditionalLogInfo(), methodParameters : filter.ToJson() ) ); return filteredSkus; } } } catch( Exception exception ) { var channelAdvisorException = new ChannelAdvisorException( this.CreateMethodCallInfo( mark : mark, additionalInfo : this.AdditionalLogInfo() ), exception ); ChannelAdvisorLogger.LogTraceException( channelAdvisorException ); throw channelAdvisorException; } }