Esempio n. 1
0
 public Product EbayGet( string id)
 {
     FindingServicePortTypeClient client = new FindingServicePortTypeClient();
     MessageHeader header = MessageHeader.CreateHeader("CustomHeader", "", "");
     using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
     {
         OperationContext.Current.OutgoingMessageHeaders.Add(header);
         HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
         httpRequestProperty.Headers.Add("X-EBAY-SOA-SECURITY-APPNAME", "XeniaK-comp-PRD-4b4e51644-6f63ec03");
         httpRequestProperty.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "findItemsByKeywords");
         httpRequestProperty.Headers.Add("X-EBAY-SOA-GLOBAL-ID", "EBAY-US");
         OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
         FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest();
         request.keywords = id;
         FindItemsByKeywordsResponse response = client.findItemsByKeywords(request);
         if (response.searchResult.count>0  )
         {
             var pr = new Product();
             pr.Title = response.searchResult.item[0].title;
             pr.Url = response.searchResult.item[0].viewItemURL;
             pr.Price = response.searchResult.item[0].sellingStatus.currentPrice.Value.ToString();
             pr.Currentcy = response.searchResult.item[0].sellingStatus.currentPrice.currencyId;
             pr.Id = response.searchResult.item[0].itemId;
             pr.Imageurl = response.searchResult.item[0].galleryURL;
             pr.Name = "Ebay";
             data = pr;
         }
         return data;
     }
 }
Esempio n. 2
0
 public static void New()
 {
     using (FindingServicePortTypeClient client = new FindingServicePortTypeClient())
     {
         MessageHeader header = MessageHeader.CreateHeader("CustomHeader", "", "");
         using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
         {
             OperationContext.Current.OutgoingMessageHeaders.Add(header);
             HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
             //Create Header
             httpRequestProperty.Headers.Add("X-EBAY-SOA-SECURITY-APPNAME", "AjaiRupa-Test-PRD-a43252cae-252f99e0");
             httpRequestProperty.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "findItemsByProduct");
             httpRequestProperty.Headers.Add("X-EBAY-SOA-GLOBAL-ID", "EBAY-US");
             OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
             //Construct Product Request
             FindItemsByProductRequest request = new FindItemsByProductRequest();
             var prod = new ProductId();
             request.productId = prod;
             prod.type         = "UPC";
             prod.Value        = Number.UpcNumber;
             FindItemsByProductResponse response = client.findItemsByProduct(request);
             //Error Handling
             if (response.ack != AckValue.Success)
             {
                 Console.WriteLine(response.errorMessage[0].message + "\nPress escape to exit");
                 if (Console.ReadKey().Key.ToString() != "Escape")
                 {
                     UserInput.Start();
                     Request.New();
                 }
             }
             else if (response.searchResult.item == null)
             {
                 Console.WriteLine("No eBay item available for UPC Number " + Number.UpcNumber +
                                   "\nPress enter to try another UPC");
                 if (Console.ReadKey().Key.ToString() == "Enter")
                 {
                     UserInput.Start();
                     Request.New();
                 }
             }
             else
             {
                 foreach (var item in response.searchResult.item)
                 {
                     Console.WriteLine("Item Title: " + item.title);
                     Console.WriteLine("Item Price: $" + item.sellingStatus.convertedCurrentPrice.Value + "\n");
                 }
                 Console.WriteLine("Press enter to perform another search\n");
                 if (Console.ReadKey().Key.ToString() == "Enter")
                 {
                     UserInput.Start();
                     Request.New();
                 }
             }
         }
     }
 }
Esempio n. 3
0
        public IEbayFinder Configure(Action<ClientConfig> config)
        {
            // Configure
            config(_clientConfig);

            // Create a service client
            _client = FindingServiceClientFactory.getServiceClient(_clientConfig);

            return this;
        }
Esempio n. 4
0
 public EbayClient()
 {
     m_config = new ClientConfig();
     m_config.ApplicationId = appID;
     m_config.EndPointAddress = findingServerAddress;
     m_client = FindingServiceClientFactory.getServiceClient(m_config);
     m_api = new ApiContext();
     m_api = AppSettingHelper.GetApiContext();
     m_cats = new tblCategory();
     db = new DataClasses1DataContext();
     m_log = new List<string> { };
 }
