Esempio n. 1
0
        public virtual async Task <bool> PutStockItemAsync(PutStockItem putStockItem, Mark markForLog)
        {
            try
            {
                var methodParameters = new List <PutStockItem> {
                    putStockItem
                }.ToJson();

                var catalogInventoryStockItemUpdateEntity = (putStockItem.Qty > 0) ?
                                                            new catalogInventoryStockItemUpdateEntity()
                {
                    is_in_stock = 1, is_in_stockSpecified = true, qty = putStockItem.Qty.ToString()
                } :
                new catalogInventoryStockItemUpdateEntity()
                {
                    is_in_stock = 0, is_in_stockSpecified = false, qty = putStockItem.Qty.ToString()
                };

                const int maxCheckCount    = 2;
                const int delayBeforeCheck = 120000;

                var res           = false;
                var privateClient = this._clientFactory.GetClient();


                await ActionPolicies.GetAsync.Do(async() =>
                {
                    var statusChecker = new StatusChecker(maxCheckCount);
                    TimerCallback tcb = statusChecker.CheckStatus;

                    privateClient = this._clientFactory.RefreshClient(privateClient);
                    var sessionId = await this.GetSessionId().ConfigureAwait(false);

                    using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                    {
                        MagentoLogger.LogTraceStarted(CreateMethodCallInfo(methodParameters, markForLog));

                        var temp = await privateClient.catalogInventoryStockItemUpdateAsync(sessionId.SessionId, putStockItem.ProductId, catalogInventoryStockItemUpdateEntity).ConfigureAwait(false);

                        res = temp.result > 0;

                        var updateBriefInfo = string.Format("{{Success:{0}}}", res);
                        MagentoLogger.LogTraceEnded(CreateMethodCallInfo(methodParameters, markForLog, methodResult: updateBriefInfo));
                    }
                }).ConfigureAwait(false);

                return(res);
            }
            catch (Exception exc)
            {
                var productsBriefInfo = new List <PutStockItem> {
                    putStockItem
                }.ToJson();
                throw new MagentoSoapException($"An error occured during PutStockItemsAsync({productsBriefInfo})", exc);
            }
        }
        public virtual async Task <bool> PutStockItemAsync(PutStockItem putStockItem, Mark markForLog)
        {
            var catalogInventoryStockItemUpdateEntity = putStockItem.Qty > 0 ?
                                                        new catalogInventoryStockItemUpdateEntity()
            {
                is_in_stock = 1, is_in_stockSpecified = true, qty = putStockItem.Qty.ToString()
            } :
            new catalogInventoryStockItemUpdateEntity()
            {
                is_in_stock = 0, is_in_stockSpecified = false, qty = putStockItem.Qty.ToString()
            };

            return(await this.GetWithAsync(
                       res => res.result > 0,
                       async ( client, session ) => await client.catalogInventoryStockItemUpdateAsync( session, putStockItem.ProductId, catalogInventoryStockItemUpdateEntity ).ConfigureAwait(false), 600000).ConfigureAwait(false));
        }
Esempio n. 3
0
 public Task <bool> PutStockItemAsync(PutStockItem putStockItem, Mark markForLog)
 {
     return(null);
 }
        public virtual async Task <bool> PutStockItemAsync(PutStockItem putStockItem, Mark markForLog)
        {
            var productsBriefInfo = new List <PutStockItem> {
                putStockItem
            }.ToJson();

            try
            {
                const int maxCheckCount    = 2;
                const int delayBeforeCheck = 120000;

                var res           = false;
                var privateClient = this._clientFactory.CreateMagentoCatalogInventoryStockServiceClient();

                await ActionPolicies.GetAsync.Do(async() =>
                {
                    var statusChecker = new StatusChecker(maxCheckCount);
                    TimerCallback tcb = statusChecker.CheckStatus;

                    privateClient = this._clientFactory.RefreshMagentoCatalogInventoryStockServiceClient(privateClient);

                    using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                    {
                        MagentoLogger.LogTraceStarted(this.CreateMethodCallInfo(productsBriefInfo, markForLog));

                        var catalogInventoryDataStockItemInterface = new CatalogInventoryDataStockItemInterface()
                        {
                            qty                            = putStockItem.Qty.ToString(),
                            productId                      = int.Parse(putStockItem.ProductId),
                            productIdSpecified             = true,
                            isInStock                      = putStockItem.Qty > 0,
                            isQtyDecimal                   = false,
                            showDefaultNotificationMessage = false,
                            useConfigMinQty                = true,
                            minQty                         = 0,
                            useConfigMinSaleQty            = 1,
                            minSaleQty                     = 1,
                            useConfigMaxSaleQty            = true,
                            maxSaleQty                     = 10000,
                            useConfigBackorders            = true,
                            backorders                     = 0,
                            useConfigNotifyStockQty        = true,
                            notifyStockQty                 = 1,
                            useConfigQtyIncrements         = true,
                            qtyIncrements                  = 0,
                            useConfigEnableQtyInc          = false,
                            enableQtyIncrements            = false,
                            useConfigManageStock           = true,
                            manageStock                    = true,
                            //lowStockDate = "2016-02-29 20:48:26",
                            isDecimalDivided       = false,
                            stockStatusChangedAuto = 1
                        };
                        var catalogInventoryStockRegistryV1UpdateStockItemBySkuRequest = new CatalogInventoryStockRegistryV1UpdateStockItemBySkuRequest()
                        {
                            //productSku = x.Sku,
                            stockItem = catalogInventoryDataStockItemInterface
                        };

                        var temp = await privateClient.catalogInventoryStockRegistryV1UpdateStockItemBySkuAsync(catalogInventoryStockRegistryV1UpdateStockItemBySkuRequest).ConfigureAwait(false);

                        res = temp.catalogInventoryStockRegistryV1UpdateStockItemBySkuResponse.result > 0;

                        var updateBriefInfo = string.Format("{{ErrorCode:{0}}}", res);
                        MagentoLogger.LogTraceEnded(this.CreateMethodCallInfo(productsBriefInfo, markForLog, methodResult: updateBriefInfo));
                    }
                }).ConfigureAwait(false);

                return(res);
            }
            catch (Exception exc)
            {
                throw new MagentoSoapException($"An error occured during PutStockItemsAsync({productsBriefInfo})", exc);
            }
        }
Esempio n. 5
0
 public UpdateRessult(PutStockItem putStockItem, int success)
 {
     this.PutStockItem = putStockItem;
     this.Success      = success;
 }