Пример #1
0
        private XmlExporter GenerateExportXml(bool includeContentGroups, bool resetAppGuid)
        {
// 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 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;
            }
            return(xmlExport);

            #endregion
        }
Пример #2
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            pnlChoose.Visible = false;

            var contentTypeIds = txtSelectedContentTypes.Text.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
            var entityIds = txtSelectedEntities.Text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            //var templateIds = txtSelectedTemplates.Text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            var messages = new List<ExportImportMessage>();
            var xml = new XmlExporter(_zoneId, _appId, false, contentTypeIds, entityIds).GenerateNiceXml();

            Response.Clear();
            Response.Write(xml);
            Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", "SexyContent-Export.xml"));
            Response.AddHeader("Content-Length", xml.Length.ToString());
            Response.ContentType = "text/xml";
            Response.End();
        }
Пример #3
0
        public HttpResponseMessage ExportContent(int appId, int zoneId, string contentTypeIdsString, string entityIdsString, string templateIdsString)
        {
            EnsureUserIsAdmin();

            var appWrapper = (UserInfo.IsSuperUser)
                ? new SxcAppWrapper(zoneId, appId)  // only super-user may switch to another zone for export
                : new SxcAppWrapper(appId);

            var fileName = $"2sxcContentExport_{appWrapper.GetNameWithoutSpecialChars()}_{appWrapper.GetVersion()}.xml";
            var fileXml = new XmlExporter
            (
                zoneId,
                appId,
                false,
                contentTypeIdsString?.Split(';') ?? new string[0],
                entityIdsString?.Split(';') ?? new string[0]
            ).GenerateNiceXml();

            return HttpResponseMessageHelper.GetAttachmentHttpResponseMessage(fileName, "text/xml", fileXml);
        }
Пример #4
0
        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;
        }
Пример #5
0
        private XmlExporter GenerateExportXml(bool includeContentGroups, bool resetAppGuid)
        {
            // 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 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;
            }
            return xmlExport;
            #endregion
        }
Пример #6
0
        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);
        }