Esempio n. 5
0
        private void HandleRequest(FindingServicePortTypeClient client, DataLayer dal, FindItemsByKeywordsRequest req, int priceSourceId)
        {
            try
            {
                log.Info($"Calling FindingAPI (keywords={req.keywords})");

                var response = client.findItemsByKeywords(req);

                // Build results for ItemPrice
                var result = new ItemPrice
                {
                    PriceSourceId = priceSourceId,
                    UpdateTime    = DateTime.Now
                };

                log.Info($"Found {response.searchResult.count} items");
                var items = response.searchResult.item;

                if (response.searchResult.count > 0)
                {
                    result.CCPaypalPrice = Convert.ToDecimal(items.Min(i => i.sellingStatus.currentPrice.Value));
                    result.MinPrice      = result.CCPaypalPrice;
                    result.MaxPrice      = Convert.ToDecimal(items.Max(i => i.sellingStatus.currentPrice.Value));

                    result.ItemUrl = items.First().viewItemURL;

                    // Update result
                    dal.UpdateItemPrice(result, false, null);
                }
                else
                {
                    // What do we do when there is no result
                    dal.UpdatePriceSourceError(priceSourceId, Strings.NoListings);
                }
            }
            catch (Exception ex)
            {
                // Update PriceSource with last error
                dal.UpdatePriceSourceError(priceSourceId, ex.Message);
            }
        }
