示例#1
0
        /// <summary>
        /// Serialize 2SexyContent data to an xml string.
        /// </summary>
        /// <param name="zoneId">ID of 2SexyContent zone</param>
        /// <param name="applicationId">ID of 2SexyContent application</param>
        /// <param name="contentTypeId">ID of 2SexyContent type</param>
        /// <param name="languageSelected">Language of the data to be serialized (null for all languages)</param>
        /// <param name="languageFallback">Language fallback of the system</param>
        /// <param name="languageScope">Languages supported of the system</param>
        /// <param name="languageReference">How value references to other languages are handled</param>
        /// <param name="resourceReference">How value references to files and pages are handled</param>
        /// <param name="selectedIds">array of IDs to export only these</param>
        /// <returns>A string containing the xml data</returns>
        public string CreateXml(int zoneId, int applicationId, int contentTypeId, string languageSelected, string languageFallback, IEnumerable<string> languageScope, LanguageReferenceExport languageReference, ResourceReferenceExport resourceReference, int[] selectedIds)
        {
            var contentType = GetContentType(zoneId, applicationId, contentTypeId);
            if (contentType == null)
                return null;

            var languages = new List<string>();
            if (!string.IsNullOrEmpty(languageSelected))
            {
                languages.Add(languageSelected);
            }
            else if (languageScope.Any())
            {   // Export all languages
                languages.AddRange(languageScope);
            }
            else
            {
                languages.Add(string.Empty);
            }

            var documentRoot = GetDocumentRoot(null);
            var document = GetDocument(documentRoot);

            var entities = contentType.Entities.Where(entity => entity.ChangeLogIDDeleted == null);
            if (selectedIds != null && selectedIds.Length > 0)
                entities = entities.Where(e => selectedIds.Contains(e.EntityID));

            foreach (var entity in entities)
            {

                foreach (var language in languages)
                {
                    var documentElement = GetDocumentEntityElement(entity.EntityGUID, language, contentType.Name);
                    documentRoot.Add(documentElement);

                    var attributes = contentType.GetAttributes();
                    foreach (var attribute in attributes)
                    {
                        if (attribute.Type == "Entity")
                        {   // Handle separately
                            documentElement.AppendEntityReferences(entity, attribute);
                        }
                        else if (languageReference.IsResolve())
                        {
                            documentElement.AppendValueResolved(entity, attribute, language, languageFallback, resourceReference);
                        }
                        else
                        {
                            documentElement.AppendValueReferenced(entity, attribute, language, languageFallback, languageScope, languages.Count() > 1, resourceReference);
                        }
                    }
                }
            }

            return document.ToString();
        }
示例#2
0
 public HttpResponseMessage ExportContent(int appId, string language, string defaultLanguage, string contentType,
     RecordExport recordExport, ResourceReferenceExport resourcesReferences,
     LanguageReferenceExport languageReferences, string selectedIds = null)
 {
     // do security check
     if(!PortalSettings.UserInfo.IsInRole(PortalSettings.AdministratorRoleName))// todo: copy to 8.5 "Administrators")) // note: user.isinrole didn't work
         throw new HttpRequestException("Needs admin permissions to do this");
     return eavCtc.ExportContent(appId, language, defaultLanguage, contentType, recordExport, resourcesReferences,
         languageReferences, selectedIds);
 }
