/// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation;

            var items = await _repository.ProductsSKU.GetPricesForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE);

            if (!items.Any())
            {
                return(false);
            }

            foreach (var item in items)
            {
                succesOperation = await _pricesClient.PutPricesAsync(item, item.Id, cancellationToken);

                if (succesOperation)
                {
                    Stmpdh_Real PricesTransfered = await _repository.ProductsSKUReal.Get(cancellationToken, new object[] { item.Stmpdh_Tippro, item.Stmpdh_Artcod });

                    PricesTransfered.Usr_Vtex_Pretra = "S";

                    await _repository.Complete();
                }
            }
            return(items.Count() == MAX_ELEMENTS_IN_QUEUE);
        }
        /// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation = true;
            VTEXNewIDResponse succesOperationWithNewID = new VTEXNewIDResponse();

            var itemsSku = await _repository.ProductsSKUReal.GetSkuForFiles(cancellationToken, MAX_ELEMENTS_IN_QUEUE);

            //var items = _mapper.Map<IEnumerable<Usr_Stimpr>, IEnumerable<SKUFileDTO>>(await _repository.SKUFiles.GetForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            if (!itemsSku.Any())
            {
                return(false);
            }

            foreach (var itemSku in itemsSku)
            {
                succesOperation = true;
                await _SKUFilesClient.DeleteAllSkuAsync(itemSku.Usr_Stmpdh_IdSKUvtex, cancellationToken);

                var itemsFiles = _mapper.Map <IEnumerable <Usr_Stimpr>, IEnumerable <SKUFileDTO> >(await _repository.SKUFiles.GetForVTEX(cancellationToken, itemSku.Usr_Stmpdh_IdSKUvtex));

                foreach (var item in itemsFiles)
                {
                    item.Url = $"{Configuration["VTEX:ImagesBasePath"]}/{item.Url}.jpg";

                    succesOperationWithNewID = await _SKUFilesClient.PostFileWithNewIDAsync(item, item.SKUId, cancellationToken);

                    if (!succesOperationWithNewID.Success)
                    {
                        succesOperation = false;
                    }
                }

                if (succesOperation)
                {
                    Stmpdh_Real SkuReal = await _repository.ProductsSKUReal
                                          .Get(cancellationToken, new object[] { itemSku.Stmpdh_Tippro.Trim(),
                                                                                 itemSku.Stmpdh_Artcod.Trim() });

                    if (succesOperationWithNewID.Success)
                    {
                        SkuReal.Usr_Vtex_Imgtra = "S";
                    }

                    await _repository.Complete();
                }
            }
            return(itemsSku.Count() == MAX_ELEMENTS_IN_QUEUE);
        }
Exemplo n.º 3
0
        /// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation = false;
            VTEXNewIDResponse succesOperationWithNewID = new VTEXNewIDResponse();

            IEnumerable <SkuDTO> items = _mapper.Map <IEnumerable <Stmpdh>, IEnumerable <SkuDTO> >(await _repository.ProductsSKU.GetSKUForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            if (!items.Any())
            {
                return(false);
            }

            foreach (var item in items)
            {
                // Put in your internal queue to process async
                // It is not recommend to process direct here, if your systems start to get slow the item will be visible in the queue and you will process more the one time
                switch (item.Sfl_TableOperation)
                {
                case "INSERT":
                    succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);

                    break;

                case "UPDATE":
                    if (item.Id == 0)     //Quiere decir que no se dio de alta en vtex aun
                    {
                        succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);
                    }
                    else
                    {
                        succesOperation = await _client.PutAsync(item, item.Id.ToString(), cancellationToken);
                    }
                    break;

                default:
                    break;
                }

                if (succesOperation || succesOperationWithNewID.Success)
                {
                    if (item.RowId == 0) //Activacion de SKU
                    {
                        Stmpdh_Real SKUReal = await _repository.ProductsSKUReal
                                              .Get(cancellationToken, new object[] { item.RefId.Substring(0, 3),
                                                                                     item.RefId.Substring(3, 9) });


                        SKUReal.Usr_Vtex_Isacti = "S";
                    }
                    else
                    {
                        //21/10/2021: Se deja de usar tabla de log para transferir productos
                        //Stmpdh SKUTransfered = await _repository.ProductsSKU.Get(cancellationToken, new object[] { item.RowId });
                        Stmpdh_Real SKUReal = await _repository.ProductsSKUReal
                                              .Get(cancellationToken, new object[] { item.Stmpdh_Tippro.Trim(),
                                                                                     item.Stmpdh_Artcod.Trim() });

                        SKUReal.Usr_Vtex_Skutra = "S";

                        if (succesOperationWithNewID.Success)
                        {
                            SKUReal.Usr_Stmpdh_IdSKUvtex = succesOperationWithNewID.NewId;
                        }
                    }

                    await _repository.Complete();
                }
                else
                {
                    if (item.RowId != 0)
                    {
                        Stmpdh_Real Sku = await _repository.ProductsSKUReal.Get(cancellationToken, new object[] { item.Stmpdh_Tippro.Trim(),
                                                                                                                  item.Stmpdh_Artcod.Trim() });

                        Sku.Usr_Vtex_Skutra = "E";
                        await _repository.Complete();
                    }
                }
            }
            return(items.Count() == MAX_ELEMENTS_IN_QUEUE);
        }
Exemplo n.º 4
0
        /// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation = false;
            VTEXNewIDResponse succesOperationWithNewID = new VTEXNewIDResponse();

            var productsFather = _mapper.Map <IEnumerable <Usr_Stmpph>, IEnumerable <ProductDTO> >(await _repository.ProductsFather.GetForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));
            var productsSKUA   = await _repository.ProductsSKU.GetProductForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE);

            var productsSKU = _mapper.Map <IEnumerable <Stmpdh>, IEnumerable <ProductDTO> >(await _repository.ProductsSKU.GetProductForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            IEnumerable <ProductDTO> items = productsFather.Concat(productsSKU).OrderBy(c => c.Sfl_LoginDateTime).Take(MAX_ELEMENTS_IN_QUEUE);

            if (!items.Any())
            {
                return(false);
            }

            foreach (var item in items)
            {
                // Put in your internal queue to process async
                // It is not recommend to process direct here, if your systems start to get slow the item will be visible in the queue and you will process more the one time
                switch (item.Sfl_TableOperation)
                {
                case "INSERT":
                    succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);

                    break;

                case "UPDATE":
                    if (item.Id == 0)     //Quiere decir que no se dio de alta en vtex aun
                    {
                        succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);
                    }
                    else
                    {
                        succesOperation = await _client.PutAsync(item, item.Id.ToString(), cancellationToken);
                    }
                    break;

                default:
                    break;
                }

                if (succesOperation || succesOperationWithNewID.Success)
                {
                    switch (item.Stmpdh_Oalias)
                    {
                    case "STMPDH":

                        //21/10/2021: Se deja de utilizar tabla de log para enviar productos
                        //Stmpdh productSKUTransfered = await _repository.ProductsSKU.Get(cancellationToken, new object[] {item.RowId});
                        Stmpdh_Real productSKUReal = await _repository.ProductsSKUReal
                                                     .Get(cancellationToken, new object[] { item.Stmpdh_Tippro.Trim(),
                                                                                            item.Stmpdh_Artcod.Trim() });


                        productSKUReal.Usr_Vtex_Transf = "S";
                        //productSKUTransfered.Usr_Vtex_Transf = "S";
                        if (succesOperationWithNewID.Success)
                        {
                            productSKUReal.Usr_Stmpdh_Idvtex = succesOperationWithNewID.NewId;
                            // productSKUTransfered.Usr_Stmpdh_Idvtex = succesOperationWithNewID.NewId;
                        }
                        break;

                    case "USR_STMPPH":
                        Usr_Stmpph productFatherTransfered = await _repository.ProductsFather.Get(cancellationToken, new object[] { item.RowId });

                        Usr_Stmpph_Real productFatherReal = await _repository.ProductsFatherReal
                                                            .Get(cancellationToken, new object[] { productFatherTransfered.Usr_Stmpph_Indcod.Trim() });


                        productFatherTransfered.Usr_Vtex_Transf = "S";
                        if (succesOperationWithNewID.Success)
                        {
                            productFatherReal.Usr_Stmpph_Idvtex = succesOperationWithNewID.NewId;
                        }
                        break;

                    default:
                        break;
                    }
                    await _repository.Complete();
                }
                else
                {
                    switch (item.Stmpdh_Oalias)
                    {
                    case "STMPDH":
                        Stmpdh_Real productSKU = await _repository.ProductsSKUReal.Get(cancellationToken, new object[] { item.Stmpdh_Tippro.Trim(), item.Stmpdh_Artcod.Trim() });

                        productSKU.Usr_Vtex_Transf = "E";
                        break;

                    case "USR_STMPPH":
                        Usr_Stmpph productFather = await _repository.ProductsFather.Get(cancellationToken, new object[] { item.RowId });

                        productFather.Usr_Vtex_Transf = "E";
                        break;

                    default:
                        break;
                    }
                    await _repository.Complete();
                }
            }
            return(items.Count() == MAX_ELEMENTS_IN_QUEUE);
        }