Beispiel #1
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);
 }
Beispiel #2
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));
 }
Beispiel #3
0
        /// <summary>
        /// Export the specified collection of sightings to a CSV file
        /// </summary>
        /// <param name="sightings"></param>
        /// <param name="file"></param>
        public void Export(IEnumerable <Sighting> sightings, string file)
        {
            using (StreamWriter writer = new StreamWriter(file))
            {
                string headers = string.Join(",", ColumnHeaders);
                writer.WriteLine(headers);

                int count = 0;
                foreach (Sighting sighting in sightings)
                {
                    writer.WriteLine(sighting.ToCsv());
                    count++;
                    RecordExport?.Invoke(this, new SightingDataExchangeEventArgs {
                        RecordCount = count, Sighting = sighting
                    });
                }
            }
        }
        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 IsBlank(this RecordExport option)
 {
     return(option == RecordExport.Blank);
 }