Example #1
0
        public void TestGenerateValidFilename()
        {
            //Arrange
            DateTime date = new DateTime(2017, 1, 23, 13, 47, 52);

            //Act
            var filename = FilenameGenerator.CreateFilename("My test filename", FileType.ExcelXlsx, date);

            //Assert
            Assert.AreEqual("My test filename_20170123_13h47m52s.xlsx", filename);
        }
Example #2
0
        /// <summary>
        /// Generates a CSV file with grid based counts of number of species observations for each selected taxon.
        /// </summary>
        /// <param name="filename">
        /// The filename (without file extension).
        /// </param>
        /// <param name="convertCountToOccurrenceBoolean">
        /// If set to <c>true</c> the observation count will be written as 1 if the count > 0 and 0 if count = 0;
        /// If set to <c>false</c> the observation count will be written.
        /// </param>
        /// <returns>
        /// A CSV file.
        /// </returns>
        private FileResult TaxonSpecificGridStatisticsOnSpeciesObservationCountsAsCsv(string filename, bool convertCountToOccurrenceBoolean)
        {
            SpeciesObservationGridCalculator resultCalculator     = new SpeciesObservationGridCalculator(GetCurrentUser(), SessionHandler.MySettings);
            TaxonSpecificGridSpeciesObservationCountResult result = resultCalculator.CalculateMultipleSpeciesObservationGrid();
            TaxonSpecificSpeciesObservationCountGridCsv    file   = FileExportManager.GetTaxonSpecificGridStatisticsOnSpeciesObservationCountsAsCsv(result, convertCountToOccurrenceBoolean);
            MemoryStream returnStream = file.ToStream();

            SetServerDone();
            return(File(
                       returnStream.ToArray(),
                       "text/csv",
                       FilenameGenerator.CreateFilename(filename, FileType.Csv)));
        }
Example #3
0
        /// <summary>
        /// Generates an GeoJson (.geojson) file with grid statistics on species richness.
        /// </summary>
        /// <returns>A .geojson file.</returns>
        public FileResult GridStatisticsOnSpeciesRichnessAsGeoJson()
        {
            TaxonGridCalculator resultCalculator = null;
            string geojson = null;

            resultCalculator = new TaxonGridCalculator(GetCurrentUser(), SessionHandler.MySettings);
            geojson          = resultCalculator.GetTaxonGridAsGeoJson();
            SetServerDone();
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(geojson);
            return(File(
                       bytes,
                       "application/json",
                       FilenameGenerator.CreateFilename("SpeciesRichnessGrid", FileType.GeoJSON)));
        }
Example #4
0
        /// <summary>
        /// Generates an GeoJson (.geojson) file with grid statistics on species observation counts.
        /// </summary>
        /// <returns>A .geojson file.</returns>
        public FileResult GridStatisticsOnSpeciesObservationCountsAsGeoJson()
        {
            SpeciesObservationGridCalculator resultCalculator = null;
            string geojson = null;
            CalculatedDataItem <FeatureCollection> result;

            resultCalculator = new SpeciesObservationGridCalculator(GetCurrentUser(), SessionHandler.MySettings);
            geojson          = resultCalculator.GetSpeciesObservationGridAsGeoJson();
            SetServerDone();
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(geojson);
            return(File(
                       bytes,
                       "application/json",
                       FilenameGenerator.CreateFilename("SpeciesObservationCountsGrid", FileType.GeoJSON)));
        }
Example #5
0
 /// <summary>
 /// Renders the species observation grid map to a png file.
 /// </summary>
 /// <returns>A png image.</returns>
 public ActionResult SpeciesObservationGridMapImage()
 {
     SetServerDone();
     try
     {
         FileStreamResult fileStream = CreateImageUsingPhantomJs(Url.Action("SpeciesObservationGridMap", "Result"), "mainPanel", 1.5);
         return(File(
                    fileStream.FileStream,
                    "image/png",
                    FilenameGenerator.CreateFilename("SpeciesObservationGridMap", FileType.Png)));
     }
     catch (Exception e)
     {
         Logger.WriteException(e);
         throw new Exception("An error occurred when generating the image.", e);
     }
 }
Example #6
0
        /// <summary>
        /// Method that generates an CSV file with species observations.
        /// </summary>
        /// <param name="presentationCoordinateSystem">Coordinate system to use.</param>
        /// <param name="columnsSet">Which columns set to use.</param>
        /// <param name="columnsHeadersType">Columns headers type to use.</param>
        /// <returns>A CSV file.</returns>
        public FileResult SpeciesObservationsAsCsv(
            int?presentationCoordinateSystem,
            int?columnsSet,
            int?columnsHeadersType)
        {
            if (NoFilterSelected)
            {
                throw new Exception("Too much data! You must set taxa filter or spatial filter.");
            }
            var coordinateSystemId = GetCoordinateSystemIdFromArgument(
                presentationCoordinateSystem,
                SessionHandler.MySettings.Presentation.Map.DownloadCoordinateSystemId);

            SpeciesObservationTableColumnsSetId speciesObservationTableColumnsSetId =
                GetSpeciesObservationTableColumnsSetIdFromArgument(
                    columnsSet,
                    SessionHandler.MySettings.Presentation.Table.SpeciesObservationTable.SpeciesObservationTableColumnsSetId);

            bool useLabelAsColumnHeader = GetUselabelAsColumnHeaderFromArgument(
                columnsHeadersType,
                SessionHandler.MySettings.Presentation.Table.SpeciesObservationTable.UseLabelAsColumnHeader);

            SpeciesObservationResultCalculator          resultCalculator = new SpeciesObservationResultCalculator(GetCurrentUser(), SessionHandler.MySettings);
            List <Dictionary <ViewTableField, string> > result           =
                resultCalculator.GetTableResult(
                    coordinateSystemId,
                    speciesObservationTableColumnsSetId);

            SpeciesObservationsCsv file = FileExportManager.GetSpeciesObservationsAsCsv(
                result,
                useLabelAsColumnHeader);
            MemoryStream returnStream = file.ToStream();

            SetServerDone();
            return(File(
                       returnStream.ToArray(),
                       "text/csv",
                       FilenameGenerator.CreateFilename("SpeciesObservations", FileType.Csv)));
        }
Example #7
0
        /// <summary>
        /// Generates an GeoJson (.geojson) file with the spatial filter.
        /// </summary>
        /// <returns>A .geojson file.</returns>
        public FileResult SpatialFilterAsGeoJson()
        {
            FeatureCollection featureCollection;

            try
            {
                SpatialFilterViewManager viewManager = new SpatialFilterViewManager(GetCurrentUser(), SessionHandler.MySettings);
                featureCollection     = viewManager.GetSpatialFilterAsFeatureCollection();
                featureCollection.CRS = new NamedCRS(SessionHandler.MySettings.Presentation.Map.PresentationCoordinateSystemId.EpsgCode());
            }
            catch (Exception)
            {
                throw;
            }

            SetServerDone();
            string geojson = JsonConvert.SerializeObject(featureCollection, JsonHelper.GetDefaultJsonSerializerSettings());

            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(geojson);
            return(File(
                       bytes,
                       "application/json",
                       FilenameGenerator.CreateFilename("SpatialFilter", FileType.GeoJSON)));
        }
Example #8
0
 /// <summary>
 /// Creates the file name of the XLSX excel file.
 /// </summary>
 /// <param name="name">The name of the Excel file.</param>
 /// <returns>A valid filename.</returns>
 private string CreateXlsxExcelFileName(string name)
 {
     return(FilenameGenerator.CreateFilename(name, FileType.ExcelXlsx));
 }