示例#3
0
 public HttpResponseMessage ExportContent(int appId, string language, string defaultLanguage, string contentType,
                                          RecordExport recordExport, ResourceReferenceExport resourcesReferences,
                                          LanguageReferenceExport languageReferences)
 {
     // do security check
     if (!PortalSettings.UserInfo.IsInRole("Administrators")) // note: user.isinrole didn't work
     {
         throw new HttpRequestException("Needs admin permissions to do this");
     }
     return(eavCtc.ExportContent(appId, language, defaultLanguage, contentType, recordExport, resourcesReferences,
                                 languageReferences));
 }
        public HttpResponseMessage ExportContent(int appId, string language, string defaultLanguage, string contentType,
            RecordExport recordExport, ResourceReferenceExport resourcesReferences,
            LanguageReferenceExport languageReferences, string selectedIds = null)
        {
            AppId = appId;

            // todo: continue here!
            var ct = CurrentContext.AttribSet.GetAttributeSetWithEitherName(contentType);
            var contentTypeId = ct.AttributeSetID;// GetContentTypeId(contentType);
            var contentTypeName = ct.Name;// GetContentTypeName(contentType);
            var contextLanguages = GetContextLanguages();

            // check if we have an array of ids
            int[] ids = null;
            try
            {
                if (recordExport == RecordExport.Selection && !string.IsNullOrWhiteSpace(selectedIds))
                    ids = selectedIds.Split(',').Select(int.Parse).ToArray();
            }
            catch (Exception e)
            {
                throw new Exception("trouble finding selected IDs to export", e);
            }

            var fileContent = recordExport == RecordExport.Blank
                ? new XmlExport().CreateBlankXml(CurrentContext.ZoneId, appId, contentTypeId) 
                : new XmlExport().CreateXml(CurrentContext.ZoneId, appId, contentTypeId, language ?? "", defaultLanguage, contextLanguages, languageReferences, resourcesReferences, ids);

            var fileName = $"2sxc {contentTypeName.Replace(" ", "-")} {language} {(recordExport == RecordExport.Blank ? "Template" : "Data")} {DateTime.Now.ToString("yyyyMMddHHmmss")}.xml";

            var response = new HttpResponseMessage(HttpStatusCode.OK);
            response.Content = new StringContent(fileContent);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/xml");
            response.Content.Headers.ContentLength = fileContent.Length;
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = fileName
            };
            return response;
        }
 public static bool IsLink(this LanguageReferenceExport option)
 {
     return(option == LanguageReferenceExport.Link);
 }
 public static bool IsResolve(this LanguageReferenceExport option)
 {
     return(option == LanguageReferenceExport.Resolve);
 }
示例#7
0
        /// <summary>
        /// Serialize 2SexyContent data to an xml string.
        /// </summary>
        /// <param name="zoneId">ID of 2SexyContent zone</param>
        /// <param name="applicationId">ID of 2SexyContent application</param>
        /// <param name="contentTypeId">ID of 2SexyContent type</param>
        /// <param name="languageSelected">Language of the data to be serialized (null for all languages)</param>
        /// <param name="languageFallback">Language fallback of the system</param>
        /// <param name="languageScope">Languages supported of the system</param>
        /// <param name="languageReference">How value references to other languages are handled</param>
        /// <param name="resourceReference">How value references to files and pages are handled</param>
        /// <returns>A string containing the xml data</returns>
        public string CreateXml(int zoneId, int applicationId, int contentTypeId, string languageSelected, string languageFallback, IEnumerable <string> languageScope, LanguageReferenceExport languageReference, ResourceReferenceExport resourceReference)
        {
            var contentType = GetContentType(zoneId, applicationId, contentTypeId);

            if (contentType == null)
            {
                return(null);
            }

            var languages = new List <string>();

            if (!string.IsNullOrEmpty(languageSelected))
            {
                languages.Add(languageSelected);
            }
            else if (languageScope.Any())
            {   // Export all languages
                languages.AddRange(languageScope);
            }
            else
            {
                languages.Add(string.Empty);
            }

            var documentRoot = GetDocumentRoot(contentType.Name, null);
            var document     = GetDocument(documentRoot);

            var entities = contentType.Entities.Where(entity => entity.ChangeLogIDDeleted == null);

            foreach (var entity in entities)
            {
                foreach (var language in languages)
                {
                    var documentElement = GetDocumentEntityElement(entity.EntityGUID, language);
                    documentRoot.Add(documentElement);

                    var attributes = contentType.GetAttributes();
                    foreach (var attribute in attributes)
                    {
                        if (languageReference.IsResolve())
                        {
                            documentElement.AppendValueResolved(entity, attribute, language, languageFallback, resourceReference);
                        }
                        else
                        {
                            documentElement.AppendValueReferenced(entity, attribute, language, languageFallback, languageScope, languages.Count() > 1, resourceReference);
                        }
                    }
                }
            }

            return(document.ToString());
        }