示例#1
0
        private void GetOrdersByNextToken(AmazonOrdersRequestInfo requestInfo, string nextToken, ActionAccessType access, RequestsCounterData responseCounter, Func <List <AmazonOrderItem>, bool> func)
        {
            var sellerId = requestInfo.MerchantId;

            var req = new ListOrdersByNextTokenRequest {
                NextToken    = nextToken,
                SellerId     = sellerId,
                MWSAuthToken = requestInfo.MWSAuthToken
            };
            var response = AmazonWaitBeforeRetryHelper.DoServiceAction(
                requestInfo.ErrorRetryingInfo,
                ListOrdersTrapForThrottling,
                "ListOrdersByNextToken",
                access,
                responseCounter,
                () => _Service.ListOrdersByNextToken(req));

            if (response != null && response.IsSetListOrdersByNextTokenResult())
            {
                var result = response.ListOrdersByNextTokenResult;
                if (result.IsSetOrders())
                {
                    var ordersList = ParseOrdersInfo(result.Orders, sellerId, access, requestInfo.CustomerId);
                    func(ordersList);
                }

                if (result.IsSetNextToken())
                {
                    GetOrdersByNextToken(requestInfo, result.NextToken, access, responseCounter, func);
                }
            }
        }
示例#2
0
        private AmazonOrdersList GetUserOrders(AmazonOrdersRequestInfo amazonRequestInfo, ActionAccessType access)
        {
            const string getFlatFileOrdersDataRequestStr = "_GET_FLAT_FILE_ORDERS_DATA_";

            var reportRequestList = new RequestsListInfo(amazonRequestInfo, "GetUserOrders", access /*timeout: 3 hours*/, amazonRequestInfo.ErrorRetryingInfo);

            reportRequestList.AddRequest(getFlatFileOrdersDataRequestStr);

            RequestAndWait(reportRequestList);

            return(ParseOrdersResult(getFlatFileOrdersDataRequestStr, reportRequestList));
        }
示例#3
0
        private static List <OrderItemTwo> GetOrders(int umi, ElapsedTimeInfo elapsedTimeInfo, AmazonServiceConnectionInfo _ConnectionInfo, int days, bool useReporting)
        {
            var session = ObjectFactory.GetInstance <ISession>();

            var marketplace = session.Get <MP_CustomerMarketPlace>(umi);

            var securityInfo = Serialized.Deserialize <AmazonSecurityInfo>(marketplace.SecurityData);

            var endDate   = DateTime.UtcNow;
            var startDate = endDate.AddDays(-days);

            var errorRetryingInfo = new ErrorRetryingInfo((bool)CurrentValues.Instance.AmazonEnableRetrying, CurrentValues.Instance.AmazonMinorTimeoutInSeconds, CurrentValues.Instance.AmazonUseLastTimeOut);

            errorRetryingInfo.Info    = new ErrorRetryingItemInfo[2];
            errorRetryingInfo.Info[0] = new ErrorRetryingItemInfo(CurrentValues.Instance.AmazonIterationSettings1Index, CurrentValues.Instance.AmazonIterationSettings1CountRequestsExpectError, CurrentValues.Instance.AmazonIterationSettings1TimeOutAfterRetryingExpiredInMinutes);
            errorRetryingInfo.Info[1] = new ErrorRetryingItemInfo(CurrentValues.Instance.AmazonIterationSettings2Index, CurrentValues.Instance.AmazonIterationSettings2CountRequestsExpectError, CurrentValues.Instance.AmazonIterationSettings2TimeOutAfterRetryingExpiredInMinutes);

            var amazonOrdersRequestInfo = new AmazonOrdersRequestInfo
            {
                StartDate         = startDate,
                EndDate           = endDate,
                MarketplaceId     = securityInfo.MarketplaceId,
                MerchantId        = securityInfo.MerchantId,
                ErrorRetryingInfo = errorRetryingInfo,
            };

            List <OrderItemTwo> orders;

            if (useReporting)
            {
                var configurator = AmazonServiceConfigurationFactory.CreateServiceReportsConfigurator(_ConnectionInfo);

                orders = ElapsedTimeHelper.CalculateAndStoreElapsedTimeForCallInSeconds(
                    elapsedTimeInfo, umi,
                    ElapsedDataMemberType.RetrieveDataFromExternalService,
                    () => AmazonServiceReports.GetUserOrders(configurator, amazonOrdersRequestInfo, ActionAccessType.Full))
                         .Select(OrderItemTwo.FromOrderItem)
                         .ToList();
            }
            else
            {
                var ordersList = ElapsedTimeHelper.CalculateAndStoreElapsedTimeForCallInSeconds(elapsedTimeInfo, umi,
                                                                                                ElapsedDataMemberType.RetrieveDataFromExternalService,
                                                                                                () => AmazonServiceHelper.GetListOrders(_ConnectionInfo, amazonOrdersRequestInfo, ActionAccessType.Full, null));

                //todo make it work again
                orders = new List <OrderItemTwo>();
            }

            return(orders);
        }
