private void ExtractDimensionsAndWeight(XmlNode listOfNode, ref Book book) { try { Dimensions dimensions = new Dimensions(); var MeasureNodes = listOfNode.SelectNodes(MeasureNodeName); var listOfMeasureNodes = new List <XmlNode>(MeasureNodes.Cast <XmlNode>()); var HeightNode = listOfMeasureNodes.SingleOrDefault(i => i.SelectSingleNode(MeasureTypeCodeNodeName) != null && i.SelectSingleNode(MeasureTypeCodeNodeName).InnerText == HeightTypeCode && i.SelectSingleNode(MeasureUnitCodeNodeName) != null && i.SelectSingleNode(MeasureUnitCodeNodeName).InnerText == MeasureUnitCodeWidth); if (HeightNode != null) { dimensions.Height = HeightNode.SelectSingleNode(MeasurementName).InnerText; } var WidthNode = listOfMeasureNodes.SingleOrDefault(i => i.SelectSingleNode(MeasureTypeCodeNodeName) != null && i.SelectSingleNode(MeasureTypeCodeNodeName).InnerText == WidthCode && i.SelectSingleNode(MeasureUnitCodeNodeName) != null && i.SelectSingleNode(MeasureUnitCodeNodeName).InnerText == MeasureUnitCodeWidth); if (WidthNode != null) { dimensions.Width = WidthNode.SelectSingleNode(MeasurementName).InnerText; } book.Dimensions = dimensions; //extract weight var WeightNode = listOfMeasureNodes.SingleOrDefault(i => i.SelectSingleNode(MeasureTypeCodeNodeName) != null && i.SelectSingleNode(MeasureTypeCodeNodeName).InnerText == WeightTypeNode && i.SelectSingleNode(MeasureUnitCodeNodeName) != null && i.SelectSingleNode(MeasureUnitCodeNodeName).InnerText == MeasureUnitCodeWeight); if (WeightNode != null) { book.Weight = WeightNode.SelectSingleNode(MeasurementName).InnerText; } } catch (Exception ex) { BooksImportLog.Error("Extract Dimensions and weight data failed. Node data: " + listOfNode.ToString(), ex); } }
/// <summary> /// populate Series data with the Series object into sitecore /// </summary> /// <param name="series">Series object generated from XML</param> /// <param name="SeriesItem">Sitecore Series item</param> private void populateSeriesItemData(Series series, Item SeriesItem, Item publisherGroupOwner) { SeriesItem.Editing.BeginEdit(); try { SeriesItem.Fields["SeriesName"].Value = series.Name; SeriesItem.Fields["MetaTitle"].Value = string.Format("{0} | Hardie Grant Publishing", series.Name); if (string.IsNullOrWhiteSpace(SeriesItem.Fields["MetaDescription"].Value)) { SeriesItem.Fields["MetaDescription"].Value = string.Format("{0}{1} | Hardie Grant Publishing", publisherGroupOwner == null ? "" : (string.IsNullOrWhiteSpace(publisherGroupOwner["Name"]) ? "" : string.Format("A {0} series: ", publisherGroupOwner["Name"])), series.Name); } if (!((Sitecore.Data.Fields.CheckboxField)SeriesItem.Fields["DisableOverridePublishingGroupOwner"]).Checked) { if (publisherGroupOwner != null) { SeriesItem.Fields["PublishingGroupOwner"].Value = publisherGroupOwner.ID.ToString(); } } SeriesItem.Fields["MetaKeywords"].Value = string.Format("{0},{1},Hardie Grant Publishing", series.Name, publisherGroupOwner); } catch (Exception ex) { BooksImportLog.Error("There is an error when trying to populate data for Series " + series.DisplayName + "into item" + SeriesItem.ID.ToString(), ex); } finally { SeriesItem.Editing.EndEdit(); } }
/// <summary> /// Read Data from XML /// </summary> /// <returns>Books XML node list</returns> public XmlNodeList ReadBookDataFromXmlFeed(string xmlFilePath, bool loadFromLocal) { string ftpServerXmlFilePath = string.Format("{0}/{1}", ftpServerPath, xmlFilePath); try { BooksImportLog.Info("Start reading book data from " + ftpServerXmlFilePath); XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; if (loadFromLocal) { GenerateXmlDocFromLocalFile(xmlFilePath, xmldoc); } else { GenerateXmlDocFromFtp(ftpServerXmlFilePath, xmldoc); } xmlnode = xmldoc.GetElementsByTagName(ExtractingElmentTagName); BooksImportLog.Info("End reading book data...."); BooksImportLog.Info("Books' nodes got from xml: " + xmlnode.Count); return(xmlnode); } catch (Exception ex) { BooksImportLog.Error("There is an error when trying to geting data from " + ftpServerXmlFilePath, ex); } return(null); }
private void ExtractSeries(XmlNode listOfNode, ref Book book) { try { var SeriesNode = listOfNode.SelectSingleNode(SerieNodeName); if (SeriesNode != null) { Series series = new Series(); var SeriesNameNode = SeriesNode.SelectSingleNode(SerieNameNodeName); if (SeriesNameNode != null) { series.Name = SeriesNameNode.InnerText; } var SeriesNumberNode = SeriesNode.SelectSingleNode(SerieNumberNodeName); if (SeriesNumberNode != null) { book.SeriesNumeber = SeriesNumberNode.InnerText; } book.Series = series; } } catch (Exception ex) { BooksImportLog.Error("Extract Series data failed. Node data: " + listOfNode.ToString(), ex); } }
/// <summary> /// Create a sigle Series item in sitecore /// </summary> /// <param name="series">Series object generated from XML</param> private ID CreateSeriesItemInSitecore(Series series, Item publisherGroupOwner) { try { using (new SecurityDisabler()) { Database masterDb = Sitecore.Configuration.Factory.GetDatabase(sitecoreMasterDatabaseName); //Item SeriesFolderItem = masterDb.GetItem(SeriesFolderItemId); //TemplateItem SeriesItemTemplate = masterDb.GetTemplate(SeriesItemTemplateId); //Item SeriesItem = SeriesFolderItem.Add(series.DisplayName.Trim(), SeriesItemTemplate); //Item SeriesItemTemplate = masterDb.GetItem(SeriesItemTemplateId); //Item SeriesFolderItem = masterDb.GetItem(SeriesFolderItemId); //BranchItem SeriesBranchItem = masterDb.GetItem(SeriesItemTemplate.ID); //Item SeriesItem = SeriesFolderItem.Add(series.DisplayName.Trim(), SeriesBranchItem); Item SeriesItem = SitecoreCreationHelper.CreateBranchItem(series.DisplayName, masterDb, SeriesItemTemplateId, SeriesFolderItemId); return(ExtractDataFromAuhorObject(series, SeriesItem, publisherGroupOwner)); } } catch (Exception ex) { BooksImportLog.Error("There is an error when trying to import Series " + series.DisplayName, ex); } return(null); }
/// <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); }
/// <summary> /// Import Authors' data into sitecore and create new items /// </summary> /// <param name="authos">Authors obejcts generated from XML</param> public void ImportAuthorsItemsToSitecore(ContributorType contributorType, ref Book book, ref List <string> ExistingAuthors, Item publisherGroupOwner) { List <Author> contributors = new List <Author>(); contributors = contributorType == ContributorType.Author ? book.Authors : book.Illustrators; for (int i = 0; i < contributors.Count; i++) { if (!ExistingAuthors.Contains(contributors[i].DisplayName.Replace(" ", "-"))) { ExistingAuthors.Add(contributors[i].DisplayName.Replace(" ", "-")); ID id = this.CreateAuthorItemInSitecore(contributors[i], contributorType, publisherGroupOwner); if (!ID.IsNullOrEmpty(id)) { contributors[i].SitecoreID = id.ToString(); } } else { Item authorItem = masterDb.GetItem(authorFolderItemId).Axes.GetDescendants().FirstOrDefault(c => c.Name == contributors[i].DisplayName.Replace(" ", "-")); BooksImportLog.Info(string.Format("Updating existing author [{0}] with item ID: {1}", contributors[i].DisplayName, authorItem != null ? authorItem.ID.ToString() : "")); this.ExtractDataFromAuthorObject(contributors[i], contributorType, authorItem, publisherGroupOwner); ID id = authorItem.ID; contributors[i].SitecoreID = id.ToString(); if (!authorItem.Fields["ContributorType"].Value.Contains(contributorType.ToString())) { authorItem.Editing.BeginEdit(); try { authorItem.Fields["ContributorType"].Value += string.Format(",{0}", contributorType.ToString()); } catch (Exception ex) { BooksImportLog.Error("There is an error when trying to populate data for author " + contributors[i].DisplayName + "into item" + authorItem.ID.ToString(), ex); } finally { authorItem.Editing.EndEdit(); BooksImportLog.Info(string.Format("Populated data for author [{0}] with item ID: {1}", contributors[i].DisplayName, authorItem != null ? authorItem.ID.ToString() : "")); } } } Thread.Sleep(100); } if (contributorType == ContributorType.Author) { book.Authors = contributors; } else { book.Illustrators = contributors; } }
public void Process() { importRunning = true; try { BookXmlTransformHelper _xmlHelper = new BookXmlTransformHelper(); BookSitecoreItemCreationHelper _bookSitecoreHelper = new BookSitecoreItemCreationHelper(); List <string> newFtpFiles = new List <string>(); bool loadFromLocal; bool.TryParse(Sitecore.Configuration.Settings.GetSetting("LoadOnixFeedFromLocal"), out loadFromLocal); if (loadFromLocal) { string localXmlFilePath = System.Web.Hosting.HostingEnvironment.MapPath("~/upload/" + xmlFilePathLocal); newFtpFiles.Add(localXmlFilePath); } else { List <string> ftpFiles = _xmlHelper.GetListOfExistingFilesNames(); newFtpFiles = _xmlHelper.GetNewFtpFiles(isImportFullVersion, ftpFiles); } if (newFtpFiles != null && newFtpFiles.Count > 0) { foreach (string newFtpFile in newFtpFiles) { BooksImportLog.Info("----------------START BOOK FULL IMPORT SERVICE---------------"); BooksImportLog.Info("Start getting books' data....."); XmlNodeList data = _xmlHelper.ReadBookDataFromXmlFeed(newFtpFile, loadFromLocal); List <Book> books = _xmlHelper.ConvertXmlNodeListToObjects(data); BooksImportLog.Info("End getting books' data....."); BooksImportLog.Info("Start creating books' items in Sitecore....."); _bookSitecoreHelper.ImportBookItemsToSitecore(books); BooksImportLog.Info("End creating books' items in Sitecore....."); //_xmlHelper.DeleteProcessFtpFiles(newFtpFile); //_xmlHelper.MoveProcessedFtpFiles(newFtpFile, FTPFullVersionArchivesFolderName); } } BooksImportLog.Info("Start updating authors' active statuses....."); AuthorSitecoreItemCreationHelper.UpdateAuthorActiveStatus(); BooksImportLog.Info("End updating authors' active statuses....."); BooksImportLog.Info("-----------------END BOOK FULL IMPORT SERVICE---------------"); } catch (Exception ex) { BooksImportLog.Error(ex.Message); } importRunning = false; }
public void Run() { // This is pointless as this isn't a singleton - a new instance will be created by the Task runner each time. if (!importRunning) { Process(); } else { BooksImportLog.Info("/*** Book Data Changed file Import skipped as the previous import has yet to complete : " + DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss") + " ***\\"); } }
private void ExtractMediaFile(XmlNode listOfNode, ref Book book) { try { if (!string.IsNullOrWhiteSpace(book.ISBN)) { book.MediaFileLink = string.Format("{0}/{1}/{2}", OnixBookCoverImageBaseUrl, book.ISBN, OnixBookCoverImageSize); } } catch (Exception ex) { BooksImportLog.Error("Extract Media data failed. Node data: " + listOfNode.ToString(), ex); } }
public void MoveProcessedFtpFiles(string processedFile, string newDirectory) { try { var req = (FtpWebRequest)WebRequest.Create(ftpServerPath + "/" + processedFile); req.Credentials = new NetworkCredential(userId, password); req.Method = WebRequestMethods.Ftp.Rename; req.RenameTo = newDirectory + "/" + processedFile; req.GetResponse().Close(); } catch (Exception ex) { BooksImportLog.Error(string.Format("Move the ftp file {0} to {1} folder failed.", processedFile, newDirectory), ex); } }
public void Run() { if (DateTime.Now.Day != 1 && !Sitecore.Context.User.IsAdministrator) { return; } // This is pointless as this isn't a singleton - a new instance will be created by the Task runner each time. if (!importRunning) { Process(); } else { BooksImportLog.Info("/*** Book Data Full Import skipped as the previous import has yet to complete : " + DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss") + " ***\\"); } }
/// <summary> /// Create a sigle book item in sitecore /// </summary> /// <param name="book">Book object generated from XML</param> private void CreateBookItemInSitecore(Book book, string bookName) { try { using (new SecurityDisabler()) { Item bookItem = SitecoreCreationHelper.CreateBranchItem(bookName, masterDb, bookItemTemplateId, booksBucketItemId); BooksImportLog.Info(string.Format("Created new book [{0}] with item ID: {1}", book.Title.TitleText, bookItem != null ? bookItem.ID.ToString() : "")); this.ExtractDataToBookItem(book, bookItem); } } catch (Exception ex) { BooksImportLog.Error("There is an error when trying to import book (new) " + book.Title.TitleText, ex); } }
private void CreateFormatItemInSitecore(Format Format) { try { using (new SecurityDisabler()) { Item FormatListFolderItem = masterDb.GetItem(FormatListFolderItemId); TemplateItem FormatItemTemplate = masterDb.GetTemplate(FormatItemTemplateId); Item formatItem = FormatListFolderItem.Add(Format.Code.Replace("�", "").Replace("?", "").Trim(), FormatItemTemplate); Format.PopulateData(ref formatItem); } } catch (Exception ex) { BooksImportLog.Error("There is an error when trying to import Format " + Format.Code, ex); } }
private void ExtractImprint(XmlNode listOfNode, ref Book book) { try { var Imprints = listOfNode.SelectNodes(ImprintNodeName); var listOfImprints = new List <XmlNode>(Imprints.Cast <XmlNode>()); var imprintNode = listOfImprints.SingleOrDefault(i => i.SelectSingleNode(NameCodeTypeNodeName).InnerText == ImprintRoleCode); if (imprintNode != null) { book.ImprintName = imprintNode.SelectSingleNode(ImprintNameNodeName).InnerText; } } catch (Exception ex) { BooksImportLog.Error("Extract Imprint data failed. Node data: " + listOfNode.ToString(), ex); } }
private void ExtractISBN(XmlNode listOfNode, ref Book book) { try { var ids = listOfNode.SelectNodes(productIdentifierNodeName); var listOfIds = new List <XmlNode>(ids.Cast <XmlNode>()); var isbnNode = listOfIds.SingleOrDefault(i => i.SelectSingleNode(productIDTypeNodeName).InnerText == ISBNRoleCode); if (isbnNode != null) { book.ISBN = isbnNode.SelectSingleNode(idValueNodeName).InnerText; } } catch (Exception ex) { BooksImportLog.Error("Extract ISBN data failed. Node data: " + listOfNode.ToString(), ex); } }
private void ExtractFormat(XmlNode listOfNode, ref Book book) { try { var FormatNode = listOfNode.SelectSingleNode(FormatNodeName); if (FormatNode != null) { if (FormatNode != null) { book.Format = FormatNode.InnerText; } } } catch (Exception ex) { BooksImportLog.Error("Extract Format data failed. Node data: " + listOfNode.ToString(), ex); } }
private void ExtractPublisingStatus(XmlNode listOfNode, ref Book book) { try { var publishingStatus = listOfNode.SelectSingleNode("PublishingStatus"); if (publishingStatus != null) { if (publishingStatus != null) { book.PublishStatus = PublishingStatus.GetPublishStatus(publishingStatus.InnerText); } } } catch (Exception ex) { BooksImportLog.Error("Extract publishing status data failed. Node data: " + listOfNode.ToString(), ex); } }
private static void UpdateActiveStatusField(string sitecoreId, bool isActive) { Item authorItem = masterDb.GetItem(sitecoreId); authorItem.Editing.BeginEdit(); try { ((CheckboxField)authorItem.Fields["HasActivedBooks"]).Checked = isActive; } catch (Exception ex) { BooksImportLog.Error("There is an error when trying to set active status for author " + sitecoreId + "into item" + authorItem.ID.ToString(), ex); } finally { authorItem.Editing.EndEdit(); } }
public void DeleteProcessFtpFiles(string processedFile) { try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServerPath + "/" + processedFile); request.Method = WebRequestMethods.Ftp.DeleteFile; request.Credentials = new NetworkCredential(userId, password); using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) { BooksImportLog.Info(string.Format("Delete the ftp file: {0} with status {1}", processedFile, response.StatusDescription)); } } catch (Exception ex) { BooksImportLog.Error(string.Format("Delete the ftp file {0} failed.", processedFile), ex); } }
private void ExtractPageNumber(XmlNode listOfNode, ref Book book) { try { var pageNumberNode = listOfNode.SelectSingleNode(PageNumberNodeName); if (pageNumberNode != null) { if (pageNumberNode != null) { book.PageNumber = pageNumberNode.InnerText; } } } catch (Exception ex) { BooksImportLog.Error("Extract Page number data failed. Node data: " + listOfNode.ToString(), ex); } }
private void PopulateGroupedBICCateData(List <BICCategory> BICCategories, Item categoryFolderItem, string categoryType) { List <Item> categoryItems = null; List <string> IDs = new List <string>(); if (categoryType == "HGB") { categoryItems = categoryFolderItem.Children.Where(c => BICCategories.First().HGBCategory.Contains(c["Name"])).ToList(); } else { categoryItems = categoryFolderItem.Children.Where(c => BICCategories.First().HGTCategory.Contains(c["Name"])).ToList(); } IDs = BICCategories.Select(b => b.SitecoreId.ToString()).ToList(); foreach (var categoryItem in categoryItems) { categoryItem.Editing.BeginEdit(); try { if (IDs.Count > 0) { MultilistField ild = (MultilistField)categoryItem.Fields["Mapped BIC Categories"]; if (string.IsNullOrWhiteSpace(ild.Value)) { ild.Value = string.Join("|", IDs); } else { ild.Value += "|" + string.Join("|", IDs); } } } catch (Exception ex) { BooksImportLog.Error("There is an error when trying to populate category data for hg categories " + BICCategories.First().HGBCategory + "into item" + categoryItem.ID.ToString(), ex); } finally { categoryItem.Editing.EndEdit(); } } }
/// <summary> /// Create a sigle author item in sitecore /// </summary> /// <param name="author">Author object generated from XML</param> private ID CreateAuthorItemInSitecore(Author author, ContributorType contributorType, Item publisherGroupOwner) { try { using (new SecurityDisabler()) { Item authorItem = SitecoreCreationHelper.CreateBranchItem(author.DisplayName, masterDb, authorItemTemplateId, authorFolderItemId); BooksImportLog.Info(string.Format("Created new author [{0}] with item ID: {1}", author.PersonNameInverted, authorItem != null ? authorItem.ID.ToString() : "")); this.ExtractDataFromAuthorObject(author, contributorType, authorItem, publisherGroupOwner); return(authorItem.ID); } } catch (Exception ex) { BooksImportLog.Error("There is an error when trying to import author " + author.PersonNameInverted, ex); return(null); } }
private void ExtractPublishtionDate(XmlNode listOfNode, ref Book book) { try { var PubishionDateNode = listOfNode.SelectSingleNode(PubishtionDateNodeName); if (PubishionDateNode != null) { if (PubishionDateNode != null) { book.PubDate = DateTime.ParseExact(PubishionDateNode.InnerText, "yyyyMMdd", CultureInfo.InvariantCulture); } } } catch (Exception ex) { BooksImportLog.Error("Extract publish date data failed. Node data: " + listOfNode.ToString(), ex); } }
/// <summary> /// populate author data with the author object into sitecore /// </summary> /// <param name="author">Author object generated from XML</param> /// <param name="authorItem">Sitecore author item</param> private void populateAuthorItemData(Author author, Item authorItem, ContributorType contributorType, Item publisherGroupOwner) { authorItem.Editing.BeginEdit(); try { authorItem.Fields["KeyNames"].Value = author.KeyNames; authorItem.Fields["NamesBeforeKey"].Value = author.NamesBeforeKey; authorItem.Fields["PersonName"].Value = author.PersonName; authorItem.Fields["PersonNameInverted"].Value = author.PersonNameInverted; authorItem.Fields["BiographicalNote"].Value = HtmlHelper.RemoveHtmlTags(author.BiographicalNote, new List <string> { "div", "span" }); if (!((Sitecore.Data.Fields.CheckboxField)authorItem.Fields["DisableOverridePublishingGroupOwner"]).Checked) { if (publisherGroupOwner != null) { authorItem.Fields["PublishingGroupOwner"].Value = publisherGroupOwner.ID.ToString(); } } authorItem.Fields["ContributorType"].Value = contributorType.ToString(); authorItem.Fields["CorporateName"].Value = author.CorporateName; authorItem.Fields["MetaTitle"].Value = string.Format("{0} | Hardie Grant Publishing", string.IsNullOrWhiteSpace(author.PersonName) ? author.CorporateName : author.PersonName); authorItem.Fields["MetaDescription"].Value = string.Format("{0} | {1} Hardie Grant Publishing", string.IsNullOrWhiteSpace(author.PersonName) ? author.CorporateName : author.PersonName, string.IsNullOrWhiteSpace(author.BiographicalNote) ? "" : getFormattedAuthorDescription(author.BiographicalNote) + "|"); authorItem.Fields["MetaKeywords"].Value = string.Format("{0}, {1}, Hardie Grant Publishing", string.IsNullOrWhiteSpace(author.PersonName) ? author.CorporateName : author.PersonName, publisherGroupOwner == null ? "" : publisherGroupOwner["Name"]); } catch (Exception ex) { BooksImportLog.Error("There is an error when trying to populate data for author " + author.DisplayName + "into item" + authorItem.ID.ToString(), ex); } finally { authorItem.Editing.EndEdit(); BooksImportLog.Info(string.Format("Updated data for author [{0}] with item ID: {1}", author.DisplayName, authorItem != null ? authorItem.ID.ToString() : "")); } }
private void ExtractPublisher(XmlNode listOfNode, ref Book book) { try { var publishers = listOfNode.SelectNodes(PublisherNodeName); var listOfPublishers = new List <XmlNode>(publishers.Cast <XmlNode>()); var publisherNode = listOfPublishers.SingleOrDefault(i => i.SelectSingleNode(PublishingRoleNodeName).InnerText == PublishingRoleCode); if (publisherNode != null) { book.Publisher = new Publisher() { Name = publisherNode.SelectSingleNode(PublisherNameNodeName).InnerText, }; book.Publisher.GroupItem = book.Publisher.GetGroupItem(HGBPublisherGroupItem, HGEPublisherGroupItem, HGTPublisherGroupItem); } } catch (Exception ex) { BooksImportLog.Error("Extract Publisher data failed. Node data: " + listOfNode.ToString(), ex); } }
private void ExtractBICMainSubject(XmlNode listOfNode, ref Book book) { try { var BICMainSubjectNode = listOfNode.SelectSingleNode(BICMainSubjectNodeName); if (BICMainSubjectNode != null) { if (BICMainSubjectNode != null) { book.Category = new Category() { MainBICCategoryName = BICMainSubjectNode.InnerText }; } } } catch (Exception ex) { BooksImportLog.Error("Extract BICMainSubject data failed. Node data: " + listOfNode.ToString(), ex); } }
public void Process() { importRunning = true; try { BookXmlTransformHelper _xmlHelper = new BookXmlTransformHelper(); BookSitecoreItemCreationHelper _bookSitecoreHelper = new BookSitecoreItemCreationHelper(); List <string> ftpFiles = _xmlHelper.GetListOfExistingFilesNames(); List <string> newFtpFiles = _xmlHelper.GetNewFtpFiles(isImportFullVersion, ftpFiles); if (newFtpFiles != null && newFtpFiles.Count > 0) { BooksImportLog.Info("----------------START BOOK CHANGED FILE IMPORT SERVICE---------------"); foreach (string newFtpFile in newFtpFiles) { BooksImportLog.Info("Start getting books' data....."); XmlNodeList data = _xmlHelper.ReadBookDataFromXmlFeed(newFtpFile, false); List <Book> books = _xmlHelper.ConvertXmlNodeListToObjects(data); BooksImportLog.Info("End getting books' data....."); BooksImportLog.Info("Start creating books' items in Sitecore....."); _bookSitecoreHelper.ImportBookItemsToSitecore(books); BooksImportLog.Info("End creating books' items in Sitecore....."); //_xmlHelper.DeleteProcessFtpFiles(newFtpFile); //_xmlHelper.MoveProcessedFtpFiles(newFtpFile, FTPChangingVersionArchivesFolderName); } } BooksImportLog.Info("Start updating authors' active statuses....."); AuthorSitecoreItemCreationHelper.UpdateAuthorActiveStatus(); BooksImportLog.Info("End updating authors' active statuses....."); BooksImportLog.Info("-----------------END BOOK CHANGED FILE IMPORT SERVICE---------------"); } catch (Exception ex) { BooksImportLog.Error(ex.Message); } importRunning = false; }
private void ExtractPrice(XmlNode listOfNode, ref Book book) { try { var SupplyDetailNode = listOfNode.SelectSingleNode(SupplyDetailNodeName); if (SupplyDetailNode != null) { var PriceNodes = SupplyDetailNode.SelectNodes(PriceNodeName); var listOfMeasureNodes = new List <XmlNode>(PriceNodes.Cast <XmlNode>()); var AUDPriceNode = listOfMeasureNodes.SingleOrDefault(i => i.SelectSingleNode(CurrencyCodeNodeName).InnerText == CurrencyCode); if (AUDPriceNode != null) { book.Price = AUDPriceNode.SelectSingleNode(PriceAmountNodeName).InnerText; } } } catch (Exception ex) { BooksImportLog.Error("Extract Price data failed. Node data: " + listOfNode.ToString(), ex); } }
private void ExtractBICSubjects(XmlNode listOfNode, ref Book book) { try { book.BICCategories = new List <string>(); var bigCategories = listOfNode.SelectNodes(SubjectNodeName); var listOfBigCategories = new List <XmlNode>(bigCategories.Cast <XmlNode>()); var BigCategoryNodes = listOfBigCategories.Where(i => i.SelectSingleNode(SubjectSchemeIdentifierNodeName).InnerText == BICCategoryIdentifierCodeNodeName); if (BigCategoryNodes != null && BigCategoryNodes.Count() > 0) { foreach (var BigCategoryNode in BigCategoryNodes) { book.BICCategories.Add(BigCategoryNode.SelectSingleNode(SubjectCodeNodeName).InnerText); } } } catch (Exception ex) { BooksImportLog.Error("Extract BIGData failed. Node data: " + listOfNode.ToString(), ex); } }