public void SubmitProductEndItemFeeds(List <ItemFeed> itemFeeds, string submittedBy) { // let's take out the items which have no item id itemFeeds.RemoveAll(x => string.IsNullOrEmpty(x.ItemId)); // determine if there's product feed to post if (!itemFeeds.Any()) { _logger.LogWarning(LogEntryType.eBayEndListing, "No eBay products for end listing."); return; } // set the log file name _context.ApiLogManager.ApiLoggerList.Add(new FileLogger(string.Format(_logDirectory, MethodBase.GetCurrentMethod().Name), false, true, true)); // we can specify up to 10 listing to end in single request var totalBatches = Math.Ceiling(itemFeeds.Count / 10.0); var failedBatches = new List <ItemFeed>(); for (var i = 0; i < totalBatches; i++) { // send product end listing by batches var batchedProducts = itemFeeds.Skip(i * 10).Take(10).ToList(); var itemRequestList = new EndItemRequestContainerTypeCollection(); try { foreach (var product in batchedProducts) { var itemRequest = new EndItemRequestContainerType { MessageID = product.EisSKU, ItemID = product.ItemId, EndingReason = EndReasonCodeType.NotAvailable, EndingReasonSpecified = true, }; itemRequestList.Add(itemRequest); } // create the api call and send the request var apiCall = new EndItemsCall(_context); var response = apiCall.EndItems(itemRequestList); // update the product eBay' ItemId to null _logger.SeteBayItemIdToNull(batchedProducts); } catch (Exception ex) { var description = string.Format("Batch: {0}/{1} - Error in submitting END_ITEM feed. \nError Message: {2} \nRequested by: {3}", i + 1, totalBatches, EisHelper.GetExceptionMessage(ex), submittedBy); _logger.LogError(LogEntryType.eBayEndListing, description, ex.StackTrace); Console.WriteLine(description); // add the batched items to the list for resubmission 1 by 1 failedBatches.AddRange(batchedProducts); } } if (failedBatches.Any()) { _logger.LogInfo(LogEntryType.eBayEndListing, string.Format("Starting sending END_ITEM feed for failed batches. Count: {0}", failedBatches.Count)); // iterate and send each item foreach (var item in failedBatches) { SubmitSingleProductEndItem(item, submittedBy); } _logger.LogInfo(LogEntryType.eBayEndListing, string.Format("Resubmission for {0} failed items for END_ITEM feed has been completed.", failedBatches.Count())); } else { _logger.LogInfo(LogEntryType.eBayEndListing, string.Format("Successfully posted product END_ITEM feed for {0} - {1} product items. \nRequested by: {2}", ChannelName, itemFeeds.Count, submittedBy)); } }
private void EndActiveAuctions(IEnumerable <Article> articles) { try { GetSellerListRequestType request = new GetSellerListRequestType(); request.Version = "0.1"; request.GranularityLevelSpecified = true; request.GranularityLevel = GranularityLevelCodeType.Coarse; // Setting the date-range filter. This call required either EndTimeFrom & EndTimeTo pair OR StartTimeFrom & StartTimeTo pair // as a required input parameter. request.EndTimeFromSpecified = true; request.EndTimeFrom = DateTime.Now.ToUniversalTime(); request.EndTimeToSpecified = true; request.EndTimeTo = DateTime.Now.AddDays(14).ToUniversalTime(); // Setting the Pagination which is a required input parameter for GetSellerList call PaginationType pagination = new PaginationType(); pagination.EntriesPerPageSpecified = true; pagination.EntriesPerPage = 200; pagination.PageNumberSpecified = true; pagination.PageNumber = 1; request.Pagination = pagination; GetSellerListResponseType response = new GetSellerListResponseType(); GetSellerListCall listApiCall = new GetSellerListCall(apiContext); response = (GetSellerListResponseType)listApiCall.ExecuteRequest(request); if (response.Ack == AckCodeType.Success) { EndItemsCall endApiCall = new EndItemsCall(apiContext); EndItemRequestContainerTypeCollection endItems = new EndItemRequestContainerTypeCollection(); foreach (ItemType item in response.ItemArray) { EndItemRequestContainerType endItem = new EndItemRequestContainerType(); endItem.EndingReason = EndReasonCodeType.NotAvailable; endItem.EndingReasonSpecified = true; endItem.MessageID = item.ItemID; endItem.ItemID = item.ItemID; endItems.Add(endItem); } if (endItems.Count > 0) { EndItemResponseContainerTypeCollection endResponse = endApiCall.EndItems(endItems); String errMsg = String.Empty; foreach (EndItemResponseContainerType item in endResponse) { errMsg += EvaluateErrorMessages(item.Errors); } if (errMsg != String.Empty) { Assert.Fail(errMsg); } } } else { String errMsg = EvaluateErrorMessages(response.Errors); if (errMsg != String.Empty) { Assert.Fail(errMsg); } } } catch (Exception ex) { Assert.Fail(ex.Message); } }