// Convert this application to REST after the feature is integrated into WCF // private const string ENDPOINT = "https://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService"; // private const string NAMESPACE = "http://webservices.amazon.com/AWSECommerceService/2009-03-31"; public static void Main() { // Instantiate the two helpers var dbHandle = new DBHelper(MY_SQL_USERNAME, MY_SQL_PASSWORD, MY_SQL_DATASOURCE); var awsHandle = new AWSHelper(ENDPOINT, MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY, NAMESPACE); //SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); //builder.UserID = MY_SQL_USERNAME; //builder.Password = MY_SQL_PASSWORD; //builder.DataSource = MY_SQL_DATASOURCE; //var db = new Klib.KDbDataContext(builder.ConnectionString); //if (!db.DatabaseExists()) //{ // db.CreateDatabase(); // var p1 = new Klib.Person { FirstName = "A", LastName = "G", Location = "2028" }; // //Klib. // db.Persons.InsertOnSubmit(p1); // var res1 = new Klib.Resource(); // db.Resources.InsertOnSubmit(res1); // db.SubmitChanges(); // var book1 = new Klib.Book { Author = "Schildt", Title = "Java", Owner = p1.UID, UniqueMap = false, UID = res1.UID }; // db.Books.InsertOnSubmit(book1); // db.SubmitChanges(); //} var wbHandle = new ResourceWebsite.WebsiteBackend(dbHandle, awsHandle); var books = wbHandle.searchDBForBook("Java", "Schildt"); var person = wbHandle.searchDBForPerson("A", "G")[0]; wbHandle.borrowBookBy(books[0], person); //if (books == null) // Console.WriteLine("No books found!"); //else //{ // foreach (var book in books) // { // Console.WriteLine(book); // Console.WriteLine("Searching online"); // var results = wbHandle.searchOnlineMatches(book); // foreach (var result in results) // { // Console.WriteLine("Title:{0}\nAuthor:{2}\n ISBN:{1}", // result.ItemAttributes.Title, result.ItemAttributes.ISBN,result.ItemAttributes.Author[0]); // } // } //} //var results = awsHandle.Search("Harry Potter and the Chamber of Secrets", BOOK); //foreach (var result in results) //{ // Console.Out.WriteLine(result.ItemAttributes.ISBN); //} Console.ReadKey(); }
/// <summary> /// Resolves specified book to the givenm search Result /// </summary> /// <param name="book">Book object to update</param> /// <param name="item">Online result whose attributes to use</param> /// <remarks> /// Use the PreviousPageProperty to post objects from 1 page to another. /// Search for a book in DB, then get online results. /// Match one of those results to the book. /// </remarks> /// <see cref="searchOnlineMatches"/> public void resolveBookWithOnlineMatch(DBHelper.Book book, Klib.AWS.WSDL.Item item) { if (book.UniqueMap) throw new InvalidOperationException("Book already mapped!"); book.Author = ""; foreach (var author in item.ItemAttributes.Author) { book.Author += author + ", "; } book.Title = item.ItemAttributes.Title; book.UniqueMap = true; if (item.ItemAttributes.ISBN.Length == 10) book.ISBN10 = item.ItemAttributes.ISBN; else if (item.ItemAttributes.ISBN.Length == 13) book.ISBN13 = item.ItemAttributes.ISBN; //TODO : add code to update the book in the database. //book.updateFunction(); book.Update(); }
/// <summary> /// NOT WORKING /// </summary> /// <param name="book"></param> /// <param name="person"></param> public void returnBook(DBHelper.Book book, DBHelper.Person person) { book.Return(person); }
/// <summary> /// NOT WORKING /// </summary> /// <param name="book"></param> /// <param name="person"></param> public void borrowBookBy(DBHelper.Book book, DBHelper.Person person) { book.Borrow(person); }
public WebsiteBackend(DBHelper _dbHandle, AWSHelper _awsHandle) { this.awsHandle = _awsHandle; this.dbHandle = _dbHandle; }
/// <summary> /// Returns an array of Online books that match the current book /// </summary> /// <param name="book">A book object present in database. Obtain by using searchDBForBook.</param> /// <returns> possible online matches, null if already matched</returns> public Klib.AWS.WSDL.Item[] searchOnlineMatches(DBHelper.Book book) { if(book.UniqueMap) return null; //Throw exception instead? return awsHandle.Search(book.Title, book.Author, bookSearchType); }