예제 #1
0
        /// <summary>
        /// Creates a species observation CSV file and stores it on the server in the
        /// Temp/Export/ folder.
        /// This can be used in workflow scenarios.
        ///
        /// </summary>
        /// <returns>JSON data with information about the URL to the generated file.</returns>
        public JsonNetResult SpeciesObservationGridAsCsvStoreFileOnServer()
        {
            JsonModel jsonModel;
            SpeciesObservationGridCalculator resultCalculator = null;
            SpeciesObservationGridResult     result           = null;

            try
            {
                IUserContext currentUser = GetCurrentUser();
                if (currentUser.IsAuthenticated() && !currentUser.IsCurrentRolePrivatePerson())
                {
                    throw new Exception(Resource.ResultWorkflowCurrentRoleIsNotPrivatePerson);
                }

                resultCalculator = new SpeciesObservationGridCalculator(currentUser, SessionHandler.MySettings);
                result           = resultCalculator.GetSpeciesObservationGridResultFromCacheIfAvailableOrElseCalculate();
                string filename = FileExportManager.CreateSpeciesObservationGridAsCsvAndStoreOnServer(currentUser, result);
                string url      = FileSystemManager.ExportFolderUrl + filename;
                jsonModel = JsonModel.CreateFromObject(url);
            }
            catch (Exception ex)
            {
                jsonModel = JsonModel.CreateFailure(ex.Message);
            }

            return(new JsonNetResult(jsonModel));
        }
예제 #2
0
        /// <summary>
        /// Method that generates an Excel (xml/xlsx) file with a time series of species observation counts.
        /// </summary>
        /// <param name="periodicity">A string value representing the alternative periodicities of the time series.</param>
        /// <param name="addSettings"></param>
        /// <param name="addProvenance"></param>
        /// <returns>An Excel file of the type xml or xlsx.</returns>
        public FileResult TimeSeriesOnSpeciesObservationCountsAsExcel(String periodicity, bool addSettings = true, bool addProvenance = true)
        {
            Periodicity periodicityEnumValue = (Periodicity)SessionHandler.MySettings.Calculation.TimeSeries.DefaultPeriodicityIndex;

            if (!string.IsNullOrEmpty(periodicity))
            {
                switch (periodicity.ToLower())
                {
                case "dayoftheyear":
                    periodicityEnumValue = Periodicity.DayOfTheYear;
                    break;

                case "weekoftheyear":
                    periodicityEnumValue = Periodicity.WeekOfTheYear;
                    break;

                case "monthoftheyear":
                    periodicityEnumValue = Periodicity.MonthOfTheYear;
                    break;

                case "daily":
                    periodicityEnumValue = Periodicity.Daily;
                    break;

                case "weekly":
                    periodicityEnumValue = Periodicity.Weekly;
                    break;

                case "monthly":
                    periodicityEnumValue = Periodicity.Monthly;
                    break;

                default:
                    periodicityEnumValue = Periodicity.Yearly;
                    break;
                }
            }

            SetServerDone();

            if (SessionHandler.MySettings.Presentation.FileFormat.ExcelFileSettings.IsSettingsDefault())
            {
                TimeSeriesOnSpeciesObservationCountsExcelXlsx file =
                    FileExportManager.GetTimeSeriesOnSpeciesObservationCountsAsExcelXlsx(
                        GetCurrentUser(),
                        periodicityEnumValue,
                        addSettings,
                        addProvenance);

                MemoryStream returnStream = file.ToStream();
                return(File(returnStream, XlsxExcelFileMimeType, CreateXlsxExcelFileName("TimeSeriesOnSpeciesObservationCounts")));
            }
            else
            {
                TimeSeriesOnSpeciesObservationCountsExcelXml file = FileExportManager.GetTimeSeriesOnSpeciesObservationCountsAsExcelXml(GetCurrentUser(), periodicityEnumValue, addSettings, addProvenance);
                MemoryStream returnStream = file.ToStream();
                return(File(returnStream, XmlExcelFileMimeType, CreateXmlExcelFileName("TimeSeriesOnSpeciesObservationCounts")));
            }
        }
