public MemoryStream ExportApp(bool includeContentGroups = false, bool resetAppGuid = false) { // Get Export XML var attributeSets = _sexy.GetAvailableContentTypes(SexyContent.AttributeSetScope).ToList(); attributeSets.AddRange(_sexy.GetAvailableContentTypes(SexyContent.AttributeSetScopeApps)); attributeSets = attributeSets.Where(a => !a.UsesConfigurationOfAttributeSet.HasValue).ToList(); var attributeSetIds = attributeSets.Select(p => p.AttributeSetId.ToString()).ToArray(); var entities = SexyContent.GetInitialDataSource(_zoneId, _appId).Out["Default"].List.Where(e => e.Value.AssignmentObjectTypeId != SexyContent.AssignmentObjectTypeIDSexyContentTemplate && e.Value.AssignmentObjectTypeId != Constants.AssignmentObjectTypeIdFieldProperties).ToList(); if (!includeContentGroups) entities = entities.Where(p => p.Value.Type.StaticName != _sexycontentContentgroupName).ToList(); var entityIds = entities .Select(e => e.Value.EntityId.ToString()).ToArray(); var messages = new List<ExportImportMessage>(); var xmlExport = new XmlExporter(_zoneId, _appId, true,attributeSetIds, entityIds); #region reset App Guid if necessary if (resetAppGuid) { var root = xmlExport.ExportXDocument;//.Root; var appGuid = root.XPathSelectElement("/SexyContent/Header/App").Attribute("Guid"); appGuid.Value = _blankGuid; } #endregion string xml = xmlExport.GenerateNiceXml(); #region Copy needed files to temporary directory var temporaryDirectoryPath = HttpContext.Current.Server.MapPath(Path.Combine(SexyContent.TemporaryDirectory, Guid.NewGuid().ToString())); if (!Directory.Exists(temporaryDirectoryPath)) Directory.CreateDirectory(temporaryDirectoryPath); var tempDirectory = new DirectoryInfo(temporaryDirectoryPath); var appDirectory = tempDirectory.CreateSubdirectory("Apps/" + _sexy.App.Folder + "/"); var sexyDirectory = appDirectory.CreateSubdirectory(_zipFolderForAppStuff); var portalFilesDirectory = appDirectory.CreateSubdirectory(_zipFolderForPortalFiles); // Copy app folder if (Directory.Exists(_sexy.App.PhysicalPath)) { FileManager.CopyAllFiles(sexyDirectory.FullName, false, messages); } // Copy PortalFiles foreach (var file in xmlExport.ReferencedFiles) { var portalFilePath = Path.Combine(portalFilesDirectory.FullName, Path.GetDirectoryName(file.RelativePath.Replace('/','\\'))); if (!Directory.Exists(portalFilePath)) Directory.CreateDirectory(portalFilePath); File.Copy(file.PhysicalPath, Path.Combine(portalFilesDirectory.FullName, file.RelativePath.Replace('/', '\\'))); } // Save export xml File.AppendAllText(Path.Combine(appDirectory.FullName, _AppXmlFileName), xml); #endregion // Zip directory and return as stream var stream = new MemoryStream(); var zipStream = new ZipOutputStream(stream); zipStream.SetLevel(6); ZipFolder(tempDirectory.FullName + "\\", tempDirectory.FullName + "\\", zipStream); zipStream.Finish(); tempDirectory.Delete(true); return stream; }
public MemoryStream ExportApp(bool includeContentGroups = false, bool resetAppGuid = false) { // Get Export XML var attributeSets = App.TemplateManager.GetAvailableContentTypes(true); attributeSets = attributeSets.Where(a => !a.ConfigurationIsOmnipresent); var attributeSetIds = attributeSets.Select(p => p.AttributeSetId.ToString()).ToArray(); var entities = DataSource.GetInitialDataSource(_zoneId, _appId).Out["Default"].List.Where(e => e.Value.AssignmentObjectTypeId != ContentTypeHelpers.AssignmentObjectTypeIDSexyContentTemplate && e.Value.AssignmentObjectTypeId != Constants.AssignmentObjectTypeIdFieldProperties).ToList(); if (!includeContentGroups) { entities = entities.Where(p => p.Value.Type.StaticName != _sexycontentContentgroupName).ToList(); } var entityIds = entities .Select(e => e.Value.EntityId.ToString()).ToArray(); var messages = new List <ExportImportMessage>(); var xmlExport = new XmlExporter(_zoneId, _appId, true, attributeSetIds, entityIds); #region reset App Guid if necessary if (resetAppGuid) { var root = xmlExport.ExportXDocument;//.Root; var appGuid = root.XPathSelectElement("/SexyContent/Header/App").Attribute("Guid"); appGuid.Value = _blankGuid; } #endregion string xml = xmlExport.GenerateNiceXml(); #region Copy needed files to temporary directory var randomShortFolderName = Guid.NewGuid().ToString().Substring(0, 4); var temporaryDirectoryPath = HttpContext.Current.Server.MapPath(Path.Combine(Settings.TemporaryDirectory, randomShortFolderName)); if (!Directory.Exists(temporaryDirectoryPath)) { Directory.CreateDirectory(temporaryDirectoryPath); } AddInstructionsToPackageFolder(temporaryDirectoryPath); var tempDirectory = new DirectoryInfo(temporaryDirectoryPath); var appDirectory = tempDirectory.CreateSubdirectory("Apps/" + App.Folder + "/"); var sexyDirectory = appDirectory.CreateSubdirectory(_zipFolderForAppStuff); var portalFilesDirectory = appDirectory.CreateSubdirectory(_zipFolderForPortalFiles); // Copy app folder if (Directory.Exists(App.PhysicalPath)) { FileManager.CopyAllFiles(sexyDirectory.FullName, false, messages); } // Copy PortalFiles foreach (var file in xmlExport.ReferencedFiles) { var portalFilePath = Path.Combine(portalFilesDirectory.FullName, Path.GetDirectoryName(file.RelativePath.Replace('/', '\\'))); if (!Directory.Exists(portalFilePath)) { Directory.CreateDirectory(portalFilePath); } if (File.Exists(file.PhysicalPath)) { var fullPath = Path.Combine(portalFilesDirectory.FullName, file.RelativePath.Replace('/', '\\')); try { File.Copy(file.PhysicalPath, fullPath); } catch (Exception e) { throw new Exception("Error on " + fullPath + " (" + fullPath.Length + ")", e); } } } // Save export xml File.AppendAllText(Path.Combine(appDirectory.FullName, _AppXmlFileName), xml); #endregion // Zip directory and return as stream var stream = new MemoryStream(); var zipStream = new ZipOutputStream(stream); zipStream.SetLevel(6); ZipFolder(tempDirectory.FullName + "\\", tempDirectory.FullName + "\\", zipStream); zipStream.Finish(); tempDirectory.Delete(true); return(stream); }