public override void Process(OutputStream <Item> output)
        {
            AWSECommerceService service = new AWSECommerceService();

            //service.Url = "http://soap.amazon.com/onca/soap?Service=AWSECommerceService";
            service.Url = "http://localhost:8080/onca/soap?Service=AWSECommerceService";

            ItemSearchRequest search = new ItemSearchRequest();

            search.Keywords      = _keywords + " tv";
            search.SearchIndex   = "Electronics";
            search.ResponseGroup = new string[] { "Large" };
            ItemSearch request = new ItemSearch();

            request.Request        = new ItemSearchRequest[] { search };
            request.Validate       = "false";
            request.XMLEscaping    = "Single";
            request.SubscriptionId = DeveloperIds.AmazonID;
            ItemSearchResponse response = service.ItemSearch(request);

            Console.WriteLine(response.OperationRequest.ToString());
            if (response.Items.Length > 0)
            {
                Items[] arrayItems = response.Items;
                foreach (Items items in arrayItems)
                {
                    foreach (Item item in items.Item)
                    {
                        output.Write(item);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static ItemSearchResponse DoAmazonItemSearch(string keywords, int page)        //AWSECommerceServicePortTypeClient ecs, ItemSearchRequest request)
        {
            ItemSearchResponse response = null;

            // Create an ItemSearch wrapper
            ItemSearch search = new ItemSearch();

            search.AssociateTag   = _ASSOCIATE_TAG;
            search.AWSAccessKeyId = _ACCESS_KEY_ID;

            AWSECommerceServicePortTypeClient ecs = GetClient();
            ItemSearchRequest request             = GetSearchRequest();

            request.Keywords = keywords;
            request.ItemPage = Convert.ToString(page);

            // Set the request on the search wrapper
            search.Request = new ItemSearchRequest[] { request };

            try
            {
                //Send the request and store the response
                response = ecs.ItemSearch(search);
            }
            catch (NullReferenceException e)
            {
                Debug.WriteLine(e.ToString());
            }
            return(response);
        }
    public void TestSearch()
    {
        AWSECommerceService service = new AWSECommerceService();

        //service.Url = "http://soap.amazon.com/onca/soap?Service=AWSECommerceService";
        service.Url = "http://localhost:8080/onca/soap?Service=AWSECommerceService";

        ItemSearchRequest search = new ItemSearchRequest();

        search.Keywords      = "television lcd";
        search.SearchIndex   = "Electronics";
        search.ResponseGroup = new string[] { "Large" };
        //OperationRequest
        ItemSearch request = new ItemSearch();

        request.Request        = new ItemSearchRequest[] { search };
        request.Validate       = "false";
        request.XMLEscaping    = "Single";
        request.SubscriptionId = DeveloperIds.AmazonID;
        ItemSearchResponse response = service.ItemSearch(request);

        Console.WriteLine(response.OperationRequest.ToString());
        if (response.Items.Length > 0)
        {
            Items[] arrayItems = response.Items;
            foreach (Items items in arrayItems)
            {
                foreach (Item item in items.Item)
                {
                    Console.WriteLine("Title (" + item.ItemAttributes.Title + ")");
                    Console.WriteLine("Item (" + item.ASIN + ")");
                }
            }
        }
    }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            // Instantiate Amazon ProductAdvertisingAPI client
            AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient();

            // prepare an ItemSearch request
            ItemSearchRequest request = new ItemSearchRequest
            {
                SearchIndex   = "Books",
                Title         = "WCF",
                ResponseGroup = new[] { "Small" }
            };

            ItemSearch itemSearch = new ItemSearch
            {
                Request        = new[] { request },
                AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"],
                AssociateTag   = "ReplaceWithYourValue"
            };

            // send the ItemSearch request
            ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);

            // write out the results from the ItemSearch request
            foreach (var item in response.Items[0].Item)
            {
                Console.WriteLine(item.ItemAttributes.Title);
            }
            Console.WriteLine("done...enter any key to continue>");
            Console.ReadLine();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var ci = CultureInfo.InvariantCulture.Clone() as CultureInfo;

            ci.NumberFormat.NumberDecimalSeparator = ".";

            List <string> products = new List <string>();
            List <string> price    = new List <string>();
            // Instantiate Amazon ProductAdvertisingAPI client
            AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient();


            for (int i = 1; i <= 6; i++)
            {
                // prepare an ItemSearch request
                ItemSearchRequest request = new ItemSearchRequest();
                request.SearchIndex = "All";
                //request.Title = "WCF";
                request.Keywords      = "playstation -kindle";
                request.ResponseGroup = new string[] { "ItemAttributes", "Images" };
                request.ItemPage      = i.ToString();



                ItemSearch itemSearch = new ItemSearch();
                itemSearch.Request        = new ItemSearchRequest[] { request };
                itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"];
                itemSearch.AssociateTag   = "testfo-20";


                // send the ItemSearch request
                ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);
            }
        }
        public ItemSearchResponse GetSearchResponse(ItemSearchRequest searchRequest)
        {
            ItemSearch search = CreateItemSearch(searchRequest);

            AWSECommerceService api      = GetService();
            ItemSearchResponse  response = api.ItemSearch(search);

            return(response);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Search a specific item set and returns all its items
        /// </summary>
        /// <param name="index">The ID of the item set to search</param>
        public async void SearchItemSet(IdObject index)
        {
            ItemSearchResponse <DublicCoreVocabulary> response = await _client.Api.SearchItems(new ItemSearchParams()
            {
                item_set_id = index.Id
            });

            GenerateItemButtons(response);
        }
Ejemplo n.º 8
0
 private void GenerateItemButtons(ItemSearchResponse <DublicCoreVocabulary> response)
 {
     ClearChildren(_buttonRoot);
     for (int i = 0; i < response.Items.Count; i++)
     {
         IdObject idObject = response.Items[i].Id;
         GenerateButton(response.Items[i].Title, () => { SearchMedia(idObject); });
     }
 }
        public ItemSearchResponse KeywordSearch(string keywords, SearchIndex searchIndex = SearchIndex.VideoGames, int pageNumber = 1)
        {
            ItemSearchRequest searchRequest = CreateItemSearchRequest(searchIndex);

            searchRequest.ItemPage = pageNumber.ToString();
            searchRequest.Keywords = keywords;

            ItemSearchResponse response = GetSearchResponse(searchRequest);

            return(response);
        }
        private List <AmazonItemSearch> MapProperties(ItemSearchResponse response)
        {
            List <AmazonItemSearch> items = new List <AmazonItemSearch>();

            if (response.Items != null && response.Items.Request != null && response.Items.Request.Errors != null)
            {
                throw new Exception(response.Items.Request.Errors.Error.Code + " - " + response.Items.Request.Errors.Error.Message);

                //item.ErrorCode = response.Items.Request.Errors.Error.Code != null ? response.Items.Request.Errors.Error.Code : "";
                //item.ErrorMessage = response.Items.Request.Errors.Error.Message != null ? response.Items.Request.Errors.Error.Message : "";
            }


            if (response.Items != null && response.Items.Item != null)
            {
                foreach (var resultItem in response.Items.Item)
                {
                    AmazonItemSearch item = new AmazonItemSearch();

                    item.ASIN          = resultItem.ASIN;
                    item.ParentASIN    = resultItem.ParentASIN != null ? resultItem.ParentASIN : "";
                    item.DetailPageURL = resultItem.DetailPageURL != null ? resultItem.DetailPageURL : "";

                    if (resultItem.SmallImage != null)
                    {
                        item.SmallImageUrl = resultItem.SmallImage.URL != null ? resultItem.SmallImage.URL : "";
                    }

                    if (resultItem.MediumImage != null)
                    {
                        item.MediumImageUrl = resultItem.MediumImage.URL != null ? resultItem.MediumImage.URL : "";
                    }

                    if (resultItem.MediumImage != null)
                    {
                        item.LargeImageUrl = resultItem.LargeImage.URL != null ? resultItem.LargeImage.URL : "";
                    }

                    if (resultItem.ItemAttributes != null)
                    {
                        item.Manufacturer = resultItem.ItemAttributes.Manufacturer != null ? resultItem.ItemAttributes.Manufacturer : "";
                        item.ProductGroup = resultItem.ItemAttributes.ProductGroup != null ? resultItem.ItemAttributes.ProductGroup : "";
                        item.Title        = resultItem.ItemAttributes.Title != null ? resultItem.ItemAttributes.Title : "";
                    }

                    // inefficient - change FetchItem
                    //item.ResultXML = SerializeObject(resultItem);

                    items.Add(item);
                }
            }

            return(items);
        }
Ejemplo n.º 11
0
        private static void ItemSearch()
        {
            // Create the request object
            ItemSearchRequest request = new ItemSearchRequest();

            // Fill request object with request parameters
            request.ResponseGroup = new string[] { "Large", "ItemAttributes", "AlternateVersions" };

            // Set SearchIndex to All and use the scanned EAN
            // as the keyword, this should generate a single response
            request.SearchIndex = "Books";
            request.Keywords    = "Century rain"; // asin = 0441013074
            request.Author      = "Alastair Reynolds";

            // Make the item search
            ItemSearch search = new ItemSearch();

            // It is ABSOLUTELY CRITICAL that you change
            // the AWSAccessKeyID to YOUR uniqe value
            // Signup for an account (and AccessKeyID) at http://aws.amazon.com/
            search.AWSAccessKeyId = access_key_id;
            search.AssociateTag   = associate_tag;

            // Set the request on the search wrapper - multiple requests
            // can be submitted on one search
            search.Request = new ItemSearchRequest[] { request };

            // Make the port
            AWSECommerceServicePortTypeClient port = new AWSECommerceServicePortTypeClient("AWSECommerceServicePort");

            port.ChannelFactory.Endpoint.EndpointBehaviors.Add(new AmazonSigningEndpointBehavior(access_key_id, secret_access_key));

            //Send the request, store the response and display some of the results
            ItemSearchResponse response = port.ItemSearch(search);

            foreach (var items in response.Items)
            {
                foreach (var item in items.Item)
                {
                    Console.WriteLine("{0}\t{1}\t{2}", item.ItemAttributes.Title, item.ASIN, item.ItemAttributes.Author[0]);

                    if (item.AlternateVersions != null)
                    {
                        Console.WriteLine(" - Alternate versions");
                        foreach (var version in item.AlternateVersions)
                        {
                            Console.WriteLine(" -- \t{0}\t{1}\t{2}", version.Title, version.Binding, version.ASIN);
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public static AmazonSearchResults Search(string keywords, int resultsRequested, int page)
        {
            AmazonSearchResults results = new AmazonSearchResults();

            results.Items = new List <AmazonItem>();

            List <Item> items = new List <Item>();

            int itemsCount   = 0;                       //results added to list
            int itemIndex    = page * resultsRequested; //item index among all results found by amazon
            int totalResults = 0;                       //results found by amazon

            bool shouldFinish = false;

            while (itemsCount < resultsRequested && !shouldFinish)
            {
                ItemSearchResponse response = DoAmazonItemSearch(keywords, (itemIndex / 10) + 1);

                if (response == null)
                {
                    Debug.WriteLine("Response was null");
                    break;
                }
                if (response.Items[0].Item == null)
                {
                    Debug.WriteLine("No items returned");
                    break;
                }
                else
                {
                    totalResults = Convert.ToInt32(response.Items[0].TotalResults);
                }

                for (int i = itemIndex % 10; i < 10; i++)
                {
                    if (itemIndex >= totalResults || itemIndex >= 50 || itemsCount >= resultsRequested)
                    {
                        shouldFinish = true;
                        break;
                    }

                    Item item = response.Items[0].Item[i];
                    results.Items.Add(new AmazonItem(item));
                    itemsCount++;
                    itemIndex++;
                }
            }

            results.TotalItems = totalResults;
            return(results);
        }
Ejemplo n.º 13
0
        public DataTable GetProducts(string productName)
        {
            DataTable products = new DataTable();

            products.Columns.Add("Product", typeof(string));
            products.Columns.Add("Price", typeof(string));
            products.Columns.Add("Image", typeof(string));
            products.Columns.Add("url", typeof(string));



            // Instantiate Amazon ProductAdvertisingAPI client
            AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient();

            for (int i = 1; i <= 5; i++)
            {
                // prepare an ItemSearch request
                ItemSearchRequest request = new ItemSearchRequest();
                request.SearchIndex   = "All";
                request.Keywords      = productName + " -kindle";
                request.ResponseGroup = new string[] { "ItemAttributes", "Images" };
                request.ItemPage      = i.ToString();
                request.Condition     = Condition.New;
                request.Availability  = ItemSearchRequestAvailability.Available;

                ItemSearch itemSearch = new ItemSearch();
                itemSearch.Request        = new ItemSearchRequest[] { request };
                itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"];
                itemSearch.AssociateTag   = "testfo-20";

                // send the ItemSearch request
                ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);



                foreach (var item in response.Items[0].Item)
                {
                    try
                    {
                        products.Rows.Add(item.ItemAttributes.Title, item.ItemAttributes.ListPrice.FormattedPrice.Replace("$", ""), item.SmallImage.URL, item.DetailPageURL);
                    }

                    catch (NullReferenceException ex) {
                        Debug.WriteLine("Caught Exception: " + ex.Message);
                        continue;
                    }
                }
            }
            return(products);
        }
Ejemplo n.º 14
0
        public async Task ItemSearch()
        {
            //create a WCF Amazon ECS client
            AWSECommerceServiceClient client = new AWSECommerceServiceClient();

            //prepare an ItemSearchRequest to search for
            ItemSearchRequest requestPage1 = new ItemSearchRequest()
            {
                SearchIndex   = SearchIndex.All.ToString(),
                Keywords      = "AbilityOne",
                ItemPage      = "20",
                ResponseGroup = new string[]
                {
                    //ResponseGroup.Images.ToString(),
                    ResponseGroup.ItemAttributes.ToString(),
                    //ResponseGroup.Offers.ToString()
                },
            };
            ItemSearchRequest requestPage2 = new ItemSearchRequest()
            {
                SearchIndex   = SearchIndex.All.ToString(),
                Keywords      = "AbilityOne",
                ItemPage      = "21",
                ResponseGroup = new string[]
                {
                    //ResponseGroup.Images.ToString(),
                    ResponseGroup.ItemAttributes.ToString(),
                    //ResponseGroup.Offers.ToString()
                },
            };

            //prepare an ItemSearch
            ItemSearch itemSearch = new ItemSearch()
            {
                Request        = new ItemSearchRequest[] { requestPage1, requestPage2 },
                AssociateTag   = AmazonInformation.GetAssociateTag(),
                AWSAccessKeyId = AmazonInformation.GetAccessKeyID(),
            };

            // issue the ItemSearch request
            ItemSearchResponse response = client.ItemSearch(itemSearch);

            /*itemSearch.Request[0].Keywords = "7920-00-543-6492";
             *
             * ItemSearchResponse response2 = client.ItemSearch(itemSearch);*/
        }
Ejemplo n.º 15
0
        private static ItemSearchResponse AmazonRequestByPage(string Keyword, int page, string SearchIndex)
        {
            #region Set Amazon Search parameters
            ItemSearch search = new ItemSearch();
            //replace these with your account info
            search.AssociateTag = "X";
            string accessKeyId = "X";
            string secretKey   = "X";

            ItemSearchRequest req = new ItemSearchRequest();

            req.ResponseGroup = new string[] { "Medium" };
            req.SearchIndex   = SearchIndex;

            req.ItemPage = Convert.ToString(page);
            req.Keywords = Keyword;

            req.Availability = ItemSearchRequestAvailability.Available;
            search.Request   = new ItemSearchRequest[] { req };


            Amazon.AWSECommerceServicePortTypeClient amzwc = new Amazon.AWSECommerceServicePortTypeClient();
            amzwc.ChannelFactory.Endpoint.EndpointBehaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey));

            try
            {
                ItemSearchResponse resp = amzwc.ItemSearch(search);
                return(resp);
            }
            catch (Exception ex)
            {
                ItemSearchResponse resp = null;
                return(resp);
            }

            #endregion
        }
Ejemplo n.º 16
0
        public async Task <ItemSearchResponse <T> > SearchItems(ItemSearchParams searchparams)
        {
            var result = await Search(ResourceType.items, searchparams);

            var response = new ItemSearchResponse <T>()
            {
                ResponseCode = result.ResponseCode, RequestURL = result.RequestURL
            };

            if (result.ResponseCode == 200)
            {
                JArray           array    = (JArray)result.Message;
                List <Item <T> > itemSets = new List <Item <T> >();
                foreach (var entry in array)
                {
                    Item <T> r = Item <T> .FromJObject((JObject)entry);

                    itemSets.Add(r);
                }

                response.Items = itemSets;
            }
            return(response);
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            // Instantiate Amazon ProductAdvertisingAPI client
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

            binding.MaxReceivedMessageSize = int.MaxValue;
            AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(
                binding,
                new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));

            //Adding this uses the code in Amazon.PAAPI.WCF to sign requests automagically
            amazonClient.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior());

            // prepare an ItemSearch request
            ItemSearchRequest request = new ItemSearchRequest();

            request.SearchIndex   = "DVD";
            request.Title         = "Matrix";
            request.ResponseGroup = new string[] { "Small" };

            ItemSearch itemSearch = new ItemSearch();

            itemSearch.Request      = new ItemSearchRequest[] { request };
            itemSearch.AssociateTag = "notag"; //this is a required param, so I just use a dummy value which seems to work

            // send the ItemSearch request
            ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);

            // write out the results from the ItemSearch request
            foreach (var item in response.Items[0].Item)
            {
                Console.WriteLine(item.ItemAttributes.Title);
            }
            Console.WriteLine("\n\n<<< done...enter any key to continue >>>");
            Console.ReadLine();
        }
Ejemplo n.º 18
0
        public ItemSearchResponse ItemSearch(string ItemPage, string SearchIndex, string[] ResponseGroup, string Title)
        {
            // BasicHttpBinding configuration
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.MaxBufferSize          = int.MaxValue;

            // create a WCF Amazon ECS client
            AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient(
                binding,
                new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));

            // add authentication to the ECS client
            client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey));

            // prepare an ItemSearchRequest
            ItemSearchRequest request = new ItemSearchRequest();

            request.SearchIndex   = SearchIndex;
            request.ResponseGroup = ResponseGroup;
            request.Title         = Title;
            request.ItemPage      = ItemPage;

            // prepare an ItemSearch
            ItemSearch search = new ItemSearch();

            search.Request        = new ItemSearchRequest[] { request };
            search.AWSAccessKeyId = accessKeyId;
            search.AssociateTag   = "http://affiliate-program.amazon.com/";

            //get ItemSearchResponse
            ItemSearchResponse response = client.ItemSearch(search);

            return(response);
        }
