public async Task <bool> RequestAccessAsync(int localId, Mark mark = null) { if (mark.IsBlank()) { mark = Mark.CreateNew(); } try { ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString, methodParameters: localId.ToString())); var requestAsyncResult = await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(async() => { var result = await this._client.RequestAccessAsync(this._credentials, localId).ConfigureAwait(false); this.CheckCaSuccess(result.RequestAccessResult); return(result.RequestAccessResult.ResultData); }).ConfigureAwait(false); ; ChannelAdvisorLogger.LogTraceEnd(this.CreateMethodCallInfo(mark: mark, methodResult: requestAsyncResult.ToJson(), additionalInfo: this.AdditionalLogInfoString, methodParameters: localId.ToString())); return(requestAsyncResult); } catch (Exception exception) { var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfoString), exception); ChannelAdvisorLogger.LogTraceException(channelAdvisorException); throw channelAdvisorException; } }
public async Task SynchItemAsync(InventoryItemSubmit item, bool isCreateNew = false, Mark mark = null) { if (mark.IsBlank()) { mark = Mark.CreateNew(); } var parameters = new { item, isCreateNew }; try { ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson())); await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(async() => { ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : parameters.ToJson())); if (!isCreateNew && !(await this.DoesSkuExistAsync(item.Sku, mark).ConfigureAwait(false))) { return; } var resultOfBoolean = await this._client.SynchInventoryItemAsync(this._credentials, this.AccountId, item).ConfigureAwait(false); CheckCaSuccess(resultOfBoolean.SynchInventoryItemResult); ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : resultOfBoolean.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : parameters.ToJson())); }).ConfigureAwait(false); ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: "void", additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson())); } catch (Exception exception) { var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception); ChannelAdvisorLogger.LogTraceException(channelAdvisorException); throw channelAdvisorException; } }
public async Task DeleteItemAsync(string sku, Mark mark = null) { if (mark.IsBlank()) { mark = Mark.CreateNew(); } try { ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: sku)); await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(async() => { ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : sku)); var resultOfBoolean = await this._client.DeleteInventoryItemAsync(this._credentials, this.AccountId, sku).ConfigureAwait(false); CheckCaSuccess(resultOfBoolean.DeleteInventoryItemResult); ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : resultOfBoolean.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : sku)); }).ConfigureAwait(false); ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: sku)); } catch (Exception exception) { var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception); ChannelAdvisorLogger.LogTraceException(channelAdvisorException); throw channelAdvisorException; } }
public async Task AssignLabelListToItemListAsync(string[] labels, bool createLabelIfNotExist, IEnumerable <string> skus, string reason, Mark mark = null) { Condition.Requires(labels, "labels").IsShorterOrEqual(3, "Only up to 3 labels allowed.").IsNotNull(); if (mark.IsBlank()) { mark = Mark.CreateNew(); } var parameters = new { labels, createLabelIfNotExist, skus, reason }; try { ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson())); await skus.DoWithPagesAsync(500, async s => await AP.CreateSubmitAsync( ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do( async() => { ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : s.ToJson())); var resultOfBoolean = await this._client.AssignLabelListToInventoryItemListAsync(this._credentials, this.AccountId, labels, createLabelIfNotExist, s.ToArray(), reason).ConfigureAwait(false); CheckCaSuccess(resultOfBoolean.AssignLabelListToInventoryItemListResult); ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : resultOfBoolean.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : s.ToJson())); } ).ConfigureAwait(false)).ConfigureAwait(false); ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson())); } catch (Exception exception) { var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception); ChannelAdvisorLogger.LogTraceException(channelAdvisorException); throw channelAdvisorException; } }
public async Task UpdateQuantityAndPricesAsync(IEnumerable <InventoryItemQuantityAndPrice> itemQuantityAndPrices, Mark mark = null) { if (mark.IsBlank()) { mark = Mark.CreateNew(); } try { ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: itemQuantityAndPrices.ToJson())); var itemQuantityAndPricesByPages = ToChunks(itemQuantityAndPrices, 800); await itemQuantityAndPricesByPages.DoInBatchAsync(3, async itemsPage => { await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(async() => { ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : itemsPage.ToJson())); var result = await this._client.UpdateInventoryItemQuantityAndPriceListAsync(this._credentials, this.AccountId, itemsPage.ToArray()).ConfigureAwait(false); CheckCaSuccess(result.UpdateInventoryItemQuantityAndPriceListResult); ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : result.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : itemsPage.ToJson())); }).ConfigureAwait(false); }).ConfigureAwait(false); } catch (Exception exception) { var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception); ChannelAdvisorLogger.LogTraceException(channelAdvisorException); throw channelAdvisorException; } }
public async Task SubmitOrderShipmentListAsync(IEnumerable <OrderShipment> orderShipments) { await orderShipments.DoWithPagesAsync(50, async p => await AP.CreateSubmitAsync( ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do( async() => { var result = await this._client.SubmitOrderShipmentListAsync(this._credentials, this.AccountId, p.ToArray()).ConfigureAwait(false); this.CheckCaSuccess(result.SubmitOrderShipmentListResult); } ).ConfigureAwait(false)).ConfigureAwait(false); }
public async Task <IEnumerable <OrderUpdateResponse> > UpdateOrderListAsync(OrderUpdateSubmit[] orderUpdates) { return(await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(async() => { var results = await this._client.UpdateOrderListAsync(this._credentials, this.AccountId, orderUpdates).ConfigureAwait(false); this.CheckCaSuccess(results.UpdateOrderListResult); return results.UpdateOrderListResult.ResultData; }).ConfigureAwait(false)); }
public async Task <int> SubmitOrderAsync(OrderSubmit orderSubmit) { return(await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Get(async() => { var apiResults = await this._client.SubmitOrderAsync(this._credentials, this.AccountId, orderSubmit).ConfigureAwait(false); this.CheckCaSuccess(apiResults.SubmitOrderResult); return apiResults.SubmitOrderResult.ResultData; }).ConfigureAwait(false)); }
public async Task WithdrawListingAsync(IList <string> itemSkus, string withdrawReason) { if (itemSkus == null || itemSkus.Count == 0) { return; } await itemSkus.DoWithPagesAsync(100, async s => await AP.CreateSubmitAsync( ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do( async() => { var result = await this._client.WithdrawListingsAsync(this._credentials, this.AccountId, s.ToArray(), null, withdrawReason).ConfigureAwait(false); this.CheckCaSuccess(result.WithdrawListingsResult); } ).ConfigureAwait(false)).ConfigureAwait(false); }
public async Task MarkOrderShippedAsync(int orderId, string carrierCode, string classCode, string trackingNumber, DateTime dateShipped) { try { await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(async() => { var result = await this._client.SubmitOrderShipmentListAsync(this._credentials, this.AccountId, CreateShipmentByOrderId(orderId, carrierCode, classCode, trackingNumber, dateShipped)).ConfigureAwait(false); this.CheckCaSuccess(result.SubmitOrderShipmentListResult); }).ConfigureAwait(false); } catch (Exception e) { throw new MarkOrderShippedException(orderId.ToString(CultureInfo.InvariantCulture), this.AccountId, carrierCode, classCode, trackingNumber, e); } }
public async Task MarkOrderShippedAsync(string clientOrderId, PartialShipmentContents partialShipmentContents) { try { await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(async() => { var result = await this._client.SubmitOrderShipmentListAsync(this._credentials, this.AccountId, CreatePartialShipmentByClientId(clientOrderId, partialShipmentContents)).ConfigureAwait(false); this.CheckCaSuccess(result.SubmitOrderShipmentListResult); }).ConfigureAwait(false); } catch (Exception e) { throw new MarkOrderShippedException(clientOrderId, this.AccountId, partialShipmentContents.CarrierCode, partialShipmentContents.ClassCode, partialShipmentContents.TrackingNumber, e); } }
public async Task SynchItemsAsync(IEnumerable <InventoryItemSubmit> items, bool isCreateNew = false, Mark mark = null) { if (mark.IsBlank()) { mark = Mark.CreateNew(); } var parameters = new { items, isCreateNew }; try { ChannelAdvisorLogger.LogStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson())); if (!isCreateNew) { var existSkus = (this.DoSkusExist(items.Select(x => x.Sku), mark)).Select(x => x.Sku); items = items.Where(x => existSkus.Contains(x.Sku)); } await items.DoWithPagesAsync(100, async i => await AP.CreateSubmitAsync( ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do( async() => { await AP.CreateSubmitAsync(ExtensionsInternal.CreateMethodCallInfo(this.AdditionalLogInfo)).Do(async() => { ChannelAdvisorLogger.LogTraceRetryStarted(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : i.ToJson())); var resultOfBoolean = await this._client.SynchInventoryItemListAsync(this._credentials, this.AccountId, i.ToArray()).ConfigureAwait(false); CheckCaSuccess(resultOfBoolean.SynchInventoryItemListResult); ChannelAdvisorLogger.LogTraceRetryEnd(this.CreateMethodCallInfo(mark: mark, methodResult: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : resultOfBoolean.ToJson(), additionalInfo: this.AdditionalLogInfo(), methodParameters: !this.LogDetailsEnum.HasFlag(LogDetailsEnum.LogParametersAndResultForRetry) ? null : i.ToJson())); }).ConfigureAwait(false); } ).ConfigureAwait(false)).ConfigureAwait(false); ChannelAdvisorLogger.LogEnd(this.CreateMethodCallInfo(mark: mark, methodResult: "void", additionalInfo: this.AdditionalLogInfo(), methodParameters: parameters.ToJson())); } catch (Exception exception) { var channelAdvisorException = new ChannelAdvisorException(this.CreateMethodCallInfo(mark: mark, additionalInfo: this.AdditionalLogInfo()), exception); ChannelAdvisorLogger.LogTraceException(channelAdvisorException); throw channelAdvisorException; } }