Esempio n. 6
0
        public IEnumerable <Product> GetEbay(string keywords)
        {
            FindingServicePortTypeClient client = new FindingServicePortTypeClient();
            MessageHeader header = MessageHeader.CreateHeader("CustomHeader", "", "");

            using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(header);
                HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
                httpRequestProperty.Headers.Add("X-EBAY-SOA-SECURITY-APPNAME", "XeniaK-comp-PRD-4b4e51644-6f63ec03");
                httpRequestProperty.Headers.Add("X-EBAY-SOA-OPERATION-NAME", "findItemsByKeywords");
                httpRequestProperty.Headers.Add("X-EBAY-SOA-GLOBAL-ID", "EBAY-US");
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;

                //FindItemsByProductRequest request2 = new FindItemsByProductRequest();
                //request2.productId
                FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest();
                request.keywords = keywords;
                FindItemsByKeywordsResponse response = client.findItemsByKeywords(request);
                data.Clear();
                if (response.searchResult != null && response.searchResult.count > 0)
                {
                    foreach (var item in response.searchResult.item)
                    {
                        var pr = new Product();
                        pr.Title          = item.title;
                        pr.Url            = item.viewItemURL;
                        pr.Price          = item.sellingStatus.currentPrice.Value.ToString();
                        pr.Currentcy      = item.sellingStatus.currentPrice.currencyId;
                        pr.Id             = item.itemId;
                        pr.Imageurl       = item.galleryURL;
                        pr.Name           = "Ebay";
                        pr.detailsenabled = true;
                        data.Add(pr);
                    }
                }
                return(data);
            }
        }
        private void ProcessEbayLoad(ILogger logger, string userId)
        {
            logger.Write(String.Format("Starting the ebay load for user Id = {0}", userId),
                         LoggerCategories.Information, 0, 0,
                         TraceEventType.Information,
                         startEbayLoadMessage,
                         new Dictionary <string, object>());

            using (
                var stagingEbayLoadService =
                    UnityConfig.GetConfiguredContainer().Resolve <IStagingEbayLoadService>())
            {
                logger.Write(String.Format("ebay load service instantiated for user Id = {0}", userId),
                             LoggerCategories.Information, 0, 0,
                             TraceEventType.Information,
                             startEbayLoadMessage,
                             new Dictionary <string, object>());

                #region 'Check if an ebay load can run'
                //Check if a new ebay batch load can run (valid only where there is no ebay load currently running)
                if (!stagingEbayLoadService.CanExecuteEbayLoad())
                {
                    //Cannot execute a new ebay batch load
                    //Log the error
                    logger.Write(EbayLoadProcessingFault.FaultMessageBatchAlreadyRunning,
                                 LoggerCategories.Error, 0, 0,
                                 TraceEventType.Error,
                                 startEbayLoadMessage,
                                 new Dictionary <string, object>());
                    //User does not have an administrator role
                    throw new FaultException <EbayLoadProcessingFault>(
                              new EbayLoadProcessingFault {
                        ErrorDetails = EbayLoadProcessingFault.FaultCodeBatchAlreadyRunning, ErrorMessage = EbayLoadProcessingFault.FaultMessageBatchAlreadyRunning, Result = false
                    },
                              new FaultReason(new FaultReasonText(EbayLoadProcessingFault.FaultMessageBatchAlreadyRunning)), new FaultCode(EbayLoadProcessingFault.FaultCodeBatchAlreadyRunning));
                }
                #endregion 'Check if an ebay load can run'

                //Create a new ebay load batch record
                StagingEbayBatchImport stagingEbayBatchImport = stagingEbayLoadService.CreateStagingEbayLoadBatch(userId);
                //Check if a ebay load batch has been created
                if (stagingEbayBatchImport == null)
                {
                    logger.Write(EbayLoadProcessingFault.FaultMessageBatchWasNotCreated,
                                 LoggerCategories.Error, 0, 0,
                                 TraceEventType.Critical,
                                 startEbayLoadMessage,
                                 new Dictionary <string, object>());
                    //User does not have an administrator role
                    throw new FaultException <EbayLoadProcessingFault>(
                              new EbayLoadProcessingFault {
                        ErrorDetails = EbayLoadProcessingFault.FaultCodeBatchWasNotCreated, ErrorMessage = EbayLoadProcessingFault.FaultMessageBatchWasNotCreated, Result = false
                    },
                              new FaultReason(new FaultReasonText(EbayLoadProcessingFault.FaultMessageBatchWasNotCreated)), new FaultCode(EbayLoadProcessingFault.FaultCodeBatchWasNotCreated));
                }
                //Set ebay batch load records default values
                SetBatchDefaults(stagingEbayBatchImport);
                //Update the ebay batch load record with respective data
                stagingEbayLoadService.UpdateStagingEbayLoadBatch(stagingEbayBatchImport, true);

                //ebay Finding API client configuration
                var config = new ClientConfig
                {
                    // Finding API service end-point configuration
                    EndPointAddress = ConfigurationManager.AppSettings["EbayFindingAPIEndPointAddress"],
                    // eBay developer account AppID
                    ApplicationId = ConfigurationManager.AppSettings["EbayFindindAPIApplicationId"],
                    // timeout value for this call
                    HttpTimeout = 1500000 //25 minutes
                };

                //ebay Finding API client service
                FindingServicePortTypeClient findingServicePortTypeClient = FindingServiceClientFactory.getServiceClient(config);

                //ebay finding API request
                var request = new FindItemsByKeywordsRequest
                {
                    keywords = ConfigurationManager.AppSettings["EbayFindingApiKeywords"]
                };

                #region 'ebay Finding API Request Filters'

                var itemFilters = new List <ItemFilter>
                {
                    new ItemFilter
                    {
                        name  = ItemFilterType.AvailableTo,
                        value = new[] { ConfigurationManager.AppSettings["EbayAvailableToItemFilter"] }
                    }
                };

                //Get the ebay ISO8601 datetime format from web.config settings
                string iso8601DatetimeFormat = ConfigurationManager.AppSettings["EbayISO8601DateTimeFormat"];

                //Get the start time filter from database for when this ebay batch load was run last
                string ebayLoadStartTimeFromConfiguration = stagingEbayLoadService.GetEbayLoadStartTimeFrom();
                if (!String.IsNullOrWhiteSpace(ebayLoadStartTimeFromConfiguration))
                {
                    itemFilters.Add(new ItemFilter
                    {
                        name  = ItemFilterType.StartTimeFrom,
                        value =
                            new[]
                        {
                            //TODO: have to remove this filter below
                            (Convert.ToDateTime(ebayLoadStartTimeFromConfiguration)).AddMinutes(-20).ToString(iso8601DatetimeFormat)
                            //DateTime.Now.AddDays(-1).AddMinutes(-20).ToString(iso8601DatetimeFormat)
                        }
                    });
                }
                request.itemFilter = itemFilters.ToArray();

                #endregion 'ebay Finding API Request Filters'

                //Call the Finding service's Find Items By Keyword method
                FindItemsByKeywordsResponse check = findingServicePortTypeClient.findItemsByKeywords(request);
                DateTime ebayCheckTime            = DateTime.UtcNow;

                if (check == null)
                {
                    logger.Write(EbayLoadProcessingFault.FaultMessageFindItemBykeywordResposeIsNull,
                                 LoggerCategories.Error, 1, 0,
                                 TraceEventType.Critical,
                                 startEbayLoadMessage,
                                 new Dictionary <string, object>());
                    //Find item response is ready
                    throw new FaultException <EbayLoadProcessingFault>(
                              new EbayLoadProcessingFault {
                        ErrorDetails = EbayLoadProcessingFault.FaultCodeFindItemBykeywordResposeIsNull, ErrorMessage = EbayLoadProcessingFault.FaultMessageFindItemBykeywordResposeIsNull, Result = false
                    },
                              new FaultReason(new FaultReasonText(EbayLoadProcessingFault.FaultMessageFindItemBykeywordResposeIsNull)), new FaultCode(EbayLoadProcessingFault.FaultCodeFindItemBykeywordResposeIsNull));
                }

                if (check.ack == AckValue.Failure || check.ack == AckValue.PartialFailure)
                {
                    logger.Write(EbayLoadProcessingFault.FaultMessageFindItemBykeywordReturnedFailure + "Failure details: " + check.errorMessage,
                                 LoggerCategories.Error, 1, 0,
                                 TraceEventType.Critical,
                                 startEbayLoadMessage,
                                 new Dictionary <string, object>());

                    //Find item response has a failure
                    throw new FaultException <EbayLoadProcessingFault>(
                              new EbayLoadProcessingFault {
                        ErrorDetails = EbayLoadProcessingFault.FaultCodeFindItemBykeywordReturnedFailure, ErrorMessage = EbayLoadProcessingFault.FaultMessageFindItemBykeywordReturnedFailure, Result = false
                    },
                              new FaultReason(new FaultReasonText(EbayLoadProcessingFault.FaultMessageFindItemBykeywordReturnedFailure)), new FaultCode(EbayLoadProcessingFault.FaultCodeFindItemBykeywordReturnedFailure));
                }

                int totalKeywordMatchedItems = check.paginationOutput.totalEntries;
                var totalPages = (int)Math.Ceiling(totalKeywordMatchedItems / 100.00);
                stagingEbayBatchImport.TotalKeywordMatched = totalKeywordMatchedItems;
                stagingEbayBatchImport.EbayVersion         = findingServicePortTypeClient.getVersion(new GetVersionRequest()).version;

                logger.Write(
                    String.Format(
                        "ebay Finding Service - findItemsByKeywords call (user id = {0}, batch id = {1}) for selected filters has Total={2} items,  Total Pages (ebay default 100 items each)={3}",
                        userId, stagingEbayBatchImport.EbayBatchImportId, totalKeywordMatchedItems, totalPages),
                    LoggerCategories.Information, 0, 0,
                    TraceEventType.Information,
                    startEbayLoadMessage,
                    new Dictionary <string, object>());

                for (int curPage = 1; curPage <= totalPages; curPage++)
                {
                    request.paginationInput = new PaginationInput
                    {
                        entriesPerPageSpecified = true,
                        entriesPerPage          = 100,
                        pageNumberSpecified     = true,
                        pageNumber = curPage,
                    };

                    FindItemsByKeywordsResponse response =
                        findingServicePortTypeClient.findItemsByKeywords(request);
                    if (response != null &&
                        (response.searchResult.item != null && response.searchResult.item.Length > 0))
                    {
                        IEnumerable <SearchItem> searchItems =
                            response.searchResult.item.Where(EBayGlobalIdUsStore).DistinctBy(i => i.itemId);
                        foreach (SearchItem ebaySearchItem in searchItems)
                        {
                            stagingEbayBatchImport.ToBeProcessed++;
                            StagingEbayItem stagingEbayItem;
                            if (stagingEbayLoadService.EbayItemExists(ebaySearchItem.itemId, out stagingEbayItem))
                            {
                                stagingEbayBatchImport.Duplicates++;
                                stagingEbayBatchImport.Failed++;

                                logger.Write(
                                    String.Format(
                                        "ebay Finding Service - item (ebay item id = {2}) already exists (user id = {0}, batch id = {1})",
                                        userId, stagingEbayBatchImport.EbayBatchImportId, ebaySearchItem.itemId),
                                    LoggerCategories.Warning, 0, 0,
                                    TraceEventType.Warning,
                                    startEbayLoadMessage,
                                    new Dictionary <string, object>());
                                continue;
                            }
                            if ((ebaySearchItem.listingInfo == null ||
                                 String.IsNullOrWhiteSpace(ebaySearchItem.listingInfo.listingType)))
                            {
                                stagingEbayBatchImport.NoListingType++;
                                stagingEbayBatchImport.Failed++;

                                logger.Write(
                                    String.Format(
                                        "ebay Finding Service - item (ebay item id = {2}) has no listing type (user id = {0}, batch id = {1})",
                                        userId, stagingEbayBatchImport.EbayBatchImportId, ebaySearchItem.itemId),
                                    LoggerCategories.Error, 0, 0,
                                    TraceEventType.Error,
                                    startEbayLoadMessage,
                                    new Dictionary <string, object>());
                                continue;
                            }

                            stagingEbayItem = CreateStagingEbayItem(stagingEbayLoadService, ebaySearchItem,
                                                                    stagingEbayBatchImport.EbayBatchImportId, ebayCheckTime, userId);
                            UpdateCounts(stagingEbayItem, stagingEbayBatchImport);
                        }
                    }
                    //Page processed log entry
                    logger.Write(
                        String.Format("Items page {2} completed (user id = {0}, batch id = {1})", userId,
                                      stagingEbayBatchImport.EbayBatchImportId, curPage),
                        LoggerCategories.Information, 0, 0,
                        TraceEventType.Information,
                        startEbayLoadMessage,
                        new Dictionary <string, object>());
                }

                stagingEbayLoadService.UpsertEbayLoadStartTimeFromConfiguration(ebayCheckTime);

                //Set ebay batch completion data
                stagingEbayBatchImport.CompletedOn = DateTime.Now;
                stagingEbayBatchImport.InProcess   = false;
                stagingEbayLoadService.UpdateStagingEbayLoadBatch(stagingEbayBatchImport, true);

                //Page processed log entry
                logger.Write(String.Format("ebay batch load completed (user id = {0}, batch id = {1}), Summary: TotalKeywordMatched={2}, ToBeProcessed={3}, Failed={4}, Duplicated={11}, Imported={5}, " +
                                           "Auctions={6}, AuctionsWithBIN={7}, Classified={8}, FixedPrice={9}, StoreInventory={10}",
                                           userId, stagingEbayBatchImport.EbayBatchImportId, stagingEbayBatchImport.TotalKeywordMatched, stagingEbayBatchImport.ToBeProcessed,
                                           stagingEbayBatchImport.Failed, stagingEbayBatchImport.Imported, stagingEbayBatchImport.Auctions, stagingEbayBatchImport.AuctionsWithBIN,
                                           stagingEbayBatchImport.Classified, stagingEbayBatchImport.FixedPrice, stagingEbayBatchImport.StoreInventory, stagingEbayBatchImport.Duplicates),
                             LoggerCategories.Information, 0, 0,
                             TraceEventType.Information,
                             startEbayLoadMessage,
                             new Dictionary <string, object>());
            }
        }
