//"http://developer.ebay.com/webservices/Finding/latest/FindingService.wsdl"; public override SearchByQueryResponse Search(SearchByQueryRequest request) { try { EbayFindingAPIAdapter service = new EbayFindingAPIAdapter(); FindItemsByKeywordsRequest findItemsRequest = new FindItemsByKeywordsRequest(); service.Url = FindingServiceURL; findItemsRequest.keywords = request.SearchQuery; // Setting the pagination PaginationInput pagination = new PaginationInput(); pagination.entriesPerPageSpecified = true; pagination.entriesPerPage = 25; pagination.pageNumberSpecified = true; pagination.pageNumber = 1; findItemsRequest.paginationInput = pagination; // Creating response object FindItemsByKeywordsResponse response = service.findItemsByKeywords(findItemsRequest); var result = response.searchResult; return(new SearchByQueryResponse { IsSuccess = true, SearchResult = new DataObjects.ECommerce.SearchResult() }); } catch (Exception ex) { Console.WriteLine("* Error: " + ex.Message); return(new SearchByQueryResponse { IsSuccess = false }); } }
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; } }
public ActionResult Users(string Id) { FindItemsByKeywordsRequest req = new FindItemsByKeywordsRequest(); FindItemsByKeywordsResponse resp = new FindItemsByKeywordsResponse(); return(View()); }
static void Main(string[] args) { // Init log // This sample and the FindingKit use <a href="http://slf.codeplex.com/">Simple Logging Facade(SLF)</a>, // Here is a <a href="http://slf.codeplex.com/">good introdution</a> about SLF(for example, supported log levels, how to log to a file) LoggerService.SetLogger(new ConsoleLogger()); ILogger logger = LoggerService.GetLogger(); // Basic service call flow: // 1. Setup client configuration // 2. Create service client // 3. Create outbound request and setup request parameters // 4. Call the operation on the service client and receive inbound response // 5. Handle response accordingly // Handle exception accrodingly if any of the above steps goes wrong. try { ClientConfig config = new ClientConfig(); // Initialize service end-point configuration config.EndPointAddress = "http://svcs.ebay.com/services/search/FindingService/v1"; // set eBay developer account AppID config.ApplicationId = "YOUR APPID HERE"; // Create a service client FindingServicePortTypeClient client = FindingServiceClientFactory.getServiceClient(config); // Create request object FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest(); // Set request parameters request.keywords = "harry potter phoenix"; PaginationInput pi = new PaginationInput(); pi.entriesPerPage = 2; pi.entriesPerPageSpecified = true; request.paginationInput = pi; // Call the service FindItemsByKeywordsResponse response = client.findItemsByKeywords(request); // Show output logger.Info("Ack = " + response.ack); logger.Info("Find " + response.searchResult.count + " items."); SearchItem[] items = response.searchResult.item; for (int i = 0; i < items.Length; i++) { logger.Info(items[i].title); } } catch (Exception ex) { // Handle exception if any logger.Error(ex); } Console.WriteLine("Press any key to close the program."); Console.ReadKey(); }
private void buildRequest(string i_SearchKeyword) { Request = new FindItemsByKeywordsRequest { //affiliate attribute //affiliate = new Affiliate { networkId = "9", trackingId = "5338260688" }, // Sorting properties sortOrderSpecified = true, sortOrder = SortOrderType.BestMatch, // Setting the required property values itemFilter = ItemFiltering, keywords = i_SearchKeyword }; Request.paginationInput = PagingManager; }
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); } }
public FindItemsByKeywordsResponse SearchItems(SellerItem sellerItem, int pageSize, int pageNumber) { // Creating an object to the BestMatchService class CustomFindingService service = new CustomFindingService(); service.Url = ConfigurationManager.AppSettings["FindingService"]; // Creating request object for FindBestMatchItemDetailsByKeywords API FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest(); // Setting the required property values request.keywords = sellerItem.Keywords; // Setting the pagination PaginationInput pagination = new PaginationInput(); pagination.entriesPerPageSpecified = true; pagination.entriesPerPage = pageSize; pagination.pageNumberSpecified = true; pagination.pageNumber = pageNumber; request.paginationInput = pagination; ItemFilter filter; List<ItemFilter> filters = new List<ItemFilter>(); /*ListingType*/ string ListingTypeFilter = null; if (sellerItem.Is_Fixed_Price == true) ListingTypeFilter = "FixedPrice"; if (sellerItem.Is_Auctions == true) ListingTypeFilter += ",AuctionWithBIN"; if (ListingTypeFilter != null) { filter = new ItemFilter(); filter.name = ItemFilterType.ListingType; filter.value = ListingTypeFilter.Split(','); filters.Add(filter); } /*ReturnsAcceptedOnly*/ if (sellerItem.Is_Returns_Accepted == true) { filter = new ItemFilter(); filter.name = ItemFilterType.ReturnsAcceptedOnly; filter.value = new string[] { "true" }; filters.Add(filter); } /*LocatedIn*/ //if (sellerItem.Is_Location_AU == true) //{ // filter = new ItemFilter(); // filter.name = ItemFilterType.LocatedIn; // filter.value = new string[] { "AU" }; // filters.Add(filter); //} if (!string.IsNullOrEmpty(sellerItem.LocatedIn)) { filter = new ItemFilter(); filter.name = ItemFilterType.LocatedIn; filter.value = new string[] { sellerItem.LocatedIn.ToUpper() }; filters.Add(filter); } /*HideDuplicateItems*/ if (sellerItem.Is_Hide_Duplicates == true) { filter = new ItemFilter(); filter.name = ItemFilterType.HideDuplicateItems; filter.value = new string[] { "true" }; filters.Add(filter); } /*TopRatedSellerOnly*/ if (sellerItem.Is_Hide_Duplicates == true) { filter = new ItemFilter(); filter.name = ItemFilterType.TopRatedSellerOnly; filter.value = new string[] {"true"}; filters.Add(filter); } else { /*Specify one or more seller names. Search results will include items from the specified sellers only. The Seller item filter cannot be used together with either the ExcludeSeller or TopRatedSellerOnly item filters. */ if (!string.IsNullOrEmpty(sellerItem.Inclued_Sellers)) { filter = new ItemFilter(); filter.name = ItemFilterType.Seller; filter.value = sellerItem.Inclued_Sellers.Split(','); filters.Add(filter); } else if (!string.IsNullOrEmpty(sellerItem.Exclude_Sellers)) { filter = new ItemFilter(); filter.name = ItemFilterType.ExcludeSeller; filter.value = sellerItem.Exclude_Sellers.Split(','); filters.Add(filter); } } /*MinQuantity*/ if (sellerItem.Minimum_Quantity > 0) { filter = new ItemFilter(); filter.name = ItemFilterType.MinQuantity; filter.value = new string[] { sellerItem.Minimum_Quantity.ToString() }; filters.Add(filter); } /*MaxQuantity*/ if (sellerItem.Maximum_Quantity > 0) { filter = new ItemFilter(); filter.name = ItemFilterType.MaxQuantity; filter.value = new string[] { sellerItem.Maximum_Quantity.ToString() }; filters.Add(filter); } /*MinPrice*/ if (sellerItem.Minimum_Price >= 0) { filter = new ItemFilter(); filter.name = ItemFilterType.MinPrice; filter.value = new string[] { sellerItem.Minimum_Price.ToString() }; filters.Add(filter); } /*MaxPrice*/ if (sellerItem.Maximum_Price > 0) { filter = new ItemFilter(); filter.name = ItemFilterType.MaxPrice; filter.value = new string[] { sellerItem.Maximum_Price.ToString() }; filters.Add(filter); } /*FeedbackScoreMin*/ if (sellerItem.Minimum_Feedback >= 0) { filter = new ItemFilter(); filter.name = ItemFilterType.FeedbackScoreMin; filter.value = new string[] {sellerItem.Minimum_Feedback.ToString()}; filters.Add(filter); } /*FeedbackScoreMax*/ if (sellerItem.Maximum_Feedback > 0) { filter = new ItemFilter(); filter.name = ItemFilterType.FeedbackScoreMax; filter.value = new string[] { sellerItem.Maximum_Feedback.ToString() }; filters.Add(filter); } /*Condition*/ if (!string.IsNullOrEmpty(sellerItem.Include_Condtion_Codes)) { filter = new ItemFilter(); filter.name = ItemFilterType.Condition; filter.value = sellerItem.Include_Condtion_Codes.Split(','); filters.Add(filter); } /*Cateogry*/ if (!string.IsNullOrEmpty(sellerItem.Exclude_Category_Codes)) { filter = new ItemFilter(); filter.name = ItemFilterType.ExcludeCategory; filter.value = sellerItem.Exclude_Category_Codes.Split(','); filters.Add(filter); } if(filters.Count > 0) request.itemFilter = filters.ToArray(); request.sortOrder = SortOrderType.BestMatch; request.sortOrderSpecified = true; // Creating response object FindItemsByKeywordsResponse response = service.findItemsByKeywords(request); return response; }
public FindItemsByKeywordsResponse SearchItems(string query, int pageSize, int pageNumber, dynamic filterList) { // Creating an object to the BestMatchService class CustomFindingService service = new CustomFindingService(); service.Url = ConfigurationManager.AppSettings["FindingService"]; // Creating request object for FindBestMatchItemDetailsByKeywords API FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest(); // Setting the required property values request.keywords = query; // Setting the pagination PaginationInput pagination = new PaginationInput(); pagination.entriesPerPageSpecified = true; pagination.entriesPerPage = pageSize; pagination.pageNumberSpecified = true; pagination.pageNumber = pageNumber; request.paginationInput = pagination; ItemFilter[] filters = new ItemFilter[4]; ItemFilter filter = new ItemFilter(); filter.name = ItemFilterType.ListingType; filter.value = new string[] { "FixedPrice", "StoreInventory" }; ItemFilter filter3 = new ItemFilter(); filter3.name = ItemFilterType.MinPrice; filter3.value = new string[] { filterList["MinPrice"] }; filters[0] = filter; filters[1] = filter3; if (int.Parse(filterList["MinQuantity"]) > 0) { ItemFilter filter2 = new ItemFilter(); filter2.name = ItemFilterType.MinQuantity; filter2.value = new string[] { filterList["MinQuantity"] }; filters[2] = filter2; } if (filterList["IsNew"] == true) { ItemFilter filter4 = new ItemFilter(); filter4.name = ItemFilterType.Condition; filter4.value = new string[] { "New" }; filters[3] = filter4; } request.itemFilter = filters; request.sortOrder = SortOrderType.BestMatch; request.sortOrderSpecified = true; // Creating response object FindItemsByKeywordsResponse response = service.findItemsByKeywords(request); return response; }
public FindItemsByKeywordsResponse SearchItemsByID(string ItemID) { // Creating an object to the BestMatchService class CustomFindingService service = new CustomFindingService(); service.Url = ConfigurationManager.AppSettings["FindingService"]; // Creating request object for FindBestMatchItemDetailsByKeywords API FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest(); // Setting the required property values request.keywords = ItemID; // Setting the pagination PaginationInput pagination = new PaginationInput(); pagination.entriesPerPageSpecified = true; pagination.entriesPerPage = 10; pagination.pageNumberSpecified = true; pagination.pageNumber = 1; request.paginationInput = pagination; List<ItemFilter> filters = new List<ItemFilter>(); ItemFilter filter = new ItemFilter(); filter.name = ItemFilterType.ListingType; filter.value = new string[] { "FixedPrice", "AuctionWithBIN" }; filters.Add(filter); request.itemFilter = filters.ToArray(); request.sortOrder = SortOrderType.BestMatch; request.sortOrderSpecified = true; // Creating response object FindItemsByKeywordsResponse response = service.findItemsByKeywords(request); return response; }
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>()); } }
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); } }
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>()); } }
public ActionResult Index(string Id, string zip) { FindingServicePortTypeClient client = FindingServiceClientFactory.getServiceClient(config); ViewBag.Message = Id; ViewBag.Zip = zip; SearchItem[] items = null; try { // Create request object FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest(); // Set request parameters request.keywords =Id; if (!string.IsNullOrEmpty(zip)) { request.buyerPostalCode = zip; ItemFilter[] ifilter = { new ItemFilter { name = ItemFilterType.MaxDistance, value = new string[] { "50" }} // , new ItemFilter { name = ItemFilterType.Seller, value = new string[] { "easypeaches" }} }; // ItemFilter[] ifilter2 = { new ItemFilter { name = ItemFilterType.Seller, value = new string[] { "easypeaches" } } }; request.itemFilter = ifilter; } request.sortOrder = SortOrderType.BidCountMost; //request.sortOrderSpecified = true; OutputSelectorType[] outputs = { OutputSelectorType.SellerInfo }; request.outputSelector = outputs; PaginationInput pi = new PaginationInput(); pi.entriesPerPage = 105; pi.entriesPerPageSpecified = true; request.paginationInput = pi; // Call the service FindItemsByKeywordsResponse response = client.findItemsByKeywords(request); // Show output if (response.searchResult != null && response.searchResult.item != null) { items = response.searchResult.item; ViewBag.resultcount = response.searchResult.count; ViewBag.totalitems = response.paginationOutput.totalEntries; // var groupeditems = items.GroupBy(i => i.sellerInfo); //var itemsBySeller = // from i in items // group i by i.sellerInfo into s // select new { SellerName = s.Key.sellerUserName, ItemCount = s.Count(), Items=s }; return View(items); } } catch (Exception ex) { var errorText = ex.Message; } return View(); }
public ActionResult Users(string Id) { FindItemsByKeywordsRequest req = new FindItemsByKeywordsRequest(); FindItemsByKeywordsResponse resp = new FindItemsByKeywordsResponse(); return View(); }
public FindResult<StoreProductSearchModel> SearchExternalStoreProduct(StoreProductSearchRequest searchRequest) { List<string> itemIds = new List<string>(); FindResult<StoreProductSearchModel> searchResult = new FindResult<StoreProductSearchModel>() { Entities = new List<StoreProductSearchModel>(), Success = false }; int totalItems = 0; eBayContext = eBayApiContextFactory.CreateServiceContext(); eBayFindingApiClient findingClient = new eBayFindingApiClient(eBayFindingApiClient.FindingServiceType.findItemsByKeywords.ToString()); FindItemsByKeywordsRequest request = new FindItemsByKeywordsRequest(); request.keywords = searchRequest.ProductName; PaginationInput pagination = new PaginationInput(); pagination.entriesPerPageSpecified = true; pagination.entriesPerPage = 100; pagination.pageNumberSpecified = true; pagination.pageNumber = 1; request.paginationInput = pagination; List<ItemFilter> filters = new List<ItemFilter>(); filters.Add(new ItemFilter { name = ItemFilterType.Currency, value = new string[] { "GBP" } }); filters.Add(new ItemFilter { name = ItemFilterType.Seller, value = new string[] { "stellatraders" }, }); request.itemFilter = filters.ToArray(); request.sortOrderSpecified = true; request.sortOrder = SortOrderType.BestMatch; request.keywords = searchRequest.ProductName; FindItemsByKeywordsResponse response = findingClient.findItemsByKeywords(request); if (response.ack != AckValue.Failure) { if (response.paginationOutput.totalEntriesSpecified) { totalItems = response.paginationOutput.totalEntries; } foreach (SearchItem searchItem in response.searchResult.item) { if (itemIds.Contains(searchItem.itemId.Trim())) { continue; } itemIds.Add(searchItem.itemId); searchResult.Entities.Add(ConvertSearchItemToSearchItemModel(searchItem)); //StoreProductSearchModel searchModel = new StoreProductSearchModel() //{ // ProductTitle = searchItem.title, // StoreProductId = searchItem.itemId, // StoreProductId1 = searchItem.productId.Value, //}; } if (response.paginationOutput.pageNumberSpecified && response.paginationOutput.totalPagesSpecified) { int totalPages = response.paginationOutput.totalPages; int currentPageNo = response.paginationOutput.pageNumber; while (totalPages > currentPageNo) { currentPageNo += 1; pagination.pageNumber = currentPageNo; request.paginationInput = pagination; response = findingClient.findItemsByKeywords(request); if (response.ack != AckValue.Failure) { foreach (SearchItem searchItem in response.searchResult.item) { if (itemIds.Contains(searchItem.itemId.Trim())) { continue; } itemIds.Add(searchItem.itemId); searchResult.Entities.Add(ConvertSearchItemToSearchItemModel(searchItem)); } } } } searchResult.Success = true; } else { searchResult.Success = false; searchResult.ErrorMessage = "Error occurred while searching for product in Ebay"; } return searchResult; }