public void GetOrders(IMarketApi api, string orderId)
 {
     if (String.IsNullOrEmpty(orderId))
     {
         var orders = api.GetOrders(_log, DateTime.UtcNow.AddDays(-4), null);
         _log.Info(orders.Count().ToString());
     }
     else
     {
         var orders = api.GetOrders(_log, new List <string>()
         {
             orderId
         });
         _log.Info(orders.Count().ToString());
     }
 }
예제 #2
0
        protected SyncResult SyncAllNewOrders(CancellationToken?token,
                                              ILogService log,
                                              IMarketApi api,
                                              MarketType market,

                                              Func <ILogService, IMarketApi, ISyncInformer, string, IList <ListingOrderDTO> > getOrderItemsFromMarketFunc,

                                              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
                });
            }
        }
예제 #3
0
        /// <summary>
        /// Requested new pending orders (from last exist pending order date)
        /// </summary>
        /// <returns></returns>
        protected SyncResult StoreNewPendingOrders(CancellationToken?token,
                                                   ILogService log,
                                                   IMarketApi api,

                                                   Func <ILogService, IMarketApi, ISyncInformer, string, IList <ListingOrderDTO> > getOrderItemsFromMarketFunc,

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

                                                   ICompanyAddressService companyAddress,
                                                   ITime time)
        {
            try
            {
                using (var db = new UnitOfWork(_log))
                {
                    var lastPending = db.Orders
                                      .GetFiltered(o => o.OrderStatus == OrderStatusEnumEx.Pending &&
                                                   o.Market == (int)api.Market &&
                                                   o.MarketplaceId == api.MarketplaceId)
                                      .OrderBy(o => o.Id).FirstOrDefault();

                    var date = lastPending != null && lastPending.OrderDate.HasValue ? lastPending.OrderDate : null;
                    log.Info(date != null ? "Last pending order date: " + date.Value : "No pending orders!");

                    var updatedAfter = date ?? DateHelper.GetAmazonNowTime().AddDays(-1);
                    log.Info(string.Format("Process Orders created since {0}", updatedAfter));

                    var statusList = new List <string> {
                        OrderStatusEnum.Pending.Str()
                    };

                    var pendingOrders = api.GetOrders(log, updatedAfter, statusList).ToList();
                    log.Info("Total pending orders:" + pendingOrders.Count());

                    syncInfo.PingSync();

                    var result = ProcessNewOrdersPack(token,
                                                      log,
                                                      api,
                                                      getOrderItemsFromMarketFunc,

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

                                                      companyAddress,
                                                      pendingOrders,
                                                      time);

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

                    return(result);
                }
            }
            catch (Exception ex)
            {
                syncInfo.AddError(null, "Error when storing new orders", ex);
                log.Error("Error when storing new orders", ex);
                return(new SyncResult()
                {
                    IsSuccess = false
                });
            }
        }
예제 #4
0
        protected SyncResult SyncAllUnshippedOrders(CancellationToken?cancel,
                                                    ILogService log,
                                                    IMarketApi api,

                                                    Func <ILogService, IMarketApi, ISyncInformer, string, IList <ListingOrderDTO> > getOrderItemsFromMarketFunc,

                                                    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");

                SyncResult result     = new SyncResult();
                var        statusList = new List <string> {
                    OrderStatusEnumEx.Unshipped, OrderStatusEnumEx.PartiallyShipped, OrderStatusEnumEx.Canceled
                };
                var unshippedOrders = api.GetOrders(log, syncMissedFrom, statusList).ToList();

                if (unshippedOrders.Any())
                {
                    result = ProcessNewOrdersPack(cancel,
                                                  log,
                                                  api,

                                                  getOrderItemsFromMarketFunc,

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

                                                  companyAddress,
                                                  unshippedOrders,
                                                  time);

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

                return(new SyncResult()
                {
                    IsSuccess = true,
                    //NOTE: Return all unshipped orders for correct calculation total orders on Amazon
                    //unprocessed orders actual didn't updated (we can safely skip processing of it)
                    ProcessedOrders = result.ProcessedOrders,
                    SkippedOrders = result.SkippedOrders,

                    /*unshippedOrders.Select(o => new SyncResultOrderInfo()
                     * {
                     *  OrderId = o.OrderId,
                     *  OrderStatus = o.OrderStatus
                     * }).ToList()*/
                });
            }
            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
                });
            }
        }
        public void GetOrders(IMarketApi api)
        {
            var orders = api.GetOrders(_log, DateTime.UtcNow.AddDays(-40), null);

            _log.Info(orders.Count().ToString());
        }