/// <summary> /// Deletes the selected uploaded gis layers. /// </summary> /// <param name="filenames">The filenames.</param> /// <returns></returns> public JsonNetResult DeleteUploadedGisLayers(string[] filenames) { JsonModel jsonModel; try { jsonModel = JsonModel.CreateSuccess("Ok"); foreach (string filename in filenames) { if (!MySettingsManager.DeleteMapDataFile(GetCurrentUser(), filename)) { jsonModel = JsonModel.CreateFailure("Deleting file failed."); } //Check if file layer is in use, if so, remove it var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings); var layer = viewManager.GetWfsLayers().FirstOrDefault(l => l.Name == GetLayerName(filename)); if (layer != null) { viewManager.RemoveWfsLayer(layer.Id); } } return(new JsonNetResult(jsonModel)); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
/// <summary> /// Adds selected uploaded gis layers to WFS layers. /// </summary> /// <param name="filenames">The filenames.</param> /// <returns></returns> public JsonNetResult AddUploadedGisLayers(string[] filenames) { JsonModel jsonModel = JsonModel.CreateSuccess("Ok"); try { foreach (string filename in filenames) { if (string.IsNullOrEmpty(filename)) { jsonModel = JsonModel.CreateFailure("No file selected."); return(new JsonNetResult(jsonModel)); } try { var featureCollection = MySettingsManager.GetMapDataFeatureCollection( GetCurrentUser(), filename, CoordinateSystemId.None); if (featureCollection == null) { jsonModel = JsonModel.CreateFailure("File not found."); return(new JsonNetResult(jsonModel)); } if (AddFileWfsLayer(filename, featureCollection)) { jsonModel = JsonModel.CreateSuccess("Ok"); } else { jsonModel = JsonModel.CreateFailure(Resource.SharedLayerAlreadyExists); break; } } catch (Exception) { jsonModel = JsonModel.CreateFailure(Resource.FilterSpatialUnableToParseGeoJsonFile); break; } } } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
public JsonNetResult WriteNameAndAgeToDebug(string name, int bornYear) { JsonModel jsonModel; try { // here you can save data... int age = DateTime.Now.Year - bornYear; Debug.WriteLine("Name: {0}, Age: {1}", name, age); jsonModel = JsonModel.CreateSuccess("Name and age was successfully written to Debug output window"); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
public JsonNetResult AddRegionById(int id) { JsonModel jsonModel; try { var viewManager = new SpatialFilterViewManager(GetCurrentUser(), SessionHandler.MySettings); viewManager.AddRegion(id); jsonModel = JsonModel.CreateSuccess(string.Empty); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
/// <summary> /// Deletes a user defined table type. /// </summary> /// <param name="id">The Id of the table to delete.</param> /// <returns>Success if deletion goes well; otherwise Error message.</returns> public JsonNetResult DeleteUserDefinedTableTypeByAjax(int id) { JsonModel jsonModel = JsonModel.CreateSuccess(""); try { var viewManager = new SpeciesObservationFieldDescriptionViewManager(GetCurrentUser(), SessionHandler.MySettings); viewManager.DeleteUserDefinedTableType(id); SessionHandler.UserMessages.Add(new UserMessage(Resources.Resource.PresentationTableDeletedUserDefinedTable)); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
/// <summary> /// Removes the specified WFS layer. /// </summary> /// <param name="data">WfsLayer Id as JSON.</param> /// <returns></returns> public JsonNetResult RemoveWfsLayer(string data) { JsonModel jsonModel; try { var javascriptSerializer = new JavaScriptSerializer(); WfsLayerViewModel wfsLayerViewModel = javascriptSerializer.Deserialize <WfsLayerViewModel>(data); var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings); viewManager.RemoveWfsLayer(wfsLayerViewModel.Id); jsonModel = JsonModel.CreateSuccess(""); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
/// <summary> /// Removes the specified WMS layers. /// </summary> /// <param name="wmsLayerIds">WMS layer ids.</param> /// <returns></returns> public JsonNetResult RemoveWmsLayers(int[] wmsLayerIds) { JsonModel jsonModel; try { var viewManager = new WmsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings); viewManager.RemoveWmsLayers(wmsLayerIds); jsonModel = JsonModel.CreateSuccess(""); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
/// <summary> /// Updates a user defined table. /// </summary> /// <param name="id">The user defined table id.</param> /// <param name="data">The table data in JSON format.</param> /// <returns>Success if update goes well; otherwise Error message.</returns> public JsonNetResult EditUserDefinedTableTypeByAjax(int id, string data) { JsonModel jsonModel = JsonModel.CreateSuccess(""); try { SpeciesObservationTableTypeViewModel tableType = JsonConvert.DeserializeObject <SpeciesObservationTableTypeViewModel>(data); var viewManager = new SpeciesObservationFieldDescriptionViewManager(GetCurrentUser(), SessionHandler.MySettings); viewManager.EditUserDefinedTableType(id, tableType); SessionHandler.UserMessages.Add(new UserMessage(Resources.Resource.PresentationTableEditedUserDefinedTable)); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
public JsonNetResult RemoveRegion(string data) { JsonModel jsonModel; try { var viewManager = new SpatialFilterViewManager(GetCurrentUser(), SessionHandler.MySettings); var javascriptSerializer = new JavaScriptSerializer(); RegionViewModel regionViewModel = javascriptSerializer.Deserialize <RegionViewModel>(data); viewManager.RemoveRegion(regionViewModel.Id); jsonModel = JsonModel.CreateSuccess(string.Empty); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
public JsonNetResult UpdatePresentationReportSettings(string data) { JsonModel jsonModel; try { var javascriptSerializer = new JavaScriptSerializer(); PresentationReportViewModel reportSettingsModel = javascriptSerializer.Deserialize <PresentationReportViewModel>(data); var viewManager = new ReportSettingsViewManager(GetCurrentUser(), SessionHandler.MySettings); viewManager.UpdatePresentationReportSetting(reportSettingsModel); jsonModel = JsonModel.CreateSuccess(string.Empty); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
/// <summary> /// Update the summary statistics setting /// </summary> /// <param name="data"></param> /// <returns>JsonNetResult</returns> public JsonNetResult UpdateSummaryStatisticsSetting(string data) { JsonModel jsonModel; try { var javascriptSerializer = new JavaScriptSerializer(); SummaryStatisticsViewModel summaryStatistics = javascriptSerializer.Deserialize <SummaryStatisticsViewModel>(data); var viewManager = new SummaryStatisticsViewManager(GetCurrentUser(), SessionHandler.MySettings); viewManager.UpdateSummaryStatistics(summaryStatistics); jsonModel = JsonModel.CreateSuccess(string.Empty); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
public JsonNetResult DeleteMapDataFile(string fileName) { var jsonModel = JsonModel.CreateSuccess("Ok"); if (!MySettingsManager.DeleteMapDataFile(GetCurrentUser(), fileName)) { jsonModel = JsonModel.CreateFailure("Deleting file failed."); } //Check if file layer is in use, if so, remove it var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings); var layer = viewManager.GetWfsLayers().FirstOrDefault(l => l.Name == GetLayerName(fileName)); if (layer != null) { viewManager.RemoveWfsLayer(layer.Id); } return(new JsonNetResult(jsonModel)); }
public JsonNetResult CancelRequest(int?id) { JsonModel jsonModel; try { if (!id.HasValue) { if (CancellationDictionary.Keys.Count > 0) { id = CancellationDictionary.Keys.First(); } else { jsonModel = JsonModel.CreateFailure("There are no requests to cancel"); return(new JsonNetResult(jsonModel)); } } if (CancellationDictionary.ContainsKey(id.Value)) { CancellationDictionary[id.Value].Cancel(); System.Diagnostics.Debug.WriteLine(string.Format("GetGridResult cancelled. Id: {0}, Time {1}", id.Value, DateTime.Now.ToLongTimeString())); jsonModel = JsonModel.CreateSuccess(string.Format("Request with Id {0} was cancelled", id.Value)); } else { jsonModel = JsonModel.CreateFailure(string.Format("Request with Id {0} was not found", id.Value)); } } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
public JsonNetResult UploadMapDataFile(int?coordinateSystemId) { JsonModel jsonModel; if (Request.Files.Count == 0) { jsonModel = JsonModel.CreateFailure("No files uploaded."); return(new JsonNetResult(jsonModel)); } if (Request.Files.Count > 1) { jsonModel = JsonModel.CreateFailure("Too many files uploaded."); return(new JsonNetResult(jsonModel)); } var file = Request.Files[0]; if (file == null || file.ContentLength == 0) { jsonModel = JsonModel.CreateFailure("The file has no content."); return(new JsonNetResult(jsonModel)); } const long MAX_FILE_SIZE = 5120000; //5MB if (file.ContentLength > MAX_FILE_SIZE) { jsonModel = JsonModel.CreateFailure(string.Format("Max file size {0} MB", MAX_FILE_SIZE / 1024000)); return(new JsonNetResult(jsonModel)); } //Set file name for uploaded file and remove file suffix for layer name var fileName = file.FileName; try { var jsonString = string.Empty; if (file.ContentType == "application/zip" || file.ContentType == "application/x-zip-compressed" || fileName.ToLower().EndsWith(".zip")) //|| file.ContentType == "application/octet-stream") { jsonString = MySettingsManager.GetGeoJsonFromShapeZip(GetCurrentUser(), file.FileName, file.InputStream); //Change file suffix since we converted shape to geojson fileName = fileName.Replace(".zip", ".geojson"); } else { jsonString = new StreamReader(file.InputStream).ReadToEnd(); } /*if (MySettingsManager.MapDataFileExists(GetCurrentUser(), fileName)) * { * jsonModel = JsonModel.CreateFailure(Resource.SharedFileAlreadyExists); * return new JsonNetResult(jsonModel); * }*/ var featureCollection = JsonConvert.DeserializeObject(jsonString, typeof(FeatureCollection)) as FeatureCollection; if (featureCollection == null) { jsonModel = JsonModel.CreateFailure(Resource.UploadFileJsonSerialaztionFaild); return(new JsonNetResult(jsonModel)); } CoordinateSystem coordinateSystem = null; if (coordinateSystemId.HasValue) { coordinateSystem = new CoordinateSystem((CoordinateSystemId)coordinateSystemId.Value); } else { coordinateSystem = GisTools.GeoJsonUtils.FindCoordinateSystem(featureCollection); if (coordinateSystem.Id == CoordinateSystemId.None) { jsonModel = JsonModel.CreateFailure(Resource.FilterSpatialUnableToDetermineCoordinateSystem); return(new JsonNetResult(jsonModel)); } } //Make sure crs is saved in file if (featureCollection.CRS == null) { featureCollection.CRS = new NamedCRS(coordinateSystem.Id.EpsgCode()); } //create a Json object from string var jsonObject = JObject.FromObject(featureCollection); //Sava json to file using (var fileStream = jsonObject.ToString().ToStream()) { MySettingsManager.SaveMapDataFile(GetCurrentUser(), fileName, fileStream); } if (AddFileWfsLayer(fileName, featureCollection)) { jsonModel = JsonModel.CreateSuccess("Ok"); } else { jsonModel = JsonModel.CreateFailure(Resource.UploafFileLayerAlreadyAdded); } } catch (ImportGisFileException importGisFileException) { jsonModel = JsonModel.CreateFailure(importGisFileException.Message); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(Resource.FilterSpatialUnableToParseGeoJsonFile); } return(new JsonNetResult(jsonModel)); }