Esempio n. 1
0
        protected SyncResult UpdateExistingUnshippedOrders(CancellationToken?token,
                                                           ILogService log,
                                                           IMarketApi api,

                                                           Func <ILogService, IMarketApi, ISyncInformer, string, IList <ListingOrderDTO> > getOrderItemsFromMarketFunc,
                                                           Func <ILogService, IUnitOfWork, IMarketApi, DTOMarketOrder, IList <ListingOrderDTO>, string, bool> fillOrderListingsFunc,

                                                           ISyncInformer syncInfo,
                                                           IList <IShipmentApi> rateProviders,
                                                           IQuantityManager quantityManager,
                                                           IEmailService emailService,
                                                           IOrderValidatorService validatorService,

                                                           IList <string> excludeOrderIdList,

                                                           ICompanyAddressService companyAddress,
                                                           ITime time)
        {
            IList <Order> ordersToUpdate = new List <Order>();

            try
            {
                using (var db = new UnitOfWork(log))
                {
                    var existOrders = db.Orders.GetOrdersByStatus(MarketType.Magento,
                                                                  "",
                                                                  new [] {
                        OrderStatusEnumEx.Pending,
                        OrderStatusEnumEx.Unshipped,
                        OrderStatusEnumEx.PartiallyShipped
                    }
                                                                  ).ToList();

                    if (excludeOrderIdList != null)
                    {
                        ordersToUpdate = existOrders.Where(o => !excludeOrderIdList.Contains(o.AmazonIdentifier)).ToList();
                    }
                    else
                    {
                        ordersToUpdate = existOrders;
                    }

                    log.Info("Orders to update count:" + ordersToUpdate.Count
                             + " (existing in DB=" + existOrders.Count
                             + ", exclude list=" + (excludeOrderIdList != null ? excludeOrderIdList.Count.ToString() : "[null]") + ")");

                    var index = 0;
                    var step  = 50;
                    while (index < ordersToUpdate.Count)
                    {
                        var ordersToProcess = ordersToUpdate.Skip(index).Take(step).ToList();
                        log.Info("Start process orders from api, from=" + index + ", count=" + ordersToProcess.Count);

                        if (!ProcessExistOrdersPack(token,
                                                    log,
                                                    api,

                                                    getOrderItemsFromMarketFunc,

                                                    syncInfo,
                                                    db,

                                                    rateProviders,
                                                    quantityManager,
                                                    emailService,
                                                    validatorService,

                                                    companyAddress,
                                                    ordersToProcess,
                                                    time))
                        {
                            syncInfo.AddWarning("", "The pending orders pack processing has failed");
                            //Break cycle if pack processing is fail, something wrong (m.b. unavailable Db, m.b. parallel sync)
                            return(new SyncResult()
                            {
                                IsSuccess = false
                            });
                        }
                        index += step;
                        syncInfo.PingSync();
                    }
                }
                return(new SyncResult()
                {
                    IsSuccess = true,
                    ProcessedOrders = ordersToUpdate.Select(o => new SyncResultOrderInfo()
                    {
                        OrderId = o.AmazonIdentifier,
                        OrderStatus = o.OrderStatus
                    }).ToList()
                });
            }
            catch (Exception ex)
            {
                LogError(log, syncInfo, ex, "", "Error when updating existing orders");
                return(new SyncResult()
                {
                    IsSuccess = false
                });
            }
        }
Esempio n. 2
0
        protected SyncResult SyncAllNewOrders(CancellationToken?token,
                                              ILogService log,
                                              IMarketApi api,
                                              MarketType market,

                                              Func <ILogService, IMarketApi, ISyncInformer, string, IList <ListingOrderDTO> > getOrderItemsFromMarketFunc,
                                              Func <ILogService, IUnitOfWork, IMarketApi, DTOMarketOrder, IList <ListingOrderDTO>, string, bool> checkOrderListingsFunc,

                                              ISyncInformer syncInfo,
                                              IList <IShipmentApi> rateProviders,
                                              IQuantityManager quantityManager,
                                              ISettingsService settings,
                                              IEmailService emailService,
                                              IOrderValidatorService validatorService,
                                              ICacheService cacheService,

                                              ICompanyAddressService companyAddress,
                                              DateTime syncMissedFrom,
                                              ITime time)
        {
            try
            {
                log.Info("Get missed orders");
                var statusList = new List <string> {
                    OrderStatusEnumEx.Canceled,
                    OrderStatusEnumEx.Shipped,
                    OrderStatusEnumEx.Unshipped,
                    OrderStatusEnumEx.Pending
                };                               //NOTE: On API level there status will be converted on eBay status
                var allOrders = api.GetOrders(log, syncMissedFrom, statusList).ToList();

                if (allOrders.Any())
                {
                    var result = ProcessNewOrdersPack(token,
                                                      log,
                                                      api,

                                                      getOrderItemsFromMarketFunc,

                                                      rateProviders,
                                                      validatorService,
                                                      syncInfo,
                                                      settings,
                                                      quantityManager,
                                                      emailService,
                                                      cacheService,

                                                      companyAddress,
                                                      allOrders,
                                                      time);

                    if (!result.IsSuccess)
                    {
                        syncInfo.AddWarning("", "The orders pack processing has failed");
                        return(new SyncResult()
                        {
                            IsSuccess = false
                        });
                    }

                    return(result);
                }

                return(new SyncResult()
                {
                    IsSuccess = true,
                    ProcessedOrders = new List <SyncResultOrderInfo>()
                });
            }
            catch (Exception ex)
            {
                syncInfo.AddError(null, "Error when storing new unshipped orders", ex);
                log.Error("Error when storing new unshipped orders", ex);
                return(new SyncResult()
                {
                    IsSuccess = false
                });
            }
        }
Esempio n. 3
0
 public CompanyAddressController(ICompanyAddressService companyAddressService)
 {
     _companyAddressService = companyAddressService;
 }