/// <summary> /// Fetches all orders created in the given time period and processes them locally. /// <param name="startTime">The starting time period of orders to fetch.</param> /// <param name="endTime">The ending time period of orders to fetch.</param> public void FetchOrders(DateTime startTime, DateTime endTime) { ListOrdersRequest request = new ListOrdersRequest(); request.CreatedAfter = startTime; if (endTime != DateTime.MinValue) { request.CreatedBefore = endTime; } request.SellerId = mwsSellerId; request.MarketplaceId = new MarketplaceIdList(); request.MarketplaceId.Id = new List <string>(); foreach (string marketplaceId in mwsMarketplaceIdList) { request.MarketplaceId.Id.Add(marketplaceId); } List <Order> orderList = new List <Order>(); ListOrdersResponse response = null; OrderFetcher.InvokeRetriable(LIST_ORDERS_DEFAULT_THROTTLE_LIMIT, delegate() { response = mwsService.ListOrders(request); ProcessOrders(response.ListOrdersResult.Orders.Order); }); String nextTokenString = response.ListOrdersResult.NextToken; while (!string.IsNullOrEmpty(nextTokenString)) { // If NextToken is set, continue looping through the orders. ListOrdersByNextTokenRequest nextRequest = new ListOrdersByNextTokenRequest(); nextRequest.NextToken = nextTokenString; nextRequest.SellerId = mwsSellerId; ListOrdersByNextTokenResponse nextResponse = null; OrderFetcher.InvokeRetriable(LIST_ORDERS_DEFAULT_THROTTLE_LIMIT, delegate() { nextResponse = mwsService.ListOrdersByNextToken(nextRequest); ProcessOrders(nextResponse.ListOrdersByNextTokenResult.Orders.Order); }); nextTokenString = nextResponse.ListOrdersByNextTokenResult.NextToken; } }
/// <summary> /// Fetches the OrderItems for the specified orderId. /// </summary> public void FetchOrderItems(string orderId, ProcessOrderItemHandler handler) { if (handler == null) { throw new ArgumentNullException("handler"); } ListOrderItemsRequest request = new ListOrderItemsRequest(); request.SellerId = mwsSellerId; request.AmazonOrderId = orderId; ListOrderItemsResponse response = null; OrderFetcher.InvokeRetriable(LIST_ORDER_ITEMS_DEFAULT_THROTTLE_LIMIT, delegate() { response = mwsService.ListOrderItems(request); foreach (OrderItem orderItem in response.ListOrderItemsResult.OrderItems.OrderItem) { handler(orderItem); } }); String nextTokenString = response.ListOrderItemsResult.NextToken; while (!string.IsNullOrEmpty(nextTokenString)) { // If NextToken is set, continue looping through the orders. ListOrderItemsByNextTokenRequest nextRequest = new ListOrderItemsByNextTokenRequest(); nextRequest.NextToken = nextTokenString; nextRequest.SellerId = mwsSellerId; ListOrderItemsByNextTokenResponse nextResponse = null; OrderFetcher.InvokeRetriable(LIST_ORDER_ITEMS_DEFAULT_THROTTLE_LIMIT, delegate() { nextResponse = mwsService.ListOrderItemsByNextToken(nextRequest); foreach (OrderItem orderItem in nextResponse.ListOrderItemsByNextTokenResult.OrderItems.OrderItem) { handler(orderItem); } }); nextTokenString = nextResponse.ListOrderItemsByNextTokenResult.NextToken; } }
/// <summary> /// Sample code to invoke the OrderFetcher to retrieve Orders and OrderItems. /// </summary> /// <param name="service">MarketplaceWebServiceOrders object.</param> public static void InvokeOrderFetcherSample(MarketplaceWebServiceOrders service, string sellerId, string[] marketplaceIdList) { OrderFetcher fetcher = new OrderFetcher(service, sellerId, marketplaceIdList); // Process each order as it comes in fetcher.ProcessOrder += delegate(Order order) { Console.WriteLine(order.ToString()); // Fetch the order items in each order fetcher.FetchOrderItems(order.AmazonOrderId, delegate(OrderItem item) { // Process order item here. Console.WriteLine("\t" + item.ToString()); }); Console.WriteLine("================================================="); Console.WriteLine(); }; // Fetch all orders from 1 day ago fetcher.FetchOrders(DateTime.Now.Subtract(TimeSpan.FromDays(1))); }