Esempio n. 8
0
        public ActionResult Index(string Id)
        {
            // create a eBay client
            config.GlobalId = "EBAY-IE"; //use Irish eBay website (www.eBay.ie)
            FindingServicePortTypeClient client = FindingServiceClientFactory.getServiceClient(config);

            ViewBag.Message = Id;

            SearchItem[] items = null;
            try
            {
                // Create request object
                FindItemsAdvancedRequest request = new FindItemsAdvancedRequest();

                //filter items so just "buy it now" items appear
                ItemFilter itemFilter1 = new ItemFilter();
                itemFilter1.name  = ItemFilterType.ListingType;
                itemFilter1.value = new string[] { "FixedPrice" };

                ItemFilter[] itemFilterArray = new ItemFilter[1];
                itemFilterArray[0] = itemFilter1;

                // Set request parameters
                request.keywords   = Id;
                request.itemFilter = itemFilterArray;
                request.sortOrder  = SortOrderType.PricePlusShippingLowest;
                //request.sortOrderSpecified = true;
                OutputSelectorType[] outputs = { OutputSelectorType.SellerInfo };
                request.outputSelector = outputs;


                PaginationInput PaginationInput = new PaginationInput();
                //PaginationInput.totalNumberOfPages = 5;
                PaginationInput.entriesPerPageSpecified = true;
                PaginationInput.entriesPerPage          = 100;
                PaginationInput.pageNumberSpecified     = true;
                PaginationInput.pageNumber = 10;
                request.paginationInput    = PaginationInput;

                // Call the api
                FindItemsAdvancedResponse response = client.findItemsAdvanced(request);

                // Show output
                if (response.searchResult != null && response.searchResult.item != null)
                {
                    items = response.searchResult.item;
                    ViewBag.noResultsMsg = "";
                    return(View(items));
                }
                else if (Id.Length == 0)
                {
                    ViewBag.noResultsMsg = "No item entered. Please enter an item to search and try again";
                }
                else if (response.searchResult == null || response.searchResult.item == null)
                {
                    ViewBag.noResultsMsg = "No Results. Please try another search";
                }
            }
            catch (Exception ex)
            {
                var errorText = ex.Message;
            }

            return(View());
        }