예제 #3
0
        /// <summary>
        /// Method that generates an Excel (XML/XLSX) file with species observations.
        /// </summary>
        /// <param name="addSettings"></param>
        /// <param name="addProvenance"></param>
        /// <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>An Excel file of the type XML or XLSX.</returns>
        public FileResult SpeciesObservationsAsExcel(
            bool?addSettings,
            bool?addProvenance,
            int?presentationCoordinateSystem,
            int?columnsSet,
            int?columnsHeadersType)
        {
            MemoryStream returnStream;
            string       fileName;

            addSettings   = addSettings.GetValueOrDefault(true);
            addProvenance = addProvenance.GetValueOrDefault(false);
            CoordinateSystemId 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);

            if (SessionHandler.MySettings.Presentation.FileFormat.ExcelFileSettings.IsSettingsDefault())
            {
                SpeciesObservationsExcelXlsx file = FileExportManager.GetSpeciesObservationsAsExcelXlsx(
                    GetCurrentUser(),
                    addSettings.Value,
                    addProvenance.Value,
                    coordinateSystemId,
                    speciesObservationTableColumnsSetId,
                    useLabelAsColumnHeader);
                returnStream = file.ToStream();
                fileName     = CreateXlsxExcelFileName("SpeciesObservations");
            }
            else
            {
                SpeciesObservationsExcelXml file =
                    FileExportManager.GetSpeciesObservationsAsExcelXml(
                        GetCurrentUser(),
                        addSettings.Value,
                        addProvenance.Value,
                        coordinateSystemId,
                        speciesObservationTableColumnsSetId,
                        useLabelAsColumnHeader);

                returnStream = file.ToStream();
                fileName     = CreateXmlExcelFileName("SpeciesObservations");
            }

            SetServerDone();

            return(File(returnStream, XlsxExcelFileMimeType, fileName));
        }
예제 #4
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)));
        }
예제 #5
0
 /// <summary>
 /// Method that generates an Excel (xml/xlsx) file with provenances.
 /// </summary>
 /// <param name="addSettings"></param>
 /// <param name="addProvenance"></param>
 /// <returns>An Excel file of the type xml or xlsx.</returns>
 public FileResult SpeciesObservationProvenancesAsExcel(bool addSettings = true, bool addProvenance = true)
 {
     SetServerDone();
     if (SessionHandler.MySettings.Presentation.FileFormat.ExcelFileSettings.IsSettingsDefault())
     {
         SpeciesObservationProvenanceExcelXlsx file = FileExportManager.GetSpeciesObservationProvenanceAsExcelXlsx(GetCurrentUser(), addSettings, addProvenance);
         MemoryStream returnStream = file.ToStream();
         return(File(returnStream, XlsxExcelFileMimeType, CreateXlsxExcelFileName("SpeciesObservationProvenances")));
     }
     else
     {
         SpeciesObservationProvenanceExcelXml file = FileExportManager.GetSpeciesObservationProvenanceAsExcelXml(GetCurrentUser(), addSettings, addProvenance);
         MemoryStream returnStream = file.ToStream();
         return(File(returnStream, XmlExcelFileMimeType, CreateXmlExcelFileName("SpeciesObservationProvenances")));
     }
 }
예제 #6
0
        /// <summary>
        /// Method that generates an Excel (xml) file with the current selected settings.
        /// </summary>
        /// <param name="addSettings"></param>
        /// <param name="addProvenance"></param>
        /// <returns>An Excel file of the type xml.</returns>
        public FileResult SettingsReportAsExcel(bool addSettings = true, bool addProvenance = true)
        {
            SetServerDone();
            if (SessionHandler.MySettings.Presentation.FileFormat.ExcelFileSettings.IsSettingsDefault())
            {
                var file = FileExportManager.GetSettingsReportAsExcelXlsx(GetCurrentUser(), addSettings, addProvenance);

                return(File(file.ToStream(), XlsxExcelFileMimeType, CreateXlsxExcelFileName("SettingsReport")));
            }
            else
            {
                var file = FileExportManager.GetSettingsReportAsExcelXml(GetCurrentUser(), addSettings, addProvenance);

                return(File(file.ToStream(), XmlExcelFileMimeType, CreateXmlExcelFileName("SettingsReport")));
            }
        }
