/// <summary>
        /// Convert books xml nodes into books objects
        /// </summary>
        /// <param name="data">Books XML node list</param>
        /// <returns>A list of books objects</returns>
        public List <Book> ConvertXmlNodeListToObjects(XmlNodeList data)
        {
            try
            {
                BooksImportLog.Info("Start converting book data... ");

                var         listOfNodes = new List <XmlNode>(data.Cast <XmlNode>());
                List <Book> books       = new List <Book>();
                foreach (XmlNode listOfNode in listOfNodes)
                {
                    Book book = new Book();

                    //Extract book data from nodelist
                    this.ExtractISBN(listOfNode, ref book);

                    //Only add the book if the data is new
                    bool doNotUseHash;
                    bool.TryParse(Settings.GetSetting("OverrideOnixHashCheck"), out doNotUseHash);

                    var hashCode = CryptoHelper.GenerateMd5Hash(listOfNode.InnerText);
                    if (doNotUseHash || !OnixBooksSearchService.BookHasMatchingHashCode(book.ISBN, hashCode))
                    {
                        book.HashCode = hashCode;
                        this.ExtractTitle(listOfNode, ref book);
                        this.ExtractAuthor(listOfNode, ref book);
                        this.ExtractImprint(listOfNode, ref book);
                        this.ExtractPublisher(listOfNode, ref book);
                        this.ExtractMediaFile(listOfNode, ref book);
                        this.ExtractSeries(listOfNode, ref book);
                        this.ExtractIllustrators(listOfNode, ref book);
                        this.ExtractPageNumber(listOfNode, ref book);
                        this.ExtractAgeRange(listOfNode, ref book);
                        this.ExtractDescription(listOfNode, ref book);
                        this.ExtractPublishtionDate(listOfNode, ref book);
                        this.ExtractDimensionsAndWeight(listOfNode, ref book);
                        this.ExtractPrice(listOfNode, ref book);
                        this.ExtractFormat(listOfNode, ref book);
                        this.ExtractBICMainSubject(listOfNode, ref book);
                        this.ExtractBICSubjects(listOfNode, ref book);
                        this.ExtractPublisingStatus(listOfNode, ref book);
                        books.Add(book);
                    }
                }

                BooksImportLog.Info("End converting book data... ");
                BooksImportLog.Info("Books' objects generated: " + books.Count);

                return(books);
            }
            catch (Exception ex)
            {
                BooksImportLog.Error("There is an error when trying to convert xml formatted book data to an object. book data: " + data.ToString(), ex);
            }
            return(null);
        }
Esempio n. 2
0
        public static void UpdateAuthorActiveStatus()
        {
            var allAuthors = OnixAuthorsSearchService.GetAllAuthorSearchItems();
            var allBooks   = OnixBooksSearchService.GetBooks();

            foreach (var Author in allAuthors)
            {
                string authorSitecoreId        = Author.ItemId.ToString();
                var    IfHasRelatedActiveBooks = allBooks.Where(b => ((b.Authors != null && b.Authors.Contains(authorSitecoreId)) || (b.Illustrators != null && b.Illustrators.Contains(authorSitecoreId))) &&
                                                                (b.PublishStatus == "Forthcoming" || b.PublishStatus == "Active")).Any();
                if (IfHasRelatedActiveBooks)
                {
                    UpdateActiveStatusField(authorSitecoreId, IfHasRelatedActiveBooks);
                }
            }
        }
 /// <summary>
 /// Import books' data into sitecore and create new items
 /// </summary>
 /// <param name="books">Books obejcts generated from XML</param>
 public void ImportBookItemsToSitecore(List <Book> books)
 {
     ExistingBooks      = OnixBooksSearchService.GetAllBooksISBN();
     ExistingAuthors    = OnixAuthorsSearchService.GetAllAuthorsNames();
     ExistingPublishers = OnixPublishersSearchService.GetAllPublishersNames();
     ExistingSeries     = OnixSeriesSearchService.GetAllSeriesNames();
     foreach (var book in books)
     {
         try
         {
             string bookName = ItemNameHelper.RemoveSpecialCharacters(book.Title.TitleText);
             if (!ExistingBooks.Contains(book.ISBN))
             {
                 ExistingBooks.Add(book.ISBN);
                 this.CreateBookItemInSitecore(book, bookName);
             }
             else
             {
                 var bookSearchItem = OnixBooksSearchService.GetBookByIsbn(book.ISBN);
                 if (bookSearchItem != null)
                 {
                     Item bookItem = bookSearchItem.GetItemFromMasterDb();
                     if (bookItem != null)
                     {
                         BooksImportLog.Info(string.Format("Updating existing book [{0}] with item ID: {1}", book.Title.TitleText, bookItem != null ? bookItem.ID.ToString() : ""));
                         this.ExtractDataToBookItem(book, bookItem);
                     }
                 }
             }
             Thread.Sleep(100);
         }
         catch (Exception ex)
         {
             BooksImportLog.Error("There is an error when trying to import book " + book.Title.TitleText + " in the loop", ex);
         }
     }
 }