示例#4
0
        private RequestsCounterData GetListOrders(AmazonOrdersRequestInfo requestInfo, ActionAccessType access, Func <List <AmazonOrderItem>, bool> func)
        {
            var request = new ListOrdersRequest {
                MarketplaceId = requestInfo.MarketplaceId,
                SellerId      = requestInfo.MerchantId,
                MWSAuthToken  = requestInfo.MWSAuthToken
            };

            if (requestInfo.StartDate.HasValue)
            {
                request.CreatedAfter = requestInfo.StartDate.Value.ToUniversalTime();
            }
            var responseCounter = new RequestsCounterData();
            var response        = AmazonWaitBeforeRetryHelper.DoServiceAction(
                requestInfo.ErrorRetryingInfo,
                ListOrdersTrapForThrottling,
                "ListOrders",
                access,
                responseCounter,
                () => _Service.ListOrders(request));

            if (response == null || response.ListOrdersResult == null || !response.IsSetListOrdersResult())
            {
                return(null);
            }

            var result = response.ListOrdersResult;

            if (result.IsSetOrders())
            {
                var ordersList = ParseOrdersInfo(result.Orders, request.SellerId, access, requestInfo.CustomerId);
                func(ordersList);
            }

            if (result.IsSetNextToken())
            {
                GetOrdersByNextToken(requestInfo, result.NextToken, access, responseCounter, func);
            }

            return(responseCounter);
        }
示例#5
0
        public static RequestsCounterData GetListOrders(IAmazonServiceOrdersConfigurator configurator, AmazonOrdersRequestInfo requestInfo, ActionAccessType access, Func <List <AmazonOrderItem>, bool> func)
        {
            var service = configurator.AmazonService;

            WriteToLog(string.Format("GetListOrders - SellerId: {0}, CreatedAfter (UTC) {1}, amazon mps id {2}, customer id {3} ", requestInfo.MerchantId, requestInfo.StartDate, requestInfo.GetMarketPlacesString(), requestInfo.CustomerId));

            return(new AmazonServiceOrders(service).GetListOrders(requestInfo, access, func));
        }