예제 #7
0
 /// <summary>
 /// Generates an Excel (xml/xlsx) file with species observations count per polygon and for each selected taxon.
 /// </summary>
 /// <param name="filename">
 /// The filename (without file extension).
 /// </param>
 /// <param name="formatCountAsOccurrence">
 /// 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>
 /// <param name="addSettings"></param>
 /// <param name="addProvenance"></param>
 /// <returns>
 /// A Excel file of the type xml or xlsx.
 /// </returns>
 private FileResult TaxonSpecificSpeciesObservationCountPerPolygonAsExcel(string filename, bool formatCountAsOccurrence, bool addSettings = true, bool addProvenance = true)
 {
     SetServerDone();
     if (SessionHandler.MySettings.Presentation.FileFormat.ExcelFileSettings.IsSettingsDefault())
     {
         TaxonSpecificSpeciesObservationCountPerPolygonExcelXlsx file = FileExportManager.GetTaxonSpecificSpeciesObservationCountPerPolygonAsExcelXlsx(GetCurrentUser(), formatCountAsOccurrence, addSettings, addProvenance);
         MemoryStream returnStream = file.ToStream();
         return(File(returnStream, XlsxExcelFileMimeType, CreateXlsxExcelFileName(filename)));
     }
     else
     {
         TaxonSpecificSpeciesObservationCountPerPolygonExcelXml file = FileExportManager.GetTaxonSpecificSpeciesObservationCountPerPolygonAsExcelXml(GetCurrentUser(), formatCountAsOccurrence, addSettings, addProvenance);
         MemoryStream returnStream = file.ToStream();
         return(File(returnStream, XmlExcelFileMimeType, CreateXmlExcelFileName(filename)));
     }
 }
예제 #8
0
 /// <summary>
 /// Method that generates an Excel (xml/xlsx) file with
 /// statistics on total number of species observations
 /// currently available from data providers associated with Swedish LifeWatch.
 /// </summary>
 /// <returns>An Excel file of the type xml or xlsx.</returns>
 public FileResult DataProviderStatisticsAsExcel()
 {
     SetServerDone();
     if (SessionHandler.MySettings.Presentation.FileFormat.ExcelFileSettings.IsSettingsDefault())
     {
         DataProviderListExcelXlsx file = FileExportManager.GetDataProvidersAsExcelXlsx(GetCurrentUser());
         MemoryStream returnStream      = file.ToStream();
         return(File(returnStream, XlsxExcelFileMimeType, CreateXlsxExcelFileName("DataProviders")));
     }
     else
     {
         DataProviderListExcelXml file         = FileExportManager.GetDataProvidersAsExcelXml(GetCurrentUser());
         MemoryStream             returnStream = file.ToStream();
         return(File(returnStream, XmlExcelFileMimeType, CreateXmlExcelFileName("DataProviders")));
     }
 }
