protected virtual void CreateCatalog(CloudBlockBlob file) { var name = file.Name.Substring(file.Name.LastIndexOf('/') == 0 ? 0 : file.Name.LastIndexOf('/') + 1); var path = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, @"..\appData\Imports\Catalog"); var zipFile = Path.Combine(path, name); var zipDirectory = new DirectoryInfo(Path.Combine(path, name.Replace(".zip", ""))); if (zipDirectory.Exists) { zipDirectory.Delete(true); } zipDirectory.Create(); file.DownloadToFile(zipFile, FileMode.Create); System.IO.Compression.ZipFile.ExtractToDirectory(zipFile, zipDirectory.FullName); var assests = zipDirectory.GetFiles("ProductAssets*") .FirstOrDefault(); var catalogXml = zipDirectory.GetFiles("*.xml") .FirstOrDefault(); if (catalogXml == null || assests == null) { throw new Exception("Zip does not contain catalog.xml or ProductAssets.episerverdata"); } var catalogFolder = ContentRepository.GetChildren <ContentFolder>(ContentReference.GlobalBlockFolder) .FirstOrDefault(_ => _.Name.Equals("Catalogs")); if (catalogFolder == null) { catalogFolder = ContentRepository.GetDefault <ContentFolder>(ContentReference.GlobalBlockFolder); catalogFolder.Name = "Catalogs"; ContentRepository.Save(catalogFolder, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess); } using (var assetStream = assests.OpenRead()) { EPiServer.Find.Cms.EventedIndexingSettings.Instance.EventedIndexingEnabled = false; EPiServer.Find.Cms.EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = false; InstallService.ImportEpiserverContent(assetStream, catalogFolder.ContentLink); EPiServer.Find.Cms.EventedIndexingSettings.Instance.EventedIndexingEnabled = true; EPiServer.Find.Cms.EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = true; } using (var catalogStream = catalogXml.OpenRead()) { InstallService.ImportCatalog(catalogStream); } }
protected virtual void CreateCatalog(HttpPostedFileBase file) { if (file == null || file.InputStream == null) { throw new Exception("File is required"); } var name = file.FileName.Substring(file.FileName.LastIndexOf("\\") == 0 ? 0 : file.FileName.LastIndexOf("\\") + 1); var path = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, @"..\appData\Imports\Catalog"); var zipFile = Path.Combine(path, name); var zipDirectory = new DirectoryInfo(Path.Combine(path, name.Replace(".zip", ""))); if (zipDirectory.Exists) { zipDirectory.Delete(true); } zipDirectory.Create(); var zipInputStream = new ZipFile(file.InputStream); zipInputStream.IsStreamOwner = false; foreach (ZipEntry zipEntry in zipInputStream) { if (!zipEntry.IsFile) { continue; } var entryFileName = zipEntry.Name; var zipStream = zipInputStream.GetInputStream(zipEntry); using (var fs = new FileStream(Path.Combine(zipDirectory.FullName, entryFileName), FileMode.Create, FileAccess.ReadWrite)) { zipStream.CopyTo(fs); } } var assests = zipDirectory.GetFiles("ProductAssets*") .FirstOrDefault(); var catalogXml = zipDirectory.GetFiles("*.xml") .FirstOrDefault(); if (catalogXml == null || assests == null) { throw new Exception("Zip does not contain catalog.xml or ProductAssets.episerverdata"); } var catalogFolder = ContentRepository.GetChildren <ContentFolder>(ContentReference.GlobalBlockFolder) .FirstOrDefault(_ => _.Name.Equals("Catalogs")); if (catalogFolder == null) { catalogFolder = ContentRepository.GetDefault <ContentFolder>(ContentReference.GlobalBlockFolder); catalogFolder.Name = "Catalogs"; ContentRepository.Save(catalogFolder, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess); } EPiServer.Find.Cms.EventedIndexingSettings.Instance.EventedIndexingEnabled = false; EPiServer.Find.Cms.EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = false; InstallService.ImportEpiserverContent(assests.OpenRead(), catalogFolder.ContentLink); InstallService.ImportCatalog(catalogXml.OpenRead()); EPiServer.Find.Cms.EventedIndexingSettings.Instance.EventedIndexingEnabled = true; EPiServer.Find.Cms.EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = true; }