private List <MallItem> CreateAndGetMalls(string showInMalls, ImportItemsArgs args) { var separator = new[] { args.ImportOptions.MultipleValuesImportSeparator }; var mallValues = showInMalls != null ? showInMalls.Split(separator, StringSplitOptions.RemoveEmptyEntries) : new string[] { }; List <MallItem> result = new List <MallItem>(); foreach (var value in mallValues) { if (value != Constants.NAMall) { var mallEnum = Enum.GetValues(typeof(Malls)).Cast <Malls>().FirstOrDefault(x => ((int)x).ToString() == value); var mallName = mallEnum.ToString() != Constants.NAMall ? mallEnum.GetDescription() : string.Empty; var countMallInList = result.Where(x => x.MallName == mallName); if (!countMallInList.Any()) { var mallItem = args.MallItems.FirstOrDefault(x => x.MallName == mallName); if (mallItem != null) { result.Add(mallItem); } } } } return(result); }
private string CreateAndGetStoreCategoryId(string category, ImportItemsArgs args) { var separator = new[] { args.ImportOptions.MultipleValuesImportSeparator }; var categoryValues = category != null ? category.Split(separator, StringSplitOptions.RemoveEmptyEntries) : new string[] { }; StringBuilder result = new StringBuilder(); foreach (var value in categoryValues) { var categoryEnum = Enum.GetValues(typeof(StoreCategory)).Cast <StoreCategory>().FirstOrDefault(x => ((int)x).ToString() == value); var categoryName = categoryEnum.ToString(); var categoryDisplayName = categoryEnum.GetDescription(); var templateItem = args.Database.GetTemplate(Templates.StoreCategories.ID); //get the parent in the specific language Item parent = args.Database.GetItem(Templates.StoreCategories.GlobalRoot); var newItem = CreateItem(parent, categoryName, categoryDisplayName, templateItem, args); if (string.IsNullOrEmpty(result.ToString())) { result.Append(newItem.ID.ToString()); } else { result.Append("|" + newItem.ID.ToString()); } } return(result.ToString()); }
private void UpdateContactUsEachMall(Item mallItem, DataTable dataTable, ImportItemsArgs args) { using (new EditContext(mallItem, true, false)) { var dataRow = dataTable.AsEnumerable().FirstOrDefault(row => row[ContactUsInputField.Mall.ToString()].ToString().Equals(mallItem.Name, StringComparison.OrdinalIgnoreCase)); if (dataRow != null) { mallItem.Fields[ContactUsOutField.Address.GetDescription()].Value = dataRow[ContactUsInputField.Address.ToString()].ToString(); mallItem.Fields[ContactUsOutField.Latitude.GetDescription()].Value = dataRow[ContactUsInputField.Latitude.ToString()].ToString(); mallItem.Fields[ContactUsOutField.Longitude.GetDescription()].Value = dataRow[ContactUsInputField.Longitude.ToString()].ToString(); mallItem.Fields[ContactUsOutField.Telephone.GetDescription()].Value = dataRow[ContactUsInputField.ContactNo.ToString()].ToString(); mallItem.Fields[ContactUsOutField.OpeningHrs.GetDescription()].Value = dataRow[ContactUsInputField.OpeningHrs.ToString()].ToString(); mallItem.Fields[ContactUsOutField.Details.GetDescription()].Value = dataRow[ContactUsInputField.Deatils.ToString()].ToString(); var photoItem = GetOrCreateAndgetPhotoItem(args, dataRow); if (photoItem != null) { mallItem.Fields[ContactUsOutField.Photo.GetDescription()].Value = string.Format("<image mediaid=\"{0}\"/>", photoItem.ID.ToString()); } var leasingResources = GetLeasingResources(dataRow); if (!string.IsNullOrEmpty(leasingResources)) { mallItem.Fields[ContactUsOutField.LeasingResources.GetDescription()].Value = leasingResources; } } } }
private void ArticleMapItems(ImportItemsArgs args, OutputMap outputMap, DataRow row, ItemDto parentItem, TableInfo tableInfo, bool isSpecialEvent) { var dataTable = tableInfo.Datatable; var currentRow = tableInfo.CurrentRow; // Show in Main var rootItem = new ID(Constants.MainSiteArticleRootId); if (isSpecialEvent) { rootItem = new ID(Constants.MainSiteEventRootId); } args.CurrentImportMallIdTemp = string.Empty; ImportMapEachRow(row, outputMap, args, rootItem, parentItem, tableInfo, isSpecialEvent); // Show in Malls var showInMallValues = dataTable.Rows[currentRow][EventInputField.ShowInMalls.ToString()].ToString(); var mallItems = CreateAndGetMalls(showInMallValues, args); foreach (MallItem mallItem in mallItems) { var rootArticleItem = mallItem.ArticleRootID; if (isSpecialEvent) { rootArticleItem = mallItem.EventRootID; } args.CurrentImportMallIdTemp = mallItem.MallID.ToString(); ImportMapEachRow(row, outputMap, args, rootArticleItem, parentItem, tableInfo, isSpecialEvent); } }
private void AssignMainSiteforMallAndContratry(Item mallItem, ImportItemsArgs args) { var fraserRewardItem = args.Database.GetItem(Templates.FrasersRewards.ID); if (fraserRewardItem != null) { using (new EditContext(fraserRewardItem, true, false)) { var mallSites = fraserRewardItem.Fields[Templates.FrasersRewards.MallSites].Value; if (!mallSites.Contains(mallItem.ID.ToString())) { if (string.IsNullOrEmpty(fraserRewardItem.Fields[Templates.FrasersRewards.MallSites].Value)) { fraserRewardItem.Fields[Templates.FrasersRewards.MallSites].Value = mallSites + mallItem.ID.ToString(); } else { fraserRewardItem.Fields[Templates.FrasersRewards.MallSites].Value = mallSites + "|" + mallItem.ID.ToString(); } } } using (new EditContext(mallItem, true, false)) { mallItem.Fields[Templates.MainSiteField].Value = Templates.FrasersRewards.ID.ToString(); } } }
public override void Process(ImportItemsArgs args) { DataReaders.IDataReader reader; if (args.FileExtension.Equals(FileExtension.xlsx.ToString(), StringComparison.OrdinalIgnoreCase) || args.FileExtension.Equals(FileExtension.xls.ToString(), StringComparison.OrdinalIgnoreCase)) { reader = new DataReaders.XlsxDataReader(); } else { Log.Info("Sitecore.Foundation.Import:Unsupported file format supplied. DataImporter accepts *.XLSX files", this); return; } reader.ReadDataExtend(args); var count = 0; foreach (var importData in args.ImportDatas) { if (importData != null) { count += importData.Rows.Count; } } args.Statistics.InputDataRows = count; }
private void MapImportData(ItemImportMap map, ImportItemsArgs args, ItemDto rootItem, DataTable dataImport, bool isSpecialEvent = false) { if (map != null) { foreach (var outputMap in map.OutputMaps) { ImportMapItems(args, dataImport, outputMap, rootItem, true, isSpecialEvent); //ick } } }
public override void Process(ImportItemsArgs args) { Log.Info("Sitecore.Foundation.Import:Processing import map...", this); args.ImportDatas[0].Columns.Clear(); foreach (var column in args.Map[0].InputFields) { args.ImportDatas[0].Columns.Add(column.Name, typeof(string)); } Log.Info(string.Format("Sitecore.Foundation.Import:{0} Columns defined in map.", args.Map[0].InputFields.Count), this); }
private string GetMediaValue(ImportItemsArgs args, string path, string fieldValue) { var fileNameNoExtention = Utils.GetFileNoExtension(fieldValue); var mediaItem = GetAndCopyFileItem(args, path, fileNameNoExtention); if (mediaItem != null) { fieldValue = string.Format("<image mediaid=\"{0}\"/>", mediaItem.ID.ToString()); } return(fieldValue); }
private void BlogMapItems(ImportItemsArgs args, OutputMap outputMap, DataRow row, ItemDto parentItem, TableInfo tableInfo) { // Show in Main var rootItem = new ID(Constants.MainSiteBlogRootId); ImportMapEachRow(row, outputMap, args, rootItem, parentItem, tableInfo); //Show in Malls foreach (MallItem mallItem in args.MallItems) { ImportMapEachRow(row, outputMap, args, mallItem.BlogRootID, parentItem, tableInfo); } }
private Item GetStoreItem(ImportItemsArgs args, ID storeRootFolderId, string storeName) { Item storeItem = null; var storeRootFolderItem = args.Database.GetItem(storeRootFolderId); if (storeRootFolderItem != null) { storeItem = storeRootFolderItem.GetChildren().FirstOrDefault(x => x.DisplayName.Equals(storeName, StringComparison.OrdinalIgnoreCase) || x.Name.Equals(storeName, StringComparison.OrdinalIgnoreCase)); } return(storeItem); }
private Item GetOrCreateAndgetPhotoItem(ImportItemsArgs args, DataRow dataRow) { var photoNameWithoutExtention = Utils.GetFileNoExtension(dataRow[ContactUsInputField.ContactNo.ToString()].ToString()); var slashString = Sitecore.Configuration.Settings.GetSetting("Sitecore.Foundation.Import.Slash"); var photoItem = args.Database.GetItem(Constants.IdentityImageSiteCorePath + slashString + photoNameWithoutExtention); if (photoItem == null) { photoItem = args.Database.GetItem(Constants.UploadedSiteCoreSiteCorePath + slashString + photoNameWithoutExtention); } return(photoItem); }
private string GetEventFieldValue(ImportItemsArgs args, string mapFieldName, string fieldValue) { if (mapFieldName == EventOutputField.Image.GetDescription() || mapFieldName == EventOutputField.Thumbnail.GetDescription()) { fieldValue = GetMediaValue(args, Constants.EventImageSiteCorePath, fieldValue); } else if (mapFieldName == EventOutputField.ShowInMalls.GetDescription()) { fieldValue = CreateOrGetMallIDsString(args, fieldValue); } return(fieldValue); }
public override void Process(ImportItemsArgs args) { List <string> mallNames; if (args.ContentType == ContentType.Store.ToString()) { mallNames = GetMallName(args.ImportDatas[0]); } else { mallNames = new DescriptionAttributes <Malls>().Descriptions.ToList(); } args.MallItems = CreateMallItems(mallNames, args); }
public override void Process(ImportItemsArgs args) { Errors = new List <string>(); foreach (var item in args.ImportItems) { ValidateName(item); } if (Errors.Any()) { args.AddMessage("Invalid item name(s) in import data."); args.ErrorDetail = string.Join("\n\n", Errors); args.AbortPipeline(); } }
private string CreateAndGetArticleCategoryId(string category, ImportItemsArgs args) { var categoryEnum = Enum.GetValues(typeof(ArticleCategory)).Cast <ArticleCategory>().FirstOrDefault(x => x.GetDescription() == category); var categoryName = categoryEnum.GetDescription(); var categoryDisplayName = categoryEnum.GetDescription(); var templateItem = args.Database.GetTemplate(Templates.ArticleCatecory.ID); //get the parent in the specific language Item parent = args.Database.GetItem(Templates.ArticleCatecory.GlobalRoot); var newItem = CreateItem(parent, categoryName, categoryDisplayName, templateItem, args); return(newItem.ID.ToString()); }
public override void Process(ImportItemsArgs args) { var rootItem = new ItemDto("<root>"); //ick if (args.ContentType != ContentType.Article.ToString()) { ItemImportMap map = null; if (args.ContentType == ContentType.Store.ToString()) { var mapItem = Factory.SetMapInputField(ContentType.Store.ToString(), Templates.Store.ID); map = Factory.BuildMapInfo(mapItem, Templates.Store.ID, ContentType.Store); } else if (args.ContentType == ContentType.Banner.ToString()) { var mapItem = Factory.SetMapInputField(ContentType.Banner.ToString(), Templates.Banner.ID); map = Factory.BuildMapInfo(mapItem, Templates.Banner.ID, ContentType.Banner); } else if (args.ContentType == ContentType.Event.ToString()) { var mapItem = Factory.SetMapInputField(ContentType.Event.ToString(), Templates.Event.ID); map = Factory.BuildMapInfo(mapItem, Templates.Event.ID, ContentType.Event); } else if (args.ContentType == ContentType.Blog.ToString()) { var mapItem = Factory.SetMapInputField(ContentType.Blog.ToString(), FrasersContent.Templates.Blog.ID); map = Factory.BuildMapInfo(mapItem, FrasersContent.Templates.Blog.ID, ContentType.Blog); } if (map != null) { args.Map.Add(map); } MapImportData(map, args, rootItem, args.ImportDatas[0]); } else { var mapArticleItem = Factory.SetMapInputField(ContentType.Article.ToString(), Templates.Article.ID); var articleMap = Factory.BuildMapInfo(mapArticleItem, Templates.Article.ID, ContentType.Article); args.Map.Add(articleMap); MapImportData(articleMap, args, rootItem, args.ImportDatas[0]); var mapSpecialItem = Factory.SetMapInputField(ContentType.Article.ToString(), FrasersContent.Templates.SpecialEvent.ID); var specialMap = Factory.BuildMapInfo(mapSpecialItem, FrasersContent.Templates.SpecialEvent.ID, ContentType.Article); args.Map.Add(specialMap); MapImportData(specialMap, args, rootItem, args.ImportDatas[1], true); } args.ImportItems.AddRange(rootItem.Children); //ick }
private ItemDto CreateItemDto(DataRow dataRow, OutputMap outputMap, ImportItemsArgs args, DataTable dataTable, int currentRow) { var item = InitialItem(outputMap.TemplateId, dataRow, args.ContentType); if (item != null) { for (int i = 0; i < outputMap.Fields.Count; i++) { var mapFieldName = outputMap.Fields[i].TargetFieldName; var fieldValue = GetFieldValue(dataRow, outputMap, args, dataTable, currentRow, i, mapFieldName); item.Fields.Add(mapFieldName, fieldValue); } } return(item); }
private string GetBlogFieldValue(ImportItemsArgs args, string mapFieldName, string fieldValue) { if (mapFieldName == BlogOutputField.Thumbnail.GetDescription() || mapFieldName == BlogOutputField.Banner.GetDescription()) { var fileName = !string.IsNullOrEmpty(fieldValue) ? Path.GetFileName(fieldValue) : string.Empty; fieldValue = GetMediaValue(args, Constants.BlogImageSiteCorePath, fileName); } else if (mapFieldName == BlogOutputField.Category.GetDescription()) { fieldValue = CreateAndGetBlogCategoryId(fieldValue, args); } return(fieldValue); }
private Item CreateItem(ImportItemsArgs args, TemplateItem item, Item parentItem, string itemName = "") { var templateItem = args.Database.GetTemplate(item.ID); //get the parent in the specific language Item parent = args.Database.GetItem(parentItem.ID); if (string.IsNullOrEmpty(itemName)) { itemName = item.Name; } Item newItem = Utils.SearchChildItem(args, parent, itemName, templateItem, this); return(newItem); }
private void EventMapItems(ImportItemsArgs args, OutputMap outputMap, DataRow row, ItemDto parentItem, TableInfo tableInfo) { // Show in Main var rootItem = new ID(Constants.MainSiteEventRootId); ImportMapEachRow(row, outputMap, args, rootItem, parentItem, tableInfo); //Show in Malls var showInMallValues = tableInfo.Datatable.Rows[tableInfo.CurrentRow][EventInputField.ShowInMalls.ToString()].ToString(); var mallItems = CreateAndGetMalls(showInMallValues, args); foreach (MallItem mallItem in mallItems) { ImportMapEachRow(row, outputMap, args, mallItem.EventRootID, parentItem, tableInfo); } }
public override void Process(ImportItemsArgs args) { Log.Info("Sitecore.Foundation.Import:Validating input...", this); var argsValid = true; if (args.FileStream == null) { Log.Error("Sitecore.Foundation.Import:Input file not found.", this); argsValid = false; } if (!argsValid) { args.AddMessage("Error: Input file not found."); args.ErrorDetail = "FileStream = null"; args.AbortPipeline(); } }
private string GetStoreFieldValue(ImportItemsArgs args, DataTable dataTable, int currentRow, string mapFieldName, string fieldValue) { if (mapFieldName == StoreOutputField.Category.GetDescription()) { fieldValue = CreateAndGetStoreCategoryId(fieldValue, args); } else if (mapFieldName == StoreOutputField.Logo.GetDescription()) { fieldValue = GetMediaValue(args, Constants.StoreImageSiteCorePath, fieldValue); } else if (mapFieldName == StoreOutputField.StoreOffers.GetDescription()) { fieldValue = GetStoreOffers(dataTable.Rows[currentRow]); } return(fieldValue); }
private void ImportMapItems(ImportItemsArgs args, DataTable dataTable, OutputMap outputMap, ItemDto parentItem, bool rootLevel, bool isSpecialEvent) { var groupedTable = dataTable.GroupBy(outputMap.Fields.Select(f => f.SourceColumn).ToArray()); for (int i = 0; i < groupedTable.Rows.Count; i++) { var row = groupedTable.Rows[i]; if (rootLevel || System.Convert.ToString(row[outputMap.ParentMap.NameInputField]) == parentItem.Name) { ID rootItem = ID.Null; var tableInfo = new TableInfo() { CurrentRow = i, Datatable = dataTable }; if (args.ContentType == ContentType.Banner.ToString()) { BannerMapItems(args, outputMap, row, parentItem, tableInfo); } else if (args.ContentType == ContentType.Event.ToString()) { EventMapItems(args, outputMap, row, parentItem, tableInfo); } else if (args.ContentType == ContentType.Article.ToString()) { ArticleMapItems(args, outputMap, row, parentItem, tableInfo, isSpecialEvent); } else if (args.ContentType == ContentType.Store.ToString()) { var rowMallName = dataTable.Rows[i][StoreInputField.Mall.ToString()].ToString(); rootItem = args.MallItems.Where(x => x.MallName.Equals(rowMallName, StringComparison.OrdinalIgnoreCase)).Select(x => x.StoreRootID).FirstOrDefault(); ImportMapEachRow(row, outputMap, args, rootItem, parentItem, tableInfo); } else if (args.ContentType == ContentType.Blog.ToString()) { BlogMapItems(args, outputMap, row, parentItem, tableInfo); } else { ImportMapEachRow(row, outputMap, args, rootItem, parentItem, tableInfo); } } } }
private void ImportItems(ImportItemsArgs args, ItemDto importItem, Item parentItem, bool rootLevel) { if (rootLevel || importItem.Parent.Name == parentItem.Name) { var createdItem = CreateItem(args, importItem, parentItem); if (createdItem != null && importItem.Children != null && importItem.Children.Any()) { foreach (var childImportItem in importItem.Children) { ImportItems(args, childImportItem, createdItem, false); } } } }
private MallItem CreateSubFolderForMall(ImportItemsArgs args, MallItem mallItem, Item newItem) { // Create Local Content Folder var templateLocalContentFolderItem = args.Database.GetTemplate(Templates.LocalContentFolder.ID); var localFolderItem = CreateItem(args, templateLocalContentFolderItem, newItem, Templates.LocalContentFolder.DefaultName); // Create Banners Folder var templateBannerFolderItem = args.Database.GetTemplate(Templates.BannerFolder.ID); var bannerFolderItem = CreateItem(args, templateBannerFolderItem, localFolderItem, Templates.BannerFolder.DefaultName); // Create Blogs Folder var templateBlogFolderItem = args.Database.GetTemplate(Templates.BlogFolder.ID); var blogFolderItem = CreateItem(args, templateBlogFolderItem, localFolderItem, Templates.BlogFolder.DefaultName); // Create Articles Folder var templateArticleFolderItem = args.Database.GetTemplate(Templates.ArticleFolder.ID); var articleFolderItem = CreateItem(args, templateArticleFolderItem, localFolderItem, Templates.ArticleFolder.DefaultName); // Create Events Folder var templateEventFolderItem = args.Database.GetTemplate(Templates.EventFolder.ID); var eventFolderItem = CreateItem(args, templateEventFolderItem, localFolderItem, Templates.EventFolder.DefaultName); // Create Pages Folder var templatePageFolderItem = args.Database.GetTemplate(Templates.ContentFolder.ID); var pageFolderItem = CreateItem(args, templatePageFolderItem, localFolderItem, Templates.ContentFolder.DefaultName); // Create Stores Folder var templateStoreFolderItem = args.Database.GetTemplate(Templates.StoreFolder.ID); var storeFolderItem = CreateItem(args, templateStoreFolderItem, localFolderItem, Templates.StoreFolder.DefaultName); mallItem.MallName = newItem.Name; mallItem.MallID = newItem.ID; mallItem.StoreRootID = storeFolderItem.ID; mallItem.BannerRootID = bannerFolderItem.ID; mallItem.EventRootID = eventFolderItem?.ID; mallItem.ArticleRootID = articleFolderItem.ID; mallItem.BlogRootID = blogFolderItem.ID; mallItem.PageRootID = pageFolderItem?.ID; return(mallItem); }
private void ImportMapEachRow(DataRow dataRow, OutputMap outputMap, ImportItemsArgs args, ID rootItem, ItemDto parentItem, TableInfo tableInfo, bool isSpecialEvent = false) { var createdItem = CreateItemDto(dataRow, outputMap, args, tableInfo.Datatable, tableInfo.CurrentRow); if (createdItem != null) { createdItem.ParentRootId = rootItem; createdItem.Parent = parentItem; parentItem.Children.Add(createdItem); if (outputMap.ChildMaps != null && outputMap.ChildMaps.Any()) { foreach (var childMap in outputMap.ChildMaps) { ImportMapItems(args, tableInfo.Datatable, childMap, createdItem, false, isSpecialEvent); } } } }
private string GetArticleFieldValue(ImportItemsArgs args, string mapFieldName, string fieldValue) { if (mapFieldName == ArticleOutputField.Banner.GetDescription() || mapFieldName == ArticleOutputField.Thumbnail.GetDescription()) { fieldValue = GetMediaValue(args, Constants.ArticleImageSiteCorePath, fieldValue); } else if (mapFieldName == ArticleOutputField.ShowInMalls.GetDescription()) { fieldValue = CreateOrGetMallIDsString(args, fieldValue); } else if (mapFieldName == ArticleOutputField.Category.GetDescription()) { fieldValue = CreateAndGetArticleCategoryId(fieldValue, args); } else if (mapFieldName == ArticleOutputField.Store.GetDescription()) { fieldValue = GetStoreForArticle(fieldValue, args.CurrentImportMallIdTemp, args); } return(fieldValue); }
public override void Process(ImportItemsArgs args) { var originalIndexingSetting = Sitecore.Configuration.Settings.Indexing.Enabled; Sitecore.Configuration.Settings.Indexing.Enabled = false; using (new BulkUpdateContext()) { using (new LanguageSwitcher(args.TargetLanguage)) { foreach (var importItem in args.ImportItems) { var parentItem = args.Database.GetItem(importItem.ParentRootId); if (parentItem != null) { ImportItems(args, importItem, parentItem, true); } } } } Sitecore.Configuration.Settings.Indexing.Enabled = originalIndexingSetting; }
private Item GetAndCopyFileItem(ImportItemsArgs args, string sitecorePath, string mediaItemName) { var slashString = Sitecore.Configuration.Settings.GetSetting("Sitecore.Foundation.Import.Slash"); Item myItem = args.Database.GetItem(sitecorePath + slashString + mediaItemName); if (myItem != null) { return(myItem); } else { myItem = args.Database.GetItem(Constants.UploadedSiteCoreSiteCorePath + slashString + mediaItemName); if (myItem != null) { var folderItem = args.Database.GetItem(sitecorePath); myItem.MoveTo(folderItem); return(myItem); } return(null); } }