예제 #9
0
 /// <summary>
 /// Method that generates an Excel (xml) file with grid based counts of number of species observations.
 /// </summary>
 /// <param name="addSettings"></param>
 /// <param name="addProvenance"></param>
 /// <returns>An Excel file of the type xml.</returns>
 public FileResult GridStatisticsOnSpeciesObservationCountsAsExcel(bool addSettings = true, bool addProvenance = true)
 {
     SetServerDone();
     if (SessionHandler.MySettings.Presentation.FileFormat.ExcelFileSettings.IsSettingsDefault())
     {
         GridStatisticsOnSpeciesObservationCountExcelXlsx file = FileExportManager.GetGridSpeciesObservationCountsAsExcelXlsx(GetCurrentUser(), SessionHandler.MySettings.Presentation.Map.DownloadCoordinateSystemId, addSettings, addProvenance);
         MemoryStream returnStream = file.ToStream();
         return(File(returnStream, XlsxExcelFileMimeType, CreateXlsxExcelFileName("GridStatisticsOnSpeciesObservationCounts")));
     }
     else
     {
         GridStatisticsOnSpeciesObservationCountExcelXml file = FileExportManager.GetGridSpeciesObservationCountsAsExcelXml(GetCurrentUser(), SessionHandler.MySettings.Presentation.Map.DownloadCoordinateSystemId, addSettings, addProvenance);
         MemoryStream returnStream = file.ToStream();
         return(File(returnStream, XmlExcelFileMimeType, CreateXmlExcelFileName("GridStatisticsOnSpeciesObservationCounts")));
     }
 }
예제 #10
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)));
        }
예제 #11
0
        public FileResult GetAOOEOOForTaxonAsExcel(bool addSettings = true, bool addProvenance = true)
        {
            if (!SessionHandler.MySettings.Filter.Taxa.HasSettings)
            {
                return(null);
            }

            string layerName;
            var    parameters = new Dictionary <string, object>()
            {
                { "alphaValue", 0 },
                { "useCenterPoint", false }
            };

            //Save current taxa filter
            var tmpTaxonIds = SessionHandler.MySettings.Filter.Taxa.TaxonIds.AsEnumerable().ToArray();

            var data = new Tuple <int, string, string, string, string> [tmpTaxonIds.Length];
            var i    = 0;

            foreach (var taxonId in tmpTaxonIds)
            {
                //Get AOO and EOO for one taxon at the time
                SessionHandler.MySettings.Filter.Taxa.ResetSettings();
                SessionHandler.MySettings.Filter.Taxa.AddTaxonId(taxonId);
                var taxon          = CoreData.TaxonManager.GetTaxon(GetCurrentUser(), taxonId);
                var scientificName = taxon.ScientificName;
                var commonName     = taxon.CommonName;

                var geoJson = MapLayerManager.GetLayerGeojson(GetCurrentUser(), MapLayerManager.EooConcaveHullLayerId, SessionHandler.MySettings.Presentation.Map.DisplayCoordinateSystem.Id, parameters, out layerName, null);
                if (geoJson != null)
                {
                    var featureCollection = JsonConvert.DeserializeObject(geoJson, typeof(FeatureCollection)) as FeatureCollection;

                    var aoo = (string)featureCollection.Features[0].Properties["AOO"];
                    var eoo = (string)featureCollection.Features[0].Properties["EOO"];

                    data[i] = new Tuple <int, string, string, string, string>(
                        taxon.Id, scientificName, commonName, aoo, eoo);
                }
                else
                {
                    data[i] = new Tuple <int, string, string, string, string>(
                        taxon.Id, scientificName, commonName, "0", "0");
                }
                i++;
            }

            //Restore taxon filter
            SessionHandler.MySettings.Filter.Taxa.AddTaxonIds(tmpTaxonIds);

            MemoryStream returnStream;
            string       fileName;

            if (SessionHandler.MySettings.Presentation.FileFormat.ExcelFileSettings.IsSettingsDefault())
            {
                var file = FileExportManager.GetSpeciesAOOEOOAsExcelXlsx(GetCurrentUser(), data, addSettings, addProvenance);
                returnStream = file.ToStream();
                fileName     = CreateXlsxExcelFileName("TaxonAOOEOO");
            }
            else
            {
                var file = FileExportManager.GetSpeciesAOOEOOAsExcelXml(GetCurrentUser(), data, addSettings, addProvenance);
                returnStream = file.ToStream();
                fileName     = CreateXmlExcelFileName("TaxonAOOEOO");
            }

            SetServerDone();

            return(File(returnStream, XlsxExcelFileMimeType, fileName));
        }