示例#6
0
        private UpdateActionResultInfo CustomerMarketplaceUpdateAction(
            IDatabaseCustomerMarketPlace databaseCustomerMarketPlace,
            AmazonSecurityInfo securityInfo,
            ActionAccessType access,
            MP_CustomerMarketplaceUpdatingHistory historyRecord
            )
        {
            // save data to order table
            //var webServiceConfigurator = CreateServiceReportsConfigurator(connectionInfo);
            var elapsedTimeInfo = new ElapsedTimeInfo();

            DateTime?startDate = ElapsedTimeHelper.CalculateAndStoreElapsedTimeForCallInSeconds(
                elapsedTimeInfo,
                databaseCustomerMarketPlace.Id,
                ElapsedDataMemberType.RetrieveDataFromDatabase,
                () => Helper.GetLastAmazonOrderDate(databaseCustomerMarketPlace)
                );

            var now = DateTime.UtcNow;

            if (!startDate.HasValue)
            {
                startDate = now.AddYears(-1);
                // We want data since the 1st of the month.
                startDate = startDate.Value.AddDays(-startDate.Value.Day).AddDays(1).Date;
            }             // if

            var fromDate = startDate.Value;
            var toDate   = now;

            var amazonOrdersRequestInfo = new AmazonOrdersRequestInfo {
                StartDate         = fromDate,
                EndDate           = toDate,
                MarketplaceId     = securityInfo.MarketplaceId,
                MerchantId        = securityInfo.MerchantId,
                ErrorRetryingInfo = this.amazonSettings,
                CustomerId        = databaseCustomerMarketPlace.Customer.Id,
                MWSAuthToken      = securityInfo.MWSAuthToken
            };

            DateTime submittedDate = now;

            log.InfoFormat(
                "Fetching Amazon orders for customer: {0} marketplace: {1}",
                databaseCustomerMarketPlace.Customer.Id,
                databaseCustomerMarketPlace.Id
                );

            MP_AmazonOrder amazonOrder = null;

            RequestsCounterData requestsCounter = ElapsedTimeHelper.CalculateAndStoreElapsedTimeForCallInSeconds(
                elapsedTimeInfo,
                databaseCustomerMarketPlace.Id,
                ElapsedDataMemberType.RetrieveDataFromExternalService,
                () => AmazonServiceHelper.GetListOrders(this.connectionInfo, amazonOrdersRequestInfo, access, data => {
                amazonOrder = Helper.StoreAmazonOrdersData(databaseCustomerMarketPlace, data, historyRecord, amazonOrder);
                return(true);
            })
                );

            var allOrders = ElapsedTimeHelper.CalculateAndStoreElapsedTimeForCallInSeconds(
                elapsedTimeInfo,
                databaseCustomerMarketPlace.Id,
                ElapsedDataMemberType.RetrieveDataFromDatabase,
                () => Helper.GetAllAmazonOrdersData(submittedDate, databaseCustomerMarketPlace)
                );

            allOrders.RequestsCounter = requestsCounter;

            if (allOrders.Count > 0)
            {
                var bestSaledOrderItemList = AnalyseOrder(allOrders).ToList();

                if (bestSaledOrderItemList.Any())
                {
                    foreach (var orderItem2 in bestSaledOrderItemList)
                    {
                        var orderItems = GetOrderItems(
                            securityInfo,
                            access,
                            orderItem2,
                            elapsedTimeInfo,
                            allOrders,
                            databaseCustomerMarketPlace.Id
                            );

                        orderItem2.OrderedItemsList = orderItems;

                        if (orderItems != null)
                        {
                            foreach (var orderItem in orderItems)
                            {
                                orderItem.Categories = GetAndSaveAmazonProcuctCategoryByProductSellerSku(
                                    databaseCustomerMarketPlace,
                                    securityInfo,
                                    orderItem.SellerSKU,
                                    access, allOrders.RequestsCounter,
                                    elapsedTimeInfo
                                    );
                            }     // for each
                        }         // if
                    }             // for each
                }                 // if

                ElapsedTimeHelper.CalculateAndStoreElapsedTimeForCallInSeconds(
                    elapsedTimeInfo,
                    databaseCustomerMarketPlace.Id,
                    ElapsedDataMemberType.StoreDataToDatabase,
                    () => Helper.StoreAmazonOrdersDetailsData(databaseCustomerMarketPlace, bestSaledOrderItemList)
                    );
            }             // if

            return(new UpdateActionResultInfo {
                Name = UpdateActionResultType.OrdersCount,
                Value = (object)allOrders.Count,
                RequestsCounter = allOrders.RequestsCounter,
                ElapsedTime = elapsedTimeInfo
            });
        }
示例#7
0
        public static RequestsCounterData GetListOrders(AmazonServiceConnectionInfo connectionInfo, AmazonOrdersRequestInfo requestInfo, ActionAccessType access, Func <List <AmazonOrderItem>, bool> func)
        {
            var configurator = AmazonServiceConfigurationFactory.CreateServiceOrdersConfigurator(connectionInfo);

            return(AmazonServiceOrders.GetListOrders(configurator, requestInfo, access, func));
        }
示例#8
0
        public static AmazonOrdersList GetReportOrders(AmazonServiceConnectionInfo connectionInfo, AmazonOrdersRequestInfo requestInfo, ActionAccessType access)
        {
            var configurator = AmazonServiceConfigurationFactory.CreateServiceReportsConfigurator(connectionInfo);

            return(AmazonServiceReports.GetUserOrders(configurator, requestInfo, access));
        }
示例#9
0
        public static AmazonOrdersList GetUserOrders(IAmazonServiceReportsConfigurator configurator, AmazonOrdersRequestInfo requestInfo, ActionAccessType access)
        {
            var service = configurator.AmazonService;

            var data = new AmazonServiceReports(service);

            return(data.GetUserOrders(requestInfo, access));
        }