Example #1
0
        public void ImportAsset()
        {
            // Get mapping from CSV file
            IEnumerable <AssetMapping> AssetsMapping = _entries;

            // Get image from Asset folder
            Console.WriteLine("Upload folder to CMS site... ");
            DirectoryInfo di = new DirectoryInfo(_folderPath);

            FileInfo[] assetFiles = di.GetFiles("*.bmp", SearchOption.AllDirectories)
                                    .Union(di.GetFiles("*.jpg", SearchOption.AllDirectories))
                                    .Union(di.GetFiles("*.png", SearchOption.AllDirectories))
                                    .ToArray();

            foreach (var assetFile in assetFiles)
            {
                string assetFileName = assetFile.Name;

                #region Import asset file as CMS content
                // Create CMS file content and get Guid after import CMS
                var cmsContentGuid = ContentHelper.CreateFileContent(assetFile, _importFolder);
                #endregion

                // when import to CMS done
                if (AssetsMapping.Where(m => m.AssetName.Equals(assetFileName, StringComparison.OrdinalIgnoreCase)).Count() > 0)
                {
                    foreach (var mapping in AssetsMapping.Where(m => m.AssetName.Equals(assetFileName, StringComparison.OrdinalIgnoreCase)))
                    {
                        mapping.AssetKey = cmsContentGuid.ToString();
                    }
                }
            }

            Console.WriteLine("Association asset with entry... ");
            foreach (var mapping in AssetsMapping)
            {
                MappingEntryHelper.AddMapping(mapping.ProductCode, mapping);
            }

            MappingEntryHelper.AssociateAssetsWithProduct();
            MappingEntryHelper.AssociateAssetsWithCatalogNode();

            //Console.WriteLine("Catalog Asset updated: " + updated);
        }