Beispiel #1
0
        public async Task <ItemsResult> GetMoreItems(SearchIndexType indexType, int itemPage)
        {
            var filename = string.Format("{0}_{1}.xml", indexType, itemPage);
            var response = await _serializer.ReadFile(CountryType.ToString(), filename);

            var result = LoadedResultType.Cached;

            if (response == null)
            {
                result   = LoadedResultType.Downloaded;
                response = await _service.ItemSearchAsync(CountryType, indexType, itemPage);

                if (string.IsNullOrEmpty(response))
                {
                    result = LoadedResultType.Failed;
                    return(new ItemsResult {
                        Result = result
                    });
                }
                _serializer.WriteFile(CountryType.ToString(), filename, response);
            }
            return(new ItemsResult
            {
                Items = _parser.Parse(response).Where(x => !x.Attributes.IsAdultProduct),
                Result = result,
            });
        }
Beispiel #2
0
        public static string ToBrowseNode(this SearchIndexType indexType, CountryType countryType)
        {
            switch (countryType)
            {
            case CountryType.Japan:
                return(ToBrowseNodeJapan(indexType));

            case CountryType.US:
                return(ToBrowseNodeUS(indexType));

            case CountryType.UK:
                return(ToBrowseNodeUK(indexType));

            case CountryType.France:
                return(ToBrowseNodeFrance(indexType));

            case CountryType.Germany:
                return(ToBrowseNodeGermany(indexType));

            case CountryType.Canada:
                return(ToBrowseNodeCanada(indexType));

            default:
                return(null);
            }
        }
        private static bool GetOnOff(XElement elem, SearchIndexType x)
        {
            var e = elem.Element(x.ToString());

            if (e == null)
            {
                return(true);
            }
            return(Convert.ToBoolean(e.Attribute("on").Value));
        }
Beispiel #4
0
        public async Task <Ranking> GetRanking(SearchIndexType indexType)
        {
            bool   cached   = false;
            string response = null;
            var    key      = string.Format("{0}:{1}", CountryType, indexType);
            var    filename = string.Format("{0}.xml", indexType);
            bool   cache;
            var    pre = _settingStore.Load <DateTime>(key, out cache);

            if (cache)
            {
                var diff = DateTime.Now - pre;
                if (diff.CompareTo(TimeSpan.FromMinutes(30)) < 0)
                {
                    response = await _serializer.ReadFile(CountryType.ToString(), filename);

                    cached = response != null;
                }
                else
                {
                    Enumerable.Range(2, 9).ForEach(async i =>
                    {
                        var deleteName = string.Format("{0}_{1}.xml", indexType, i);
                        await _serializer.DeleteFile(CountryType.ToString(), deleteName);
                    });
                }
            }

            if (response == null)
            {
                response = await _service.ItemSearchAsync(CountryType, indexType, 1);

                if (string.IsNullOrEmpty(response))
                {
                    return(null);
                }
                _serializer.WriteFile(CountryType.ToString(), filename, response);
                _settingStore.Save(key, DateTime.Now.ToString());
            }

            var items = _parser.Parse(response).Where(x => !x.Attributes.IsAdultProduct);

            return(new Ranking(this)
            {
                IndexType = indexType, Items = items, Cached = cached
            });
        }
Beispiel #5
0
        public string ItemSearch(SearchIndexType indexType, ResponseGroupType responseType = ResponseGroupType.Medium | ResponseGroupType.EditorialReview, string keyword = null, SortType sortType = SortType.salesrank, int itemPage = 1)
        {
            var request = CreateCommonRequest(OperationType.ItemSearch);

            request["SearchIndex"]   = Convert.ToString(indexType);
            request["ResponseGroup"] = Convert.ToString(responseType);
            request["BrowseNode"]    = indexType.ToBrowseNode(_countryType);
            request["Sort"]          = Convert.ToString(sortType);
            request["ItemPage"]      = itemPage.ToString();
            //request["MerchantId"] = "All";
            if (keyword != null)
            {
                request["Keywords"] = keyword;
            }

            return(GetResponse(request));
        }
        public async Task GetAvailableTypes()
        {
            var mockProxyService = new Mock <IAmazonProxyService>();
            IEnumerable <SearchIndexType> fakeTypes = new SearchIndexType[]
            {
                SearchIndexType.Apparel, SearchIndexType.Appliances, SearchIndexType.ArtsAndCrafts,
            };

            mockProxyService.Setup(x => x.AvailableTypesAsync(CountryType.Japan))
            .Returns(Task.Factory.StartNew(() => fakeTypes));

            var service = new AmazonDataService(CountryType.Japan,
                                                mockProxyService.Object, null, null, null);

            var types = await service.AvailableTypesAsync();

            Assert.IsNotNull(types);
            Assert.AreEqual(3, types.Count());
        }
Beispiel #7
0
        public Ranking GetRanking(SearchIndexType indexType)
        {
            var response = ItemSearch(indexType);
            var doc      = XDocument.Parse(response);
            var items    = doc.Descendants(ns + "Item")
                           //.Select(x => x.Element(ns + "ItemAttributes"))
                           .Select(x => new Item
            {
                ASIN          = x.GetValue("ASIN"),
                DetailPageURL = x.GetValue("DetailPageURL"),
                ItemLinks     = x.Descendants(ns + "ItemLink")
                                .Select(y => new ItemLink {
                    URL = y.GetValue("URL"), Description = y.GetValue("Description")
                }),
                SmallImageURL  = x.GetAttributesValue("SmallImage", "URL"),
                MediumImageURL = x.GetAttributesValue("MediumImage", "URL"),
                LargeImageURL  = x.GetAttributesValue("LargeImage", "URL"),
                Attributes     = new ItemAttributes
                {
                    Author          = x.GetAttributesValue("ItemAttributes", "Author"),
                    Format          = x.GetAttributesValue("ItemAttributes", "Format"),
                    Binding         = x.GetAttributesValue("ItemAttributes", "Binding"),
                    IsAdultProduct  = x.GetAttributesValue <bool>("ItemAttributes", "IsAdultProduct"),
                    ISBN            = x.GetAttributesValue("ItemAttributes", "ISBN"),
                    Label           = x.GetAttributesValue("ItemAttributes", "Label"),
                    Amount          = x.GetListPrice <int>("Amount"),
                    FormattedPrice  = x.GetListPrice <string>("FormattedPrice"),
                    Manufacturer    = x.GetAttributesValue("ItemAttributes", "Manufacturer"),
                    NumberOfPages   = x.GetAttributesValue <int>("ItemAttributes", "NumberOfPages"),
                    PublicationDate = x.GetAttributesValue <DateTime>("ItemAttributes", "PublicationDate"),
                    ReleaseDate     = x.GetAttributesValue <DateTime>("ItemAttributes", "ReleaseDate"),
                    Publisher       = x.GetAttributesValue("ItemAttributes", "Publisher"),
                    Title           = x.GetAttributesValue("ItemAttributes", "Title"),
                }
            });    //.ToArray();

            return(new Ranking {
                IndexType = SearchIndexType.Books, Items = items
            });
        }
Beispiel #8
0
        public string ItemSearch(CountryType countryType, SearchIndexType indexType, int itemPage = 1)
        {
            var cachePath = @"C:\amazon\cache";

            if (!Directory.Exists(cachePath))
            {
                Directory.CreateDirectory(cachePath);
            }

            var filepath = Path.Combine(cachePath, string.Format("{0}-{1}-{2}.cache", countryType, indexType, itemPage));

            lock (filepath)
            {
                try
                {
                    if (File.Exists(filepath))
                    {
                        var file = new FileInfo(filepath);
                        if (file.LastWriteTime.CompareTo(DateTime.Now.AddMinutes(-30)) > 0)
                        {
                            return(File.ReadAllText(filepath));
                        }
                        //File.Delete(filepath);
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }


            var client = new AmazonClient(countryType);

            var accessFilePath = Path.Combine(cachePath, @"last_access.txt");

            if (!File.Exists(accessFilePath))
            {
                File.WriteAllText(accessFilePath, DateTime.Now.ToString());
            }
            var lastAccessInfo = new FileInfo(accessFilePath);

            if (lastAccessInfo.LastWriteTime.CompareTo(DateTime.Now.AddSeconds(-1)) > 0)
            {
                Thread.Sleep(1000);
            }
            File.SetLastWriteTime(accessFilePath, DateTime.Now);
            var response = client.ItemSearch(indexType, itemPage: itemPage);

            lock (filepath)
            {
                try
                {
                    File.WriteAllText(filepath, response);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                    throw;
                }
            }

            return(response);
        }
Beispiel #9
0
        private static string ToBrowseNodeCanada(SearchIndexType indexType)
        {
            switch (indexType)
            {
            case SearchIndexType.Baby:
                return("3561346011");

            case SearchIndexType.Beauty:
                return("6205124011");

            case SearchIndexType.Books:
                return("927726");

            case SearchIndexType.Classical:
                return("962454");

            case SearchIndexType.DVD:
                return("14113311");

            case SearchIndexType.Electronics:
                return("677211011");

            case SearchIndexType.ForeignBooks:
                return("927726");

            case SearchIndexType.HealthPersonalCare:
                return("6205177011");

            case SearchIndexType.KindleStore:
                return("2972705011");

            case SearchIndexType.Kitchen:
                return("2206275011");

            case SearchIndexType.LawnGardern:
                return("6205499011");

            case SearchIndexType.Music:
                return("962454");

            case SearchIndexType.PetSupplies:
                return("6205514011");

            case SearchIndexType.Software:
                return("3234171");

            case SearchIndexType.SoftwareVideoGames:
                return("3323751");

            case SearchIndexType.VHS:
                return("962072");

            case SearchIndexType.Video:
                return("962454");

            case SearchIndexType.VideoGames:
                return("110218011");

            default:
                return(null);
            }
        }
Beispiel #10
0
        private static string ToBrowseNodeGermany(SearchIndexType indexType)
        {
            switch (indexType)
            {
            case SearchIndexType.Apparel:
                return("78689031");

            case SearchIndexType.Automotive:
                return("78191031");

            case SearchIndexType.Baby:
                return("357577011");

            case SearchIndexType.Beauty:
                return("64257031");

            case SearchIndexType.Books:
                return("541686");

            case SearchIndexType.Classical:
                return("542676");

            case SearchIndexType.DVD:
                return("547664");

            case SearchIndexType.Electronics:
                return("569604");

            case SearchIndexType.ForeignBooks:
                return("54071011");

            case SearchIndexType.Grocery:
                return("340846031");

            case SearchIndexType.HealthPersonalCare:
                return("64257031");

            case SearchIndexType.HomeGarden:
                return("10925241");

            case SearchIndexType.Jewelry:
                return("327473011");

            case SearchIndexType.KindleStore:
                return("530484031");

            case SearchIndexType.Kitchen:
                return("3169011");

            case SearchIndexType.Lighting:
                return("213083031");

            case SearchIndexType.Magazines:
                return("1161658");

            case SearchIndexType.MP3Downloads:
                return("77195031");

            case SearchIndexType.Music:
                return("542676");

            case SearchIndexType.MusicalInstruments:
                return("340849031");

            case SearchIndexType.OfficeProducts:
                return("192416031");

            case SearchIndexType.OutdoorLiving:
                return("10925051");

            case SearchIndexType.PCHardware:
                return("569604");

            case SearchIndexType.Photo:
                return("569604");

            case SearchIndexType.Software:
                return("542064");

            case SearchIndexType.SoftwareVideoGames:
                return("541708");

            case SearchIndexType.SportingGoods:
                return("16435121");

            case SearchIndexType.Toys:
                return("12950661");

            case SearchIndexType.VHS:
                return("547082");

            case SearchIndexType.Video:
                return("547664");

            case SearchIndexType.VideoGames:
                return("541708");

            case SearchIndexType.Watches:
                return("193708031");

            default:
                return(null);
            }
        }
Beispiel #11
0
        private static string ToBrowseNodeFrance(SearchIndexType indexType)
        {
            switch (indexType)
            {
            case SearchIndexType.Apparel:
                return("340855031");;

            case SearchIndexType.Automotive:
                return("1571265031");

            case SearchIndexType.Baby:
                return("206617031");

            case SearchIndexType.Beauty:
                return("197858031");

            case SearchIndexType.Books:
                return("468256");

            case SearchIndexType.Classical:
                return("537366");

            case SearchIndexType.DVD:
                return("578608");

            case SearchIndexType.Electronics:
                return("1058082");

            case SearchIndexType.ForeignBooks:
                return("69633011");

            case SearchIndexType.HealthPersonalCare:
                return("197861031");

            case SearchIndexType.HomeImprovement:
                return("590748031");

            case SearchIndexType.Jewelry:
                return("193711031");

            case SearchIndexType.KindleStore:
                return("818936031");

            case SearchIndexType.Kitchen:
                return("57686031");

            case SearchIndexType.Lighting:
                return("213080031");

            case SearchIndexType.MP3Downloads:
                return("206442031");

            case SearchIndexType.Music:
                return("537366");

            case SearchIndexType.MusicalInstruments:
                return("340862031");

            case SearchIndexType.OfficeProducts:
                return("192420031");

            case SearchIndexType.PetSupplies:
                return("1571268031");

            case SearchIndexType.Shoes:
                return("215934031");

            case SearchIndexType.Software:
                return("548012");

            case SearchIndexType.SoftwareVideoGames:
                return("548014");

            case SearchIndexType.Toys:
                return("548014");

            case SearchIndexType.VHS:
                return("578610");

            case SearchIndexType.Video:
                return("578608");

            case SearchIndexType.VideoGames:
                return("548014");

            case SearchIndexType.Watches:
                return("60937031");

            default:
                return(null);
            }
        }
Beispiel #12
0
        private static string ToBrowseNodeUK(SearchIndexType indexType)
        {
            switch (indexType)
            {
            case SearchIndexType.Apparel:
                return("83451031");

            case SearchIndexType.Automotive:
                return("248877031");

            case SearchIndexType.Baby:
                return("60032031");

            case SearchIndexType.Beauty:
                return("66280031");

            case SearchIndexType.Books:
                return("1025612");

            case SearchIndexType.Classical:
                return("505510");

            case SearchIndexType.DVD:
                return("283926");

            case SearchIndexType.Electronics:
                return("560800");

            case SearchIndexType.Grocery:
                return("340834031");

            case SearchIndexType.HealthPersonalCare:
                return("66280031");

            case SearchIndexType.HomeGarden:
                return("11052591");

            case SearchIndexType.HomeImprovement:
                return("2016929051");

            case SearchIndexType.Jewelry:
                return("193717031");

            case SearchIndexType.KindleStore:
                return("341677031");

            case SearchIndexType.Kitchen:
                return("11052591");

            case SearchIndexType.Lighting:
                return("213077031");

            case SearchIndexType.MP3Downloads:
                return("77198031");

            case SearchIndexType.Music:
                return("505510");

            case SearchIndexType.MusicalInstruments:
                return("340837031");

            case SearchIndexType.OfficeProducts:
                return("560800");

            case SearchIndexType.OutdoorLiving:
                return("11052591");

            case SearchIndexType.Software:
                return("1025614");

            case SearchIndexType.SoftwareVideoGames:
                return("1025616");

            case SearchIndexType.SportingGoods:
                return("319530011");

            case SearchIndexType.Tools:
                return("11052591");

            case SearchIndexType.Toys:
                return("712832");

            case SearchIndexType.VHS:
                return("283926");

            case SearchIndexType.Video:
                return("283926");

            case SearchIndexType.VideoGames:
                return("1025616");

            case SearchIndexType.Watches:
                return("595312");

            default:
                return(null);
            }
        }
Beispiel #13
0
        private static string ToBrowseNodeUS(SearchIndexType indexType)
        {
            switch (indexType)
            {
            case SearchIndexType.Apparel:
                return("1036592");

            case SearchIndexType.Appliances:
                return("2619525011");

            case SearchIndexType.ArtsAndCrafts:
                return("2617941011");

            case SearchIndexType.Automotive:
                return("15690151");

            case SearchIndexType.Baby:
                return("165796011");

            case SearchIndexType.Beauty:
                return("11055981");

            case SearchIndexType.Books:
                return("1000");

            case SearchIndexType.Classical:
                return("301668");

            case SearchIndexType.Collectibles:
                return("4991425011");

            case SearchIndexType.DigitalMusic:
                return("195208011");

            case SearchIndexType.DVD:
                return("2625373011");

            case SearchIndexType.Electronics:
                return("493964");

            case SearchIndexType.GourmetFood:
                return("3580501");

            case SearchIndexType.Grocery:
                return("16310101");

            case SearchIndexType.HealthPersonalCare:
                return("3760931");

            case SearchIndexType.HomeGarden:
                return("285080");

            case SearchIndexType.Industrial:
                return("228239");

            case SearchIndexType.Jewelry:
                return("3880591");

            case SearchIndexType.KindleStore:
                return("133141011");

            case SearchIndexType.Kitchen:
                return("1063498");

            case SearchIndexType.Magazines:
                return("599872");

            case SearchIndexType.Miscellaneous:
                return("10304191");

            case SearchIndexType.MobileApps:
                return("2350149011");

            case SearchIndexType.MP3Downloads:
                return("195211011");

            case SearchIndexType.Music:
                return("301668");

            case SearchIndexType.MusicalInstruments:
                return("11091801");

            case SearchIndexType.OfficeProducts:
                return("1084128");

            case SearchIndexType.OutdoorLiving:
                return("1063498");

            case SearchIndexType.PCHardware:
                return("493964");

            case SearchIndexType.PetSupplies:
                return("1063498");

            case SearchIndexType.Photo:
                return("493964");

            case SearchIndexType.Software:
                return("409488");

            case SearchIndexType.SportingGoods:
                return("3375251");

            case SearchIndexType.Tools:
                return("468240");

            case SearchIndexType.Toys:
                return("493964");

            case SearchIndexType.VHS:
                return("404272");

            case SearchIndexType.Video:
                return("130");

            case SearchIndexType.VideoGames:
                return("493964");

            case SearchIndexType.Watches:
                return("377110011");

            case SearchIndexType.Wireless:
                return("508494");

            case SearchIndexType.WirelessAccessories:
                return("13900851");

            default:
                return(null);
            }
        }
Beispiel #14
0
        public static string ToBrowseNodeJapan(SearchIndexType indexType)
        {
            switch (indexType)
            {
            case SearchIndexType.Apparel:
                return("361299011");

            case SearchIndexType.Appliances:
                return("2277724051");

            case SearchIndexType.Automotive:
                return("2017305051");

            case SearchIndexType.Baby:
                return("344845011");   //"13331821";

            case SearchIndexType.Beauty:
                return("52391051");

            case SearchIndexType.Books:
                return("465610");

            case SearchIndexType.Classical:
                return("562032");

            case SearchIndexType.DVD:
                return("562002");

            case SearchIndexType.Electronics:
                return("3210991");

            case SearchIndexType.ForeignBooks:
                return("52231011");

            case SearchIndexType.Grocery:
                return("57239051");

            case SearchIndexType.HealthPersonalCare:
                return("161669011");

            case SearchIndexType.Hobbies:
                return("2189355051");   //"13331821";

            case SearchIndexType.Jewelry:
                return("85896051");

            case SearchIndexType.KindleStore:
                return("2250738051");

            case SearchIndexType.Kitchen:
                return("3839151");

            case SearchIndexType.MP3Downloads:
                return("2128134051");

            case SearchIndexType.Music:
                return("562032");

            case SearchIndexType.MusicalInstruments:
                return("2123629051");

            case SearchIndexType.Shoes:
                return("2016926051");

            case SearchIndexType.Software:
                return("637630");

            case SearchIndexType.SportingGoods:
                return("14304371");

            case SearchIndexType.Toys:
                return("13299531");   //"13331821";

            case SearchIndexType.VHS:
                return("2130989051");

            //case SearchIndexType.Video:
            //    return "561972";
            case SearchIndexType.VideoGames:
                return("637872");

            case SearchIndexType.Watches:
                return("331952011");   //"324025011";

            default:
                return(null);
            }
        }
 public async Task <Ranking> LoadRanking(SearchIndexType type)
 {
     return(await _amazonDataService.GetRanking(type));
 }
Beispiel #16
0
 public async Task <string> ItemSearchAsync(CountryType countryType, SearchIndexType indexType, int itemPage)
 {
     return(await Task <string> .Factory.FromAsync(_client.BeginItemSearch,
                                                   _client.EndItemSearch,
                                                   countryType, indexType, itemPage, null));
 }