Exemple #1
0
        private void button_Click_2(object sender, RoutedEventArgs e)//add from open library
        {
            string  isbn = txtIsbn.Text.Replace("-", "");
            Book    b    = new Book();
            Boolean okay = b.ISBN_Cheker(isbn);//check isbn is valid

            if (okay)
            {
                BookData bd   = new BookData();
                OLBook   book = bd.AccessOpenLibrary(isbn);
                if (book.title != null)//if a book was found
                {
                    txtTitle.Text  = book.title;
                    txtAuthor.Text = book.authors[0].name;
                    if (book.edition_name != null)//if edition was included in json
                    {
                        txtEdition.Text = book.edition_name.Replace("edition", "").Replace("Edition", "").Replace("ed.", "");
                    }
                }
            }
            else
            {
                MessageBox.Show("Invalid ISBN-10. Try again.");
            }
        }
Exemple #2
0
        public OLBook convertToOLBook(string data, string isbn)//this takes the json and makes an OLBook object
        {
            JObject       rawbook = JObject.Parse(data);
            List <JToken> tokens  = rawbook[string.Format("ISBN:{0}", isbn)].Children().ToList();
            OLBook        book    = new OLBook();

            foreach (var token in tokens)
            {
                if (token.ToString().Contains("\"details\""))//this section contains the details about the book
                {
                    List <JToken> t = token.Children().ToList();
                    book = t.First().ToObject <OLBook>();
                    return(book);
                }
            }
            return(book);
        }
Exemple #3
0
        public OLBook AccessOpenLibrary(string isbn)//this will take a given isbn number and check it against open library
        {
            OLBook    book = new OLBook();
            WebClient wc   = new WebClient();
            string    path = string.Format(@"https://openlibrary.org/api/books?bibkeys=ISBN:{0}&jscmd=details&format=json", isbn);
            //connect to api
            string data = wc.DownloadString(path);

            if (data == "{}")//if openlibrary doesn't have the book
            {
                MessageBox.Show("No results found on OpenLibrary.");
            }
            else
            {
                return(convertToOLBook(data, isbn));
            }
            return(book);
        }