public void EndItems()
        {
            Assert.IsNotNull(TestData.itemIds);
            Assert.IsTrue(TestData.itemIds.Count > 0);

            EndItemsCall api = new EndItemsCall(this.apiContext);
            EndItemRequestContainerTypeCollection endItemsContainers = new EndItemRequestContainerTypeCollection();
            EndItemRequestContainerType           container;

            foreach (String itemID in TestData.itemIds)
            {
                container              = new EndItemRequestContainerType();
                container.ItemID       = itemID;
                container.EndingReason = EndReasonCodeType.LostOrBroken;
                container.MessageID    = Convert.ToString(endItemsContainers.Count + 1);
                endItemsContainers.Add(container);
            }
            api.EndItemRequestContainerList = endItemsContainers;
            api.Execute();

            //check whether the call is success.
            Assert.IsTrue(api.ApiResponse.Ack == AckCodeType.Success || api.ApiResponse.Ack == AckCodeType.Warning, "do not success!");
            Assert.IsNotNull(api.EndItemResponseContainerList);
            Assert.IsTrue(api.EndItemResponseContainerList.Count == TestData.itemIds.Count);
            TestData.itemIds = null;
        }
Example #2
0
        void AddItems()
        {
            try
            {
                ApiContext apiContext = GetApiContext();

                AddFixedPriceItemCall addApiCall  = new AddFixedPriceItemCall(apiContext);
                GetItemCall           getApiCall  = new GetItemCall(apiContext);
                GetSellerListCall     listApiCall = new GetSellerListCall(apiContext);
                EndItemsCall          endApiCall  = new EndItemsCall(apiContext);

                ModelDataContext context = new ModelDataContext();
                articles = (from current in context.Articles
                            orderby current.ArticleNumber
                            where current.AmountOnStock > 0
                            select current).Take(2);

                EndActiveAuctions(articles);

                System.Threading.Thread.Sleep(5000);

                foreach (Article article in articles)
                {
                    try
                    {
                        //create a new ItemType object corresponding to article-backend data with fix quantity of 99 pieces an add it
                        ItemType item = BuildItem(article);
                        addApiCall.AddFixedPriceItem(item);
                    }
                    catch (Exception ex)
                    {
                        Assert.Fail(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Example #3
0
        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));
            }
        }
Example #4
0
        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);
            }
        }