public IEnumerable <string> Resolve(Usr_Pratri source, ProductSpecificationDTO destination, IEnumerable <string> member, ResolutionContext context)
        {
            if (source.Usr_Pratri_Valor.IndexOf(";") == -1)
            {
                return(new List <string> {
                    source.Usr_Pratri_Valor
                });
            }

            return(source.Usr_Pratri_Valor.Split(';').Select(p => p.Trim()).ToList());
        }
예제 #2
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 items = _mapper.Map <IEnumerable <Usr_Pratri>, IEnumerable <SKUSpecificationDTO> >(await _repository.ProductsAndSKUSpecifications.GetSKUSpecificationForVTEX(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 _SKUspecificationsClient.PostSKUSpecificationWithNewIDAsync(item, item.SKUId, cancellationToken);

                    break;

                case "UPDATE":
                    succesOperation = await _SKUspecificationsClient.PutSKUSpecificationAsync(item, item.SKUId.ToString(), cancellationToken);

                    break;

                case "DELETE":
                    if (item.Id != 0)
                    {
                        succesOperation = await _SKUspecificationsClient.DeleteSpecificationAsync(item, item.SKUId, item.Id, cancellationToken);
                    }
                    break;

                default:
                    break;
                }

                if (succesOperation || succesOperationWithNewID.Success)
                {
                    Usr_Pratri productSpecificationTransfered = await _repository.ProductsAndSKUSpecifications.Get(cancellationToken, new object[] { item.RowId });

                    Usr_Pratri_Real productSpecificationReal = await _repository.ProductsAndSKUSpecificationsReal
                                                               .Get(cancellationToken, new object[] { productSpecificationTransfered.Usr_Pratri_Tippro.Trim(),
                                                                                                      productSpecificationTransfered.Usr_Pratri_Artcod.Trim(),
                                                                                                      productSpecificationTransfered.Usr_Pratri_Orden });


                    productSpecificationTransfered.Usr_Vtex_Transf = "S";
                    if (succesOperationWithNewID.Success)
                    {
                        productSpecificationReal.Usr_Pratri_Idvtex       = succesOperationWithNewID.NewId;
                        productSpecificationTransfered.Usr_Pratri_Idvtex = succesOperationWithNewID.NewId;
                    }

                    await _repository.Complete();
                }
                else
                {
                    Usr_Pratri productSpecificationTransfered = await _repository.ProductsAndSKUSpecifications.Get(cancellationToken, new object[] { item.RowId });

                    productSpecificationTransfered.Usr_Vtex_Transf = "E";

                    await _repository.Complete();
                }
            }
            return(items.Count() == MAX_ELEMENTS_IN_QUEUE);
        }
예제 #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();

            var productSpecifications       = _mapper.Map <IEnumerable <Usr_Pratri>, IEnumerable <ProductSpecificationDTO> >(await _repository.ProductsAndSKUSpecifications.GetProductSpecificationForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));
            var productFatherSpecifications = _mapper.Map <IEnumerable <Usr_Stmppa>, IEnumerable <ProductSpecificationDTO> >(await _repository.ProductsFatherSpecifications.GetForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            IEnumerable <ProductSpecificationDTO> items = productSpecifications.Concat(productFatherSpecifications).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":
                case "UPDATE":
                    succesOperation = await _specificationsClient.PostProductSpecificationAsync(new List <ProductSpecificationDTO> {
                        item
                    }, item.ProductId, cancellationToken);

                    break;

                case "DELETE":
                    if (item.Id != 0)
                    {
                        succesOperation = await _specificationsClient.DeleteSpecificationAsync(item, item.ProductId, item.Id, cancellationToken);
                    }
                    break;

                default:
                    break;
                }

                if (succesOperation || succesOperationWithNewID.Success)
                {
                    switch (item.Usr_St_Oalias)
                    {
                    case "USR_PRATRI":
                        Usr_Pratri productSpecificationTransfered = await _repository.ProductsAndSKUSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productSpecificationTransfered.Usr_Vtex_Transf = "S";

                        break;

                    case "USR_STMPPA":
                        Usr_Stmppa productFatherSpecificationTransfered = await _repository.ProductsFatherSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productFatherSpecificationTransfered.Usr_Vtex_Transf = "S";
                        break;

                    case "USR_PRATRM":
                        Usr_Pratrm productMotoSpecificationTransfered = await _repository.ProductsFatherMotoSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productMotoSpecificationTransfered.Usr_Vtex_Transf = "S";
                        break;

                    default:
                        break;
                    }
                    await _repository.Complete();
                }
                else
                {
                    switch (item.Usr_St_Oalias)
                    {
                    case "USR_PRATRI":
                        Usr_Pratri productSpecificationTransfered = await _repository.ProductsAndSKUSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productSpecificationTransfered.Usr_Vtex_Transf = "E";
                        break;

                    case "USR_STMPPA":
                        Usr_Stmppa productFatherSpecificationTransfered = await _repository.ProductsFatherSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productFatherSpecificationTransfered.Usr_Vtex_Transf = "E";
                        break;

                    case "USR_PRATRM":
                        Usr_Pratrm productMotoSpecificationTransfered = await _repository.ProductsFatherMotoSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productMotoSpecificationTransfered.Usr_Vtex_Transf = "E";
                        break;

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