Ejemplo n.º 19
0
 public SearchResults(ItemSearchResponse response)
 {
     this.Info = new SearchResponseInfo(response.Items[0]);
     SetItems();
 }
Ejemplo n.º 20
0
    static void Main(String[] args)
    {
        // Write to console
        Console.WriteLine("Welcome to the C# Station Tutorial!");

        // Set default args if two are not supplied
        if (args.Length != 2)
        {
            args = new string[] { "DVD", "Matrix" };
        }
        // Get searchIndex and keywords from the command line
        string searchIndex = args[0];
        string keywords    = args[1];
        // Create an instance of the Product Advertising API service
        AWSECommerceServicePortTypeClient ecs = new AWSECommerceServicePortTypeClient();

        /* Error:
         * An endpoint configuration section for contract 'amazon.ecs.AWSECommerceServicePortType'
         * could not be loaded because more than one endpoint configuration for that contract was
         * found. Please indicate the preferred endpoint configuration section by name.
         */

        // Create ItemSearch wrapper
        ItemSearch search = new ItemSearch();

        //search.AssociateTag = assocTag;
        search.AWSAccessKeyId = accessKeyId;
        // Create a request object
        ItemSearchRequest request = new ItemSearchRequest();

        // Fill request object with request parameters
        request.ResponseGroup = new string[] { "ItemAttributes" };
        // Set SearchIndex and Keywords
        request.SearchIndex = searchIndex;
        request.Keywords    = keywords;
        // Set the request on the search wrapper
        search.Request = new ItemSearchRequest[] { request };
        Console.WriteLine(request.Keywords);
        try
        {
            //Send the request and store the response in response
            Console.WriteLine("try...");
            ItemSearchResponse response = ecs.ItemSearch(search);
            //Check for null response
            if (response == null)
            {
                throw new Exception("Server Error - no response recieved!");
            }
            //ItemSearchResult[] itemsArray = response.GetItemSearchResult;
            if (response.OperationRequest.Errors != null)
            {
                throw new Exception(response.OperationRequest.Errors[0].Message);
            }
            Console.WriteLine("Response: " + response.ToString());
            Console.WriteLine("Length: " + response.Items.Length);
        }
        catch (Exception e)
        {
            Console.WriteLine("...catch");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Err: " + e.Message);
            Console.WriteLine("Type: " + e.GetType());
            Console.WriteLine("Inner Exception: " + e.InnerException.Message);
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Press any key to quit...");
            // http://www.webdesigncompany.co.uk/blog/2011/10/5/using-the-new-amazon-product-api-wsdl-with-microsoftwebservices3/
            // Err: The remote server returned an unexpected response: (400) Bad Request.
        }
        Console.ReadKey();
    }
        public void ProductsInfo()
        {
            ProductsPages productsInfo = new ProductsPages();



            int skip = (_pageNumber - 1) * _itemsPerPage;

            int startPage;

            if ((skip % 10) <= 2 && (skip % 10) != 0)
            {
                startPage = _pageNumber + 1;
            }
            else
            {
                startPage = _pageNumber;
            }

            int startItem = skip % 10;


            ///////////////////

            for (int page = startPage; page <= 10; page++)
            {
                AmazonRequestHelper amazonRequestHelper = new AmazonRequestHelper();
                string             itemPage             = Convert.ToString(page);
                ItemSearchResponse itemSearchResponse   = amazonRequestHelper.ItemSearch(itemPage, "Books", new string[] { "ItemAttributes", "Offers" }, _keywords);

                int totalPages = Convert.ToInt32(itemSearchResponse.Items[0].TotalPages);

                if (totalPages >= 10)
                {
                    productsInfo.Pages = 10;
                }
                else
                {
                    productsInfo.Pages = totalPages;
                }


                if (itemSearchResponse.Items[0].Item != null)
                {
                    for (int i = startItem; i < itemSearchResponse.Items[0].Item.Length; i++)
                    {
                        if (_itemsPerPage > 0)
                        {
                            var item = itemSearchResponse.Items[0].Item[i];

                            Debug.WriteLine("{0}\t{1}\tpage:{2}\titem:{3}", item.ItemAttributes.Title, Convert.ToDecimal(item.OfferSummary.LowestNewPrice.Amount) / 100, page, i);
                            Product currentProduct = new Product()
                            {
                                Title = item.ItemAttributes.Title,
                                Price = Convert.ToDecimal(item.OfferSummary.LowestNewPrice.Amount) / 100
                            };
                            productsInfo.Products.Add(currentProduct);
                            _itemsPerPage--;
                        }
                        else
                        {
                            break;
                        }
                    }
                    startItem = 0;
                    Thread.Sleep(1000);
                }
            }
            _productInfo = productsInfo;
        }
Ejemplo n.º 22
0
        public static DataModels.SearchResult SearchItems(string Keyword, double Rate, string SearchIndex)
        {
            #region init Model
            Models.DataModels.SearchResult Searchresults = new DataModels.SearchResult();
            List <Models.DataModels.SearchResult.SearchResultsList> SearchresultsList = new List <DataModels.SearchResult.SearchResultsList>();
            #endregion

            ItemSearchResponse resp = AmazonRequestByPage(Keyword, 1, SearchIndex);
            #region Check Response for errors
            //Check for null response
            if (resp == null)
            {
                Searchresults.Error = "Server Error - no response received!";
            }
            if (Convert.ToInt32(resp.Items[0].TotalResults) == 0)
            {
                Searchresults.Error = "No matches found!";
            }
            #endregion

            #region Set the pages to Loop Through according to amazon product advertising api
            ///If SearchIndex==All then Max Pages to query is 5
            ///else Max pages to loop through is 10
            int PagesToLoopTrhough         = Convert.ToInt32(resp.Items[0].TotalPages.ToString());
            int ModifiedPagesToLoopThrough = 0;
            if (SearchIndex == "All")
            {
                if (PagesToLoopTrhough > 5)
                {
                    ModifiedPagesToLoopThrough = 5;
                }
                else
                {
                    ModifiedPagesToLoopThrough = PagesToLoopTrhough;
                }
            }
            else
            {
                if (PagesToLoopTrhough > 10)
                {
                    ModifiedPagesToLoopThrough = 10;
                }
                else
                {
                    ModifiedPagesToLoopThrough = PagesToLoopTrhough;
                }
            }
            #endregion
            #region Loop Through The Search Results And Add to Model
            for (int i = 1; i < ModifiedPagesToLoopThrough + 1; i++)
            {
                resp = AmazonRequestByPage(Keyword, i, SearchIndex);
                foreach (Item item in resp.Items[0].Item)
                {
                    Models.DataModels.SearchResult.SearchResultsList SingleSearchResult = new Models.DataModels.SearchResult.SearchResultsList();
                    if (item.ItemAttributes.Author != null)
                    {
                        SingleSearchResult.Author = item.ItemAttributes.Author[0].ToString();
                    }
                    SingleSearchResult.Title        = item.ItemAttributes.Title ?? "";
                    SingleSearchResult.ProductGroup = item.ItemAttributes.ProductGroup;
                    if (item.ItemAttributes.ListPrice != null)
                    {
                        string Trimmed = item.ItemAttributes.ListPrice.FormattedPrice.Trim('£');
                        Trimmed = Trimmed.Replace(",", string.Empty);
                        SingleSearchResult.Price = Convert.ToString(Math.Round(Convert.ToDouble(Trimmed) * Rate, 2));
                    }
                    else
                    {
                        SingleSearchResult.Price = null;
                    }

                    SearchresultsList.Add(SingleSearchResult);
                }
            }

            #endregion

            Searchresults._SearchResultsList = SearchresultsList;
            return(Searchresults);
        }
Ejemplo n.º 23
0
 private static void ItemSearchFunc()
 {
     var request = new ItemSearchRequest
     {
         Keywords = "tv",
         SearchIndex = "All",
         ItemPage = _itemPage.ToString(CultureInfo.InvariantCulture)
     };
     var itemSearch = new ItemSearch
     {
         Request = new ItemSearchRequest[] {request},
         AWSAccessKeyId = AwsAccessKeyId,
         AssociateTag = AssociateTag
     };
     if (_itemSearchResponse == null)
     {
         try
         {
             _itemSearchResponse = AmazonClient.ItemSearch(itemSearch);
             Console.WriteLine("TotalResults: " + _itemSearchResponse.Items[0].TotalResults);
             Console.WriteLine("TotalPages: " + _itemSearchResponse.Items[0].TotalPages);
         }
         catch (ServerTooBusyException)
         {
             ItemSearchFunc();
         }
     }
     if (_itemSearchResponse == null) return;
     ItemLookupFunc(_itemSearchResponse.Items[0].Item.ToList());
 }