public void ItemSearch() { var client = new AmazonClient(CountryType.Japan); var r = client.ItemSearch(SearchIndexType.Books); Console.WriteLine(r); }
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); }