private ICollection <DeliveryMethodTranslationCarrier> UpdateLanguageId(ICollection <DeliveryMethodTranslationCarrier> deliveryTranslations, StructureInfo structureInfo) { foreach (var translation in deliveryTranslations) { translation.LanguageID = structureInfo.Id(translation.LanguageID); translation.DeliveryMethodID = structureInfo.Id(translation.DeliveryMethodID); } return(deliveryTranslations); }
private PointerItem CorrectValue(StructureInfo structureInfo, PointerItem fieldValue) { if (fieldValue is PointerPageItem pointerPageItem) { pointerPageItem.ChannelSystemId = structureInfo.Id(pointerPageItem.ChannelSystemId); } fieldValue.EntitySystemId = structureInfo.Id(fieldValue.EntitySystemId); return(fieldValue); }
private ICollection <DeliveryMethodCostCarrier> UpdateDeliveryCurrency(ICollection <DeliveryMethodCostCarrier> deliveryCosts, StructureInfo structureInfo) { foreach (var cost in deliveryCosts) { cost.CurrencyID = structureInfo.Id(cost.CurrencyID); cost.DeliveryMethodID = structureInfo.Id(cost.DeliveryMethodID); } return(deliveryCosts); }
private void CreateWebsite(string name, StructureInfo structureInfo) { var website = structureInfo.Website.Website.MakeWritableClone(); website.Id = _slugifyService.Slugify(CultureInfo.CurrentCulture, name).NullIfEmpty(); foreach (var language in _languageService.GetAll()) { website.Localizations[language.CultureInfo].Name = name; } website.SystemId = structureInfo.Id(website.SystemId); website.FieldTemplateSystemId = structureInfo.Id(website.FieldTemplateSystemId); _websiteService.Create(website); structureInfo.Website.Website = website; }
private string CorrectValue(StructureInfo structureInfo, string field, string fieldValue, FieldDefinition fieldDefinition, bool changeUrl) { if (changeUrl && field == SystemFieldDefinitionConstants.Url) { fieldValue = $"{fieldValue}-{structureInfo.Prefix}"; } else { switch (fieldDefinition.FieldType) { case SystemFieldTypeConstants.Text: case SystemFieldTypeConstants.MultirowText: case SystemFieldTypeConstants.Editor: fieldValue = structureInfo.ReplaceText(fieldValue); break; case SystemFieldTypeConstants.MediaPointerFile: case SystemFieldTypeConstants.MediaPointerImage: case SystemFieldTypeConstants.Pointer: fieldValue = structureInfo.Id(new Guid(fieldValue)).ToString(); break; } } return(fieldValue); }
private void AddInventories(StructureInfo structureInfo) { if (structureInfo.ProductCatalog.InventoryItems != null && structureInfo.ProductCatalog.InventoryItems.Count > 0) { foreach (var inventoryItem in structureInfo.ProductCatalog.InventoryItems) { _inventoryItemService.Create( new InventoryItem( structureInfo.Id(inventoryItem.VariantSystemId), structureInfo.Id(inventoryItem.InventorySystemId)) { InStockQuantity = inventoryItem.InStockQuantity }); } } }
/// <summary> /// Imports the specified structure info. /// </summary> /// <param name="structureInfo"> The structure info. </param> /// <param name="folder"> The folder. </param> /// <param name="parentId"> The parent id. </param> protected virtual void Import(StructureInfo structureInfo, Folder folder, Guid parentId) { foreach (var folderCarrier in structureInfo.MediaArchive.Folders.Where(x => x.ParentFolderSystemId == parentId)) { var newFolder = new Folder(structureInfo.MediaArchive.FolderTemplateId, folderCarrier.Name) { SystemId = structureInfo.Id(folderCarrier.SystemId), ParentFolderSystemId = folder.SystemId, }; foreach (var item in folderCarrier.AccessControlList) { newFolder.AccessControlList.Add(new AccessControlEntry(item.Operation, structureInfo.Id(structureInfo.Foundation.VisitorGroupId))); } _folderService.Create(newFolder); if (structureInfo.CreateExampleProducts) { Import(structureInfo, newFolder, folderCarrier.SystemId); } else { ImportFiles(structureInfo, newFolder, folderCarrier.SystemId); } } ImportFiles(structureInfo, folder, parentId); }
private void CreateMarket(StructureInfo structureInfo, Guid assortmentSystemId, string marketName) { var market = structureInfo.Website.Market.MakeWritableClone(); market.SystemId = structureInfo.Id(market.SystemId); market.FieldTemplateSystemId = structureInfo.Id(market.FieldTemplateSystemId); _structureInfoService.AddProperties <WebsiteArea>(structureInfo, structureInfo.Website.Market.Fields, market.Fields, false); market.AssortmentSystemId = assortmentSystemId; foreach (var language in _languageService.GetAll()) { market.Localizations[language.CultureInfo].Name = marketName; } market.Id = _slugifyService.Slugify(CultureInfo.CurrentCulture, marketName).NullIfEmpty(); _marketService.Create(market); structureInfo.Website.Market = market; }
private ICollection <BlockToChannelLink> UpdateBlockChannelLink(StructureInfo structureInfo, ICollection <BlockToChannelLink> blockChannelLinks) { foreach (var channelLink in blockChannelLinks) { channelLink.ChannelSystemId = structureInfo.Id(channelLink.ChannelSystemId); } return(blockChannelLinks); }
private void AddBundles(StructureInfo structureInfo, Variant variant, Variant newVariant) { if (variant.BundledVariants != null && variant.BundledVariants.Count > 0) { newVariant.BundledVariants = new List <VariantBundledLink>(); foreach (var bundleItem in variant.BundledVariants) { if (structureInfo.Id(bundleItem.BundledVariantSystemId) != bundleItem.BundledVariantSystemId) { newVariant.BundledVariants.Add(new VariantBundledLink(structureInfo.Id(bundleItem.BundledVariantSystemId)) { Quantity = bundleItem.Quantity }); } } } }
private void CreateBlocks(StructureInfo structureInfo) { using (var db = _dataService.CreateBatch()) { foreach (var block in structureInfo.Website.Blocks) { var newBlock = block.MakeWritableClone(); newBlock.SystemId = structureInfo.Id(block.SystemId); newBlock.FieldTemplateSystemId = structureInfo.Id(block.FieldTemplateSystemId); newBlock.AccessControlList = _structureInfoService.GetAccessControlList(block.AccessControlList); _structureInfoService.AddProperties <BlockArea>(structureInfo, block.Fields, newBlock.Fields, false); newBlock.ChannelLinks = UpdateBlockChannelLink(structureInfo, block.ChannelLinks); db.Create(newBlock); } db.Commit(); } }
/// <summary> /// Imports the categories. /// </summary> /// <param name="structureInfo">The structure info.</param> private void ImportCategories(StructureInfo structureInfo) { foreach (var category in structureInfo.ProductCatalog.Categories) { var newCategory = new Category(structureInfo.Id(category.FieldTemplateSystemId), structureInfo.Id(structureInfo.ProductCatalog.Assortment.SystemId)) { SystemId = structureInfo.Id(category.SystemId), ParentCategorySystemId = structureInfo.Id(category.ParentCategorySystemId), AccessControlList = category.AccessControlList.MakeWritable() }; MapCategories(structureInfo, category.ProductLinks, newCategory.ProductLinks); _structureInfoService.AddProperties <ProductArea>(structureInfo, category.Fields, newCategory.Fields, false); MapPublish(structureInfo, category.ChannelLinks, newCategory.ChannelLinks); AddRelations(structureInfo, category, newCategory); _categoryService.Create(newCategory); } }
private void AddProductLists(StructureInfo structureInfo) { using (var batch = _dataService.CreateBatch()) { foreach (var productListLink in structureInfo.ProductCatalog.ProductListItems) { if (_productListService.Get <ProductList>(structureInfo.Id(productListLink.ProductListSystemId)) is object) { var item = new ProductListItem(structureInfo.Id(productListLink.BaseProductSystemId), structureInfo.Id(productListLink.ProductListSystemId)); foreach (var activeVariantSystemId in productListLink.ActiveVariantSystemIds) { item.ActiveVariantSystemIds.Add(structureInfo.Id(activeVariantSystemId)); } batch.Create(item); } } batch.Commit(); } }
private void MapPublish(StructureInfo structureInfo, ICollection <CategoryToChannelLink> oldChannelLink, ICollection <CategoryToChannelLink> newChannelLink) { foreach (var item in oldChannelLink) { if (item.ChannelSystemId == structureInfo.Website.Channel.SystemId) { newChannelLink.Add(new CategoryToChannelLink(structureInfo.Id(item.ChannelSystemId))); } } }
private void PrepareCountryImport(StructureInfo structureInfo) { foreach (var country in structureInfo.Website.Countries) { var existCountry = _countryService.Get(country.Id)?.MakeWritableClone(); if (existCountry != null) { structureInfo.Mappings.Add(country.SystemId, existCountry.SystemId); foreach (var countryToTaxClassLink in country.TaxClassLinks) { var taxclass = existCountry.TaxClassLinks.FirstOrDefault(x => x.TaxClassSystemId == structureInfo.Id(countryToTaxClassLink.TaxClassSystemId)); if (taxclass != null) { taxclass.VatRate = countryToTaxClassLink.VatRate; } else { existCountry.TaxClassLinks.Add(new CountryToTaxClassLink(structureInfo.Id(countryToTaxClassLink.TaxClassSystemId)) { VatRate = countryToTaxClassLink.VatRate }); } } _countryService.Update(existCountry); } else { var countryId = Guid.NewGuid(); structureInfo.Mappings.Add(country.SystemId, countryId); var newCountry = country.MakeWritableClone(); newCountry.SystemId = countryId; newCountry.TaxClassLinks = country.TaxClassLinks.Select(x => new CountryToTaxClassLink(structureInfo.Id(x.TaxClassSystemId)) { VatRate = x.VatRate }).ToList(); newCountry.CurrencySystemId = structureInfo.Id(country.CurrencySystemId); _countryService.Create(newCountry); } } }
private JToken CorrectValue <TArea>(StructureInfo structureInfo, string field, JToken fieldValue, FieldDefinition fieldDefinition, bool changeUrl) where TArea : IArea { if (field.Equals(SystemFieldDefinitionConstants.ThumbnailsMetadata, StringComparison.OrdinalIgnoreCase)) { var channelId = structureInfo.Id(structureInfo.Website.Channel.SystemId).ToString("N"); foreach (var item in ((JArray)fieldValue)) { var fileNameSuffix = item.SelectToken("fileNameSuffix"); if (fileNameSuffix.Value <string>() == channelId) { fileNameSuffix.Replace(new JValue(channelId)); } } return(fieldValue); } var value = ConvertFromJsonValue(fieldValue); switch (value) { case List <string> _: var items = value as List <string>; for (var i = 0; i < items.Count; i++) { items[i] = CorrectValue(structureInfo, field, items[i], fieldDefinition, changeUrl); } return(new JArray(items)); case string _: return(CorrectValue(structureInfo, field, (string)value, fieldDefinition, changeUrl)); case List <PointerItem> pointerItems: for (var i = 0; i < pointerItems.Count; i++) { pointerItems[i] = CorrectValue(structureInfo, pointerItems[i]); } return(JArray.FromObject(pointerItems, _jsonSerializer)); case List <MultiFieldItem> multiFieldItems: foreach (var item in multiFieldItems) { if (item != null) { AddProperties <TArea>(structureInfo, item.Fields, item.Fields); } } return(JArray.FromObject(multiFieldItems, _jsonSerializer)); } return(fieldValue); }
private void MapCategories(StructureInfo structureInfo, ICollection <CategoryToProductLink> oldCategories, ICollection <CategoryToProductLink> newCategories) { foreach (var categoryLink in oldCategories) { var baseProductSystemId = structureInfo.Id(categoryLink.BaseProductSystemId); newCategories.Add(new CategoryToProductLink(baseProductSystemId) { MainCategory = categoryLink.MainCategory, ActiveVariantSystemIds = new HashSet <Guid>(categoryLink.ActiveVariantSystemIds.Select(structureInfo.Id)) }); } }
private void CreatePages(StructureInfo structureInfo, PackageInfo packageInfo) { using (var db = _dataService.CreateBatch()) { foreach (var page in structureInfo.Website.ChildPages) { var newPage = page.MakeWritableClone(); newPage.SystemId = structureInfo.Id(page.SystemId); newPage.FieldTemplateSystemId = structureInfo.Id(page.FieldTemplateSystemId); newPage.ParentPageSystemId = structureInfo.Id(page.ParentPageSystemId); newPage.WebsiteSystemId = structureInfo.Id(page.WebsiteSystemId); newPage.AccessControlList = _structureInfoService.GetAccessControlList(page.AccessControlList); newPage.ChannelLinks = new List <PageToChannelLink> { new PageToChannelLink(packageInfo.Channel.SystemId) }; UpdateBlockSystemId(structureInfo, page, newPage); _structureInfoService.AddProperties <WebsiteArea>(structureInfo, page.Fields, newPage.Fields, false); db.Create(newPage); } db.Commit(); } }
private void AddPrices(StructureInfo structureInfo) { if (structureInfo.ProductCatalog.PriceListItems != null && structureInfo.ProductCatalog.PriceListItems.Count > 0) { foreach (var priceItem in structureInfo.ProductCatalog.PriceListItems) { _priceListItemService.Create(new PriceListItem(structureInfo.Id(priceItem.VariantSystemId), structureInfo.Id(priceItem.PriceListSystemId)) { MinimumQuantity = priceItem.MinimumQuantity, Price = priceItem.Price, }); } } }
private PriceList CreatePriceList(Website webSite, StructureInfo structureInfo) { var priceList = _priceListService.Get(webSite.Id.Replace(" ", "")); if (priceList != null) { return(priceList); } var currency = _currencyService.Get(structureInfo.ProductCatalog.CurrencyId) ?? _currencyService.GetBaseCurrency(); priceList = new PriceList(structureInfo.Id(currency.SystemId)) { Id = webSite.Id.Replace(" ", ""), Active = structureInfo.ProductCatalog.PriceList?.Active ?? true, AccessControlList = structureInfo.ProductCatalog.PriceList.AccessControlList.MakeWritable() }; if (structureInfo.ProductCatalog.PriceList?.WebSiteLinks.Any(x => structureInfo.Id(x.WebSiteSystemId) == structureInfo.Website.Website.SystemId) ?? false) { priceList.WebSiteLinks.Add(new PriceListToWebSiteLink(webSite.SystemId)); } foreach (var language in Solution.Instance.Languages) { priceList.Localizations[language.Culture].Name = webSite.Localizations[language.Culture].Name; } _priceListService.Create(priceList); if (structureInfo.ProductCatalog.PriceList != null) { structureInfo.Mappings.Add(structureInfo.ProductCatalog.PriceList.SystemId, priceList.SystemId); } return(priceList); }
private void UpdateBlockSystemId(StructureInfo structureInfo, Page oldPage, Page newPage) { var newBlockContainer = new BlockContainer(); foreach (var blockContainer in oldPage.Blocks) { var newBlockItemContainer = new BlockItemContainer(blockContainer.Id); foreach (var oldItemLink in blockContainer.Items.OfType <BlockItemLink>()) { newBlockItemContainer.Items.Add(new BlockItemLink(structureInfo.Id(oldItemLink.BlockSystemId))); } newBlockContainer.Add(newBlockItemContainer); } newPage.Blocks.Clear(); foreach (var item in newBlockContainer) { newPage.Blocks.Add(item); } }
private void ImportThumbnail(Dictionary <Guid, byte[]> thumbnailData, StructureInfo structureInfo, string blobAuthority) { foreach (var thumbnail in thumbnailData) { using (var inputStream = new MemoryStream(thumbnail.Value)) { var container = _blobService.Create(blobAuthority, structureInfo.Id(thumbnail.Key)); if (container.GetDefault().Exists) { // since we are using the same Blob Uri over and over, we need to delete the container // add write new file in order to delete generated thumbnails. _blobService.Delete(container); } using (var stream = container.GetDefault().OpenWrite()) { inputStream.CopyTo(stream); } } } }
private Channel CreateChannel(StructureInfo structureInfo, Guid websiteId, string urlPrefix, string channelName) { var channel = structureInfo.Website.Channel; var newChannel = new Channel(structureInfo.Id(channel.FieldTemplateSystemId)) { GoogleTagManagerContainerId = channel.GoogleTagManagerContainerId, SystemId = structureInfo.Id(channel.SystemId), DomainNameLinks = new List <ChannelToDomainNameLink> { new ChannelToDomainNameLink(structureInfo.Id(structureInfo.Website.DomainName.SystemId)) { UrlPrefix = urlPrefix } }, GoogleAnalyticsAccountId = channel.GoogleAnalyticsAccountId }; foreach (var language in _languageService.GetAll()) { newChannel.Localizations[language.CultureInfo].Name = channelName; } if (channel.MarketSystemId != null) { newChannel.MarketSystemId = structureInfo.Id(structureInfo.Website.Market.SystemId); } if (channel.ProductLanguageSystemId.HasValue) { newChannel.ProductLanguageSystemId = structureInfo.Id(channel.ProductLanguageSystemId.Value); } if (channel.WebsiteLanguageSystemId.HasValue) { newChannel.WebsiteLanguageSystemId = structureInfo.Id(channel.WebsiteLanguageSystemId.Value); } newChannel.CountryLinks.Clear(); newChannel.WebsiteSystemId = structureInfo.Id(websiteId); newChannel.Id = _slugifyService.Slugify(CultureInfo.CurrentCulture, channelName); _channelService.Create(newChannel); return(newChannel); }
protected virtual void ImportFiles(StructureInfo structureInfo, Folder folder, Guid parentId) { foreach (var fileCarrier in structureInfo.MediaArchive.Files.Where(x => x.FolderSystemId == parentId).OrderBy(x => x.Name)) { using (var stream = new MemoryStream(structureInfo.MediaArchive.FileData[fileCarrier.SystemId])) { var blobContainer = _blobService.Create(ModuleName); using (var blobStream = blobContainer.GetDefault().OpenWrite()) { stream.CopyTo(blobStream); } var template = _fieldTemplateService.FindFileTemplate(fileCarrier.GetFileExtension()); var fileObject = new File(template.SystemId, folder.SystemId, blobContainer.Uri, fileCarrier.Name) { SystemId = structureInfo.Id(fileCarrier.SystemId), LastWriteTimeUtc = DateTimeOffset.UtcNow }; _fileMetadataExtractorService.UpdateMetadata(template, fileObject, null, blobContainer.Uri); fileObject.AccessControlList = folder.AccessControlList; _fileService.Create(fileObject); } } }
public void UpdatePropertyReferences(StructureInfo structureInfo, PackageInfo packageInfo) { var website = _websiteService.Get(structureInfo.Id(packageInfo.Website.SystemId)).MakeWritableClone(); AddProperties <WebsiteArea>(structureInfo, structureInfo.Website.Website.Fields, website.Fields, false); _websiteService.Update(website); var channel = _channelService.Get(packageInfo.Channel.SystemId).MakeWritableClone(); channel.CountryLinks = structureInfo.Website.Channel.CountryLinks.Select(x => new ChannelToCountryLink(structureInfo.Id(x.CountrySystemId)) { DeliveryMethodSystemIds = x.DeliveryMethodSystemIds.Select(z => ModuleECommerce.Instance.DeliveryMethods.Get(packageInfo.DeliveryMethods.Find(zz => zz.ID == z)?.Name ?? string.Empty, ModuleECommerce.Instance.AdminToken)?.ID ?? Guid.Empty).Where(z => z != Guid.Empty).ToList(), PaymentMethodSystemIds = x.PaymentMethodSystemIds.Select(z => { var payment = packageInfo.PaymentMethods.Find(zz => zz.ID == z); if (payment == null) { return(Guid.Empty); } return(ModuleECommerce.Instance.PaymentMethods.Get(payment.Name, payment.PaymentProviderName, ModuleECommerce.Instance.AdminToken)?.ID ?? Guid.Empty); }).Where(z => z != Guid.Empty).ToList(), }).ToList(); AddProperties <GlobalizationArea>(structureInfo, structureInfo.Website.Channel.Fields, channel.Fields, false, new List <string> { SystemFieldDefinitionConstants.Name }); _channelService.Update(channel); var inventory = _inventoryService.Get(packageInfo.Inventory.SystemId).MakeWritableClone(); inventory.CountryLinks = structureInfo.ProductCatalog.Inventory.CountryLinks.Select(x => new InventoryToCountryLink(structureInfo.Id(x.CountrySystemId))).ToList(); _inventoryService.Update(inventory); var priceList = _priceListService.Get(packageInfo.PriceList.SystemId).MakeWritableClone(); priceList.CountryLinks = structureInfo.ProductCatalog.PriceList.CountryLinks.Select(x => new PriceListToCountryLink(structureInfo.Id(x.CountrySystemId))).ToList(); _priceListService.Update(priceList); }
/// <summary> /// Imports the products. /// </summary> /// <param name="structureInfo">The structure info.</param> private void ImportProducts(StructureInfo structureInfo) { foreach (var product in structureInfo.ProductCatalog.BaseProducts) { var newSystemId = structureInfo.Id(product.SystemId); var newId = GetNewId(structureInfo, product.Id, newSystemId); var baseProduct = new BaseProduct(newId, structureInfo.Id(product.FieldTemplateSystemId)) { SystemId = newSystemId, TaxClassSystemId = structureInfo.Id(product.TaxClassSystemId), AccessControlList = product.AccessControlList.MakeWritable() }; _structureInfoService.AddProperties <ProductArea>(structureInfo, product.Fields, baseProduct.Fields, false); foreach (var language in _languageService.GetAll()) { var url = baseProduct.Localizations[language.CultureInfo].Url; if (string.IsNullOrEmpty(url)) { continue; } baseProduct.Localizations[language.CultureInfo].Url = $"{structureInfo.Prefix}_{url}"; } _baseProductService.Create(baseProduct); foreach (var variant in structureInfo.ProductCatalog.Variants.Where(x => x.BaseProductSystemId == product.SystemId)) { newSystemId = structureInfo.Id(variant.SystemId); newId = GetNewId(structureInfo, variant.Id, newSystemId); var newVariant = new Variant(newId, structureInfo.Id(baseProduct.SystemId)) { SystemId = newSystemId, UnitOfMeasurementSystemId = variant.UnitOfMeasurementSystemId == null ? null : (Guid?)structureInfo.Id(variant.UnitOfMeasurementSystemId.Value) }; _structureInfoService.AddProperties <ProductArea>(structureInfo, variant.Fields, newVariant.Fields); MapPublish(structureInfo, variant.ChannelLinks, newVariant.ChannelLinks); _variantService.Create(newVariant); } _baseProductService.Update(baseProduct); } AddPrices(structureInfo); AddInventories(structureInfo); AddProductLists(structureInfo); foreach (var product in structureInfo.ProductCatalog.BaseProducts) { var newProduct = _baseProductService.Get(structureInfo.Id(product.SystemId)).MakeWritableClone(); AddRelations(structureInfo, product, newProduct); _baseProductService.Update(newProduct); foreach (var variant in structureInfo.ProductCatalog.Variants.Where(x => x.BaseProductSystemId == product.SystemId)) { var newVariant = _variantService.Get(structureInfo.Id(variant.SystemId)).MakeWritableClone(); AddBundles(structureInfo, variant, newVariant); AddRelations(structureInfo, variant, newVariant); _variantService.Update(newVariant); } } if (structureInfo.ProductCatalog.ProductFilters == null) { return; } var filters = _filterService.GetProductFilteringFields(); var missingFilters = structureInfo.ProductCatalog.ProductFilters.Where(x => !filters.Contains(x)).ToList(); if (missingFilters.Any()) { _filterService.SaveProductFilteringFields(missingFilters.Union(filters).ToList()); } }
private void AddRelations(StructureInfo structureInfo, Variant variant, Variant newVariant) { if (variant.RelationshipLinks != null && variant.RelationshipLinks.Count > 0) { if (newVariant.RelationshipLinks == null) { newVariant.RelationshipLinks = new List <VariantToRelationshipLinkBase>(); } foreach (var relationshipLink in variant.RelationshipLinks) { var relationshipType = _relationshipTypeService.Get(structureInfo.Id(relationshipLink.RelationshipTypeSystemId)); var relatedItemId = Guid.Empty; if (relationshipLink is VariantToBaseProductRelationshipLink) { var newId = structureInfo.Id( ((VariantToBaseProductRelationshipLink)relationshipLink).BaseProductSystemId); relatedItemId = newId == ((VariantToBaseProductRelationshipLink)relationshipLink).BaseProductSystemId ? Guid.Empty : newId; } else if (relationshipLink is VariantToVariantRelationshipLink) { var newId = structureInfo.Id(((VariantToVariantRelationshipLink)relationshipLink).VariantSystemId); relatedItemId = newId == ((VariantToVariantRelationshipLink)relationshipLink).VariantSystemId ? Guid.Empty : newId; } else if (relationshipLink is VariantToCategoryRelationshipLink) { var newId = structureInfo.Id(((VariantToCategoryRelationshipLink)relationshipLink).CategorySystemId); relatedItemId = newId == ((VariantToCategoryRelationshipLink)relationshipLink).CategorySystemId ? Guid.Empty : newId; } if (relatedItemId != Guid.Empty) { if (relationshipType.Bidirectional) { //Avoid adding duplicates var relationWasAdded = _bidirectionalRelationList.Any(x => x.RelationTypeId == relationshipType.SystemId && x.Item1Id == relatedItemId && x.Item2Id == newVariant.SystemId); if (relationWasAdded) { continue; } _bidirectionalRelationList.Add(new ImportBidirectionalRelation { RelationTypeId = relationshipType.SystemId, Item1Id = newVariant.SystemId, Item2Id = relatedItemId }); } if (relationshipLink is VariantToBaseProductRelationshipLink) { newVariant.RelationshipLinks.Add( new VariantToBaseProductRelationshipLink(relationshipType.SystemId, relatedItemId)); } else if (relationshipLink is VariantToVariantRelationshipLink) { newVariant.RelationshipLinks.Add( new VariantToVariantRelationshipLink(relationshipType.SystemId, relatedItemId)); } else if (relationshipLink is VariantToCategoryRelationshipLink) { newVariant.RelationshipLinks.Add( new VariantToCategoryRelationshipLink(relationshipType.SystemId, relatedItemId)); } } } } }
/// <summary> /// Replaces the text. /// </summary> /// <param name="structureInfo"></param> /// <param name="text"> The text. </param> /// <returns> </returns> public static string ReplaceText([NotNull] this StructureInfo structureInfo, string text) { if (string.IsNullOrEmpty(text)) { return(text); } foreach (Match hit in RegexPageId.Matches(text)) { var value = hit.Groups[1].Value; var newPageId = structureInfo.Id(new Guid(value)).ToString("N"); if (!newPageId.Equals(value, StringComparison.InvariantCultureIgnoreCase)) { text = text.Replace(value, newPageId); } } var replacedMatch = new HashSet <string>(); var tags = RegexpTags.Matches(text); foreach (Match tag in tags) { var storageMatches = RegexpStorage.Matches(tag.Value); foreach (Match storageMatch in storageMatches) { string fullMatch; Guid ownerId; string formatPath; try { fullMatch = storageMatch.Groups[1].Value; ownerId = structureInfo.Id(new Guid(storageMatch.Groups[4].Value)); formatPath = storageMatch.Groups[6].Value; } catch { continue; } if (fullMatch.Contains("\"")) { fullMatch = fullMatch.Substring(0, fullMatch.IndexOf('"')); } if (replacedMatch.Contains(fullMatch)) { continue; } replacedMatch.Add(fullMatch); var file = FileService.Get(ownerId); if (file == null) { continue; } Size size; bool keepAspectRatio; ImageFormat resizeFormat; FileExtensions.DecodeFormatPart(formatPath, out size, out keepAspectRatio, out resizeFormat); if (file.GetFileType().IsImage()) { var url = FileExtensions.GetUrl(file.SystemId, file.BlobUri.ToString(), file.Name, null, size, keepAspectRatio, false); text = text.Replace(fullMatch, url); } else { var url = FileExtensions.GetUrl(file.SystemId, file.BlobUri.ToString(), file.Name, null, Size.Empty, false, false);; text = text.Replace(fullMatch, url); } } } return(text); }