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(); }
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> { }; }
/// <summary> /// A simple interface to get eBay Finding Service client proxy /// </summary> /// <param name="config">Client configuration</param> /// <returns>eBay Finding Service client proxy of type FindingServicePortTypeClient</returns> public static FindingServicePortTypeClient getServiceClient(ClientConfig config) { return (FindingServicePortTypeClient)ClientFactory.GetSerivceClient<FindingServicePortType>(config, typeof(FindingServicePortTypeClient), ServiceConstants.FINDING_SERVICE_NAME); }
public EbayFinder() { _clientConfig = new ClientConfig(); }
static List<VideoCard> GrabPricesFromEbay(string keyword) { List<VideoCard> foundCards = new List<VideoCard>(); //setup for console logging of api results LoggerService.SetLogger(new ConsoleLogger()); ILogger logger = LoggerService.GetLogger(); try { ClientConfig config = new ClientConfig(); // Initialize service end-point configuration config.EndPointAddress = "http://svcs.sandbox.ebay.com/services/search/FindingService/v1"; // set eBay developer account AppID config.ApplicationId = "JackPetr-b629-4a64-94a2-cb909b9c0c47"; // Create a service client FindingServicePortTypeClient client = FindingServiceClientFactory.getServiceClient(config); // Create request object FindCompletedItemsRequest completedItemsRequest = new FindCompletedItemsRequest(); // Set request parameters keyword = keyword + " -water -block -waterblock -heatsink -heat -sink"; completedItemsRequest.keywords = keyword; DateTime today = DateTime.UtcNow; DateTime month = new DateTime(today.Year, today.Month, 1); DateTime lastMonth = month.AddMonths(-1); ItemFilter if1 = new ItemFilter(); if1.name = ItemFilterType.EndTimeFrom; if1.value = new string[] {lastMonth.ToString("o")}; ItemFilter if2 = new ItemFilter(); if2.name = ItemFilterType.EndTimeTo; if2.value = new string[] { today.ToString("o") }; ItemFilter if3 = new ItemFilter(); if3.name = ItemFilterType.MinPrice; if3.paramName = "Currency"; if3.paramValue = "USD"; if3.value = new string[] {"50"}; ItemFilter if4 = new ItemFilter(); if4.name = ItemFilterType.MaxPrice; if4.paramName = "Currency"; if4.paramValue = "USD"; if4.value = new string[] { "1100" }; ItemFilter if5 = new ItemFilter(); if5.name = ItemFilterType.ExcludeCategory; if5.value = new string[] {"179"}; ItemFilter[] ifa = new ItemFilter[5]; ifa[0] = if1; ifa[1] = if2; ifa[2] = if3; ifa[3] = if4; ifa[4] = if5; completedItemsRequest.itemFilter = ifa; PaginationInput pi = new PaginationInput(); pi.entriesPerPage = 200; pi.entriesPerPageSpecified = true; completedItemsRequest.paginationInput = pi; // Call the service FindCompletedItemsResponse response = client.findCompletedItems(completedItemsRequest); // Show output if (Debug) if (response.ack.ToString().Equals("Failure")) { int tries = 0; while (tries < 3) { if (response.ack.ToString().Equals("Failure")) { //retry tries++; response = client.findCompletedItems(completedItemsRequest); }else { break; } } } logger.Info("Ack = " + response.ack); logger.Info("Find " + response.searchResult.count + " items."); SearchItem[] items = response.searchResult.item; if(Debug){logSearchResultsToFile(items);} foreach (SearchItem item in items) { if (item.sellingStatus.sellingState.Equals("EndedWithSales")) { VideoCard trackCard = new VideoCard(); trackCard.SetCardName(item.title); trackCard.SetPrice(item.sellingStatus.currentPrice.Value); foundCards.Add(trackCard); logger.Info("Item" + item.title + "added!"); logger.Info(item.sellingStatus.currentPrice.Value); } } } catch (Exception ex) { // Handle exception if any logger.Error(ex); } return foundCards; }
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 IEnumerable<long> SearchLinks() { IList<long> list = new List<long>(); //181419645692 var config = new ClientConfig(); config.EndPointAddress = "http://svcs.ebay.com/services/search/FindingService/v1"; config.ApplicationId = "Artsiom97-3905-4c09-9e4e-4144ac444e6"; var client = FindingServiceClientFactory.getServiceClient(config); var request = new FindItemsAdvancedRequest(); // Set request parameters request.keywords = Keywords; request.categoryId = new string[] { CategoryId.ToString() }; var pi = new PaginationInput(); pi.entriesPerPage = PerPage; pi.entriesPerPageSpecified = true; request.paginationInput = pi; // Call the service var response = client.findItemsAdvanced(request); // Show output var items = response.searchResult.item; for (var i = 0; i < items.Length; i++) { list.Add(Convert.ToInt64(items[i].itemId)); } return list; }