예제 #1
0
 public IActionResult GetAll(int?parentId)
 {
     using (var uow = _unitOfWorkProvider.CreateReadOnly())
     {
         return(Ok(_categoryService.GetAll(parentId)));
     }
 }
        private void ExportCustomers()
        {
            try
            {
                SynchronizeStampEntity synchronizeStamp = null;
                DateTime stampTo = DateTime.Now;

                using (var uow = unitOfWorkProvider.CreateReadOnly())
                {
                    synchronizeStamp = synchronizeStampRepository.Get(SynchronizeCodes.Customer, SynchronizeDirectionType.Export);
                }

                DateTime stampFrom = synchronizeStamp?.DateTimeStamp ?? DateTime.MinValue;

                IReadOnlyCollection <int> customerIds = null;

                using (var uow = unitOfWorkProvider.CreateReadOnly())
                {
                    customerIds = customerRepository.GetModifiedCustomersIdsWithWebAccount(stampFrom, stampTo);
                }

                if (Enumerable.Any(customerIds))
                {
                    logger.LogDebug($"Starting synchronize {customerIds.Count} customers");

                    var parallelOptions = new ParallelOptions
                    {
                        MaxDegreeOfParallelism = 1
                    };

                    Parallel.ForEach(customerIds, parallelOptions, x => ProcessCustomerId(x, stampTo));

                    if (synchronizeStamp == null)
                    {
                        synchronizeStamp = SynchronizeStampFactory.Create(SynchronizeCodes.Customer, SynchronizeDirectionType.Export);
                    }

                    synchronizeStamp.DateTimeStamp = stampTo;

                    using (var uow = unitOfWorkProvider.Create())
                    {
                        synchronizeStampRepository.SaveOrUpdate(synchronizeStamp);
                        uow.Commit();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"Synchronize customers to PrestaShop error: {ex.ToString()}");
            }
        }
예제 #3
0
        public Task RunImport(IServiceScope serviceScope)
        {
            try
            {
                _unitOfWorkProvider      = serviceScope.ServiceProvider.GetRequiredService <IUnitOfWorkProvider>();
                _synchronizeStampService = serviceScope.ServiceProvider.GetRequiredService <ISynchronizeStampService>();
                _api = serviceScope.ServiceProvider.GetRequiredService <IEnovaAPiClient>();

                _stamp = _synchronizeStampService.GetImportStampAsync(SynchronizeCode, SynchronizeDirection).Result;
                _dbts  = _api.GetDbtsAsync().Result;

                IEnumerable <TEntry> entries;

                using (var uow = _unitOfWorkProvider.CreateReadOnly())
                {
                    entries = GetEntriesAsync(_stamp, _dbts).Result;
                }

                if (entries.Any())
                {
                    Parallel.ForEach(entries, GetParrallelOptions(), ProcessEntryCore);
                }

                _synchronizeStampService.SaveImportStampAsync(SynchronizeCode, _dbts, SynchronizeDirection).Wait();
            }
            catch (Exception ex)
            {
                HandleImportExeception(ex);
            }

            return(Task.CompletedTask);
        }
예제 #4
0
        private void SynchronizeOrder()
        {
            logger.LogDebug("Starting synchronize orders");

            try
            {
                SynchronizeStampEntity synchronizeStamp = null;
                DateTime stampTo = DateTime.Now;

                using (var uow = unitOfWorkProvider.CreateReadOnly())
                {
                    synchronizeStamp = synchronizeStampRepository.Get(SynchronizeCodes.Order, SynchronizeDirectionType.Import);
                }

                DateTime stampFrom = synchronizeStamp?.DateTimeStamp ?? DateTime.MinValue;

                IReadOnlyCollection <long> psOrderIds = psOrderRepository.GetAllModifiedBetween(stampFrom, stampTo);

                if (Enumerable.Any(psOrderIds))
                {
                    logger.LogDebug($"Starting synchronize {psOrderIds.Count} orders");

                    var parallelOptions = new ParallelOptions
                    {
                        MaxDegreeOfParallelism = 1
                    };

                    Parallel.ForEach(psOrderIds, parallelOptions, x => ProcessOrderId(x, stampTo));

                    if (synchronizeStamp == null)
                    {
                        synchronizeStamp = SynchronizeStampFactory.Create(SynchronizeCodes.Order, SynchronizeDirectionType.Import);
                    }

                    synchronizeStamp.DateTimeStamp = stampTo;

                    using (var uow = unitOfWorkProvider.Create())
                    {
                        synchronizeStampRepository.SaveOrUpdate(synchronizeStamp);
                        uow.Commit();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"Synchronize orders from PrestaShop error: {ex}");
            }
        }