//This method works by checking whether the AmazonModel object(passed into the method's argument) is not null. If it is not null then it will check whether the Average rating attribute is not equal to 0. If it is
 //not equal to 0 then the average rating attribute along with the other atributes relating to amazon ratings will will be assigned to the relevant data attributes of the public BookModel object.
 private void SetAmazonRatings(AmazonModel amazonBookData)
 {
     if (amazonBookData != null)
     {
         if (amazonBookData.AverageRating != 0)
         {
             bookModel.AmazonFiveStarRatingPercentage  = amazonBookData.FiveStarRatingPercentage;
             bookModel.AmazonFourStarRatingPercentage  = amazonBookData.FourStarRatingPercentage;
             bookModel.AmazonThreeStarRatingPercentage = amazonBookData.ThreeStarRatingPercentage;
             bookModel.AmazonTwoStarRatingPercentage   = amazonBookData.TwoStarRatingPercentage;
             bookModel.AmazonOneStarRatingPercentage   = amazonBookData.OneStarRatingPercentage;
             bookModel.AmazonAverageRating             = amazonBookData.AverageRating;
         }
     }
 }
 //This method works by checking whether the AmazonModel object(passed into the method's argument) is not null. If it is not null then it will check whether the Reviews attribute is actually contains one or more reviews. If it does
 //then this will be assigned to the public BookModel object data attribute that holds the reviews. If it contains no reviews then an empty list of strings will be assigned to the public BookModel object data attribute that holds the reviews.
 //If the object is null then an empty list of strings will be assigned to the public BookModel object's data attribute that holds the reviews.
 private void SetAmazonReviews(AmazonModel amazonBookData)
 {
     if (amazonBookData != null)
     {
         if (amazonBookData.Reviews.Count != 0)
         {
             bookModel.AmazonReviews = amazonBookData.Reviews;
         }
         else
         {
             bookModel.AmazonReviews = new List <string>();
         }
     }
     else
     {
         bookModel.AmazonReviews = new List <string>();
     }
 }
 //This method works by checking whether the AmazonModel object(passed into the method's argument) is not null. If it is not null then it will check whether the Reviews count attribute is not equal to 0. If it does not equal to 0
 //then this  data value will be assigned to the public BookModel object data attribute that holds the Amazon reviews count. If it does equal 0 then assign a 0 to the same data attribute on the BookModel object. However, if
 //the AmazonModel object was null then assign a 0 to the same data attribute on the BookModel object.
 private void SetReviewCount(AmazonModel amazonBookData)
 {
     if (amazonBookData != null)
     {
         if (amazonBookData.ReviewCount != 0)
         {
             bookModel.AmazonReviewsCount = amazonBookData.ReviewCount;
         }
         else
         {
             bookModel.AmazonReviewsCount = 0;
         }
     }
     else
     {
         bookModel.AmazonReviewsCount = 0;
     }
 }
        //This method works by first checking with the data(passed into the method's argument) is an Isbn. If it is not an isbn number it will first collect book data from the Google books api and uses the output to retrieve the
        //isbn number and this is then used to get book data from the Goodreads api. If the data is an isbn number then get the book data from the Google books and Goodreads apis. Afterwards, it then uses the data retrieved from
        //the Goodreads api to initalise the GoodreadsModel. This model along with the GoogleBookModel is used to set the description to the BookModel object which involves working the Python text summariser to receive a
        //summarised description of the book which is what is assigned to the BookModel object. It then proceeds use the AmazonWebScraper to scrape the relevent book data from the relevent product page and this returns
        //and AmazonModel object. All three models( GoodreadsModel, GoogleBooksModel and AmazonModel) were used to initialise the attributes for the BookModel object.
        public async void CollectDataFromSources(string data)
        {
            bookModel = new BookModel();
            server    = new TCPServer();
            dominantColorWebScraper = new DominantColorWebScraper();
            amazonWebScraper        = new AmazonWebScraper();
            AmazonModel amazonBookData = null;

            IWebDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            //If the data doesnt contain the isbn then the isbn will be initially retrieved
            //from the google books api which is then passed into the good reads api solution
            var dataContainsIsbn = data.All(char.IsDigit);

            if (dataContainsIsbn.Equals(false))
            {
                googleBookTask = googleBookApi.CollectDataForBook(data);
                amazonTask     = amazonWebScraper.CollectDataForBook(driver, data);
                var isbn = GetIsbn(googleBookModel);
                goodreadsTask = goodreadsApi.SearchByIsbn(isbn);
            }
            else
            {
                googleBookTask = googleBookApi.CollectDataForBook(data);
                amazonTask     = amazonWebScraper.CollectDataForBook(driver, data);
                goodreadsTask  = goodreadsApi.SearchByIsbn(data);
            }

            Task.WhenAll(amazonTask, googleBookTask, goodreadsTask);

            googleBookModel = googleBookTask.Result;

            //Check if model has a valid thumbnail url
            if (googleBookModel.ThumbnailUrl.Count() > 2)
            {
                DominantColorWebScraper dominantColorWebScraper = new DominantColorWebScraper();
                var dominantColour = dominantColorWebScraper.GetDominantColor(driver, googleBookModel.ThumbnailUrl);
                dominantColorString = dominantColour;
            }

            var            book           = goodreadsTask.Result;
            GoodreadsModel goodreadsModel = null;

            if (book != null)
            {
                goodreadsModel = goodreadsApi.CollectDataForBook(book);
            }

            amazonBookData = amazonTask.Result;
            SetDescription(goodreadsModel, googleBookModel);

            SetBookTitle(goodreadsModel, googleBookModel);
            SetAuthorsOfBook(goodreadsModel, googleBookModel);

            SetAverageRatings(goodreadsModel, googleBookModel, amazonBookData);
            SetPageCount(goodreadsModel, googleBookModel);
            SetAmazonRatings(amazonBookData);
            SetAmazonReviews(amazonBookData);
            SetReviewCount(amazonBookData);
            SetGenres(googleBookModel);
            SetSubtitle(googleBookModel);
            SetIsbn(goodreadsModel, googleBookModel, data);
            SetThumbnailUrl(googleBookModel);
            SetDominantColor(dominantColorString);
        }
        //For each object passed into the method's arguments, it will check whether it is null. If it is not null then it further check to see if the object's attribute for holding the average rating is not equal to 0. If is does not equal
        //then it will assign this data value to the public BookModel object's corresponding data attribute.
        private void SetAverageRatings(GoodreadsModel goodreadsBookData, GoolgeBooksApi.GoogleBookModel googleBooksBookData, AmazonModel amazonBookData)
        {
            if (googleBooksBookData != null)
            {
                if (googleBooksBookData.AverageRating != 0)
                {
                    bookModel.GoogleBooksAverageRating = googleBooksBookData.AverageRating;
                }
            }

            if (goodreadsBookData != null)
            {
                if (goodreadsBookData.AverageRating != 0)
                {
                    bookModel.GoodreadsAverageRating = goodreadsBookData.AverageRating;
                }
            }

            if (amazonBookData != null)
            {
                if (amazonBookData.AverageRating != 0)
                {
                    bookModel.GoodreadsAverageRating = amazonBookData.AverageRating;
                }
            }
        }