/// <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)); }
private JsonModel GetGridResult(CancellationToken ct) { JsonModel jsonModel; try { if (ct.IsCancellationRequested) { return(null); } MySettings mySettings = Session["mySettings"] as MySettings; // mySettings.Filter.Taxa.TaxonIds = new ObservableCollection<int>() { 5, 7, 8, 11, 14, 16 }; //mySettings.Filter.Taxa.TaxonIds = new ObservableCollection<int>() { 5, 7, 8, 11, 14, 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40 }; mySettings.Filter.Taxa.IsActive = true; IUserContext userContext = CoreData.UserManager.GetCurrentUser(); IList <IGridCellSpeciesObservationCount> res = GetSpeciesObservationGridCellResultFromWebService(userContext, mySettings); SpeciesObservationGridResult model = SpeciesObservationGridResult.Create(res); //SpeciesObservationGridResult model = resultsManager.GetSpeciesObservationGridCellResult(); jsonModel = JsonModel.CreateFromObject(model); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(jsonModel); }
/// <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)); }
/// <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)); }
/// <summary> /// Returns all WMS layers stored in MySettings /// </summary> /// <returns></returns> public JsonNetResult GetWmsLayers() { JsonModel jsonModel; try { var viewManager = new WmsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings); List <WmsLayerViewModel> wmsLayers = viewManager.GetWmsLayers(); jsonModel = JsonModel.Create(wmsLayers); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
public JsonNetResult ChangeButtonCheckStateAjax(int identifier, bool checkValue) { JsonModel jsonModel; try { StateButtonModel buttonModel = StateButtonManager.GetButton(identifier); buttonModel.IsChecked = checkValue; jsonModel = JsonModel.CreateFromObject(new { Identifier = identifier, IsChecked = buttonModel.IsChecked }); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
public JsonNetResult GetWfsLayerSettings(int id) { JsonModel jsonModel; try { var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings); WfsLayerViewModel model = viewManager.CreateWfsLayerViewModel(id); jsonModel = JsonModel.CreateFromObject(model); } 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> /// Returns all Regions stored in MySettings. /// </summary> /// <returns></returns> public JsonNetResult GetAllRegions() { JsonModel jsonModel; try { var viewManager = new SpatialFilterViewManager(GetCurrentUser(), SessionHandler.MySettings); List <RegionViewModel> regions = viewManager.GetAllRegions(); jsonModel = JsonModel.Create(regions); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
/// <summary> /// Returns all table fields that can be selected in a custom table. /// </summary> /// <returns>All table fields that can be selected in a custom table.</returns> public JsonNetResult GetAllSelectableTableFields() { JsonModel jsonModel; try { var viewManager = new SpeciesObservationFieldDescriptionViewManager(GetCurrentUser(), SessionHandler.MySettings); List <TableFieldDescriptionViewModel> tableFields = viewManager.GetAllSelectableTableFields(); jsonModel = JsonModel.Create(tableFields); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
/// <summary> /// Gets the logged in users all uploaded gis layers. /// </summary> /// <returns></returns> public JsonNetResult GetAllUploadedGisLayers() { JsonModel jsonModel; try { var viewManager = new WfsLayersViewManager(GetCurrentUser(), SessionHandler.MySettings); var uploadedGisLayers = viewManager.GetAllUploadedGisFiles(); jsonModel = JsonModel.Create(uploadedGisLayers); } 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)); }
/// <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)); }
public JsonNetResult Query1(string id) { JsonModel jsonModel; try { var sleepTime = TimeSpan.FromMilliseconds(random.Next(2000, 20000)); Thread.Sleep(sleepTime); System.Diagnostics.Debug.WriteLine(string.Format("{0} finished after {1} seconds", id, sleepTime.Seconds)); jsonModel = JsonModel.CreateFromObject(string.Format("{0} finished after {1} seconds", id, sleepTime.Seconds)); } 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)); }
public JsonNetResult GetAvailableWorkerThreads() { JsonModel jsonModel; try { int availableWorker, availableIO; int maxWorker, maxIO; ThreadPool.GetAvailableThreads(out availableWorker, out availableIO); ThreadPool.GetMaxThreads(out maxWorker, out maxIO); jsonModel = JsonModel.CreateFromObject(new { AvailableWorkers = availableWorker, MaxWorkers = maxWorker, AvailableIO = availableIO, MaxIO = maxIO }); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
public JsonNetResult GetMountains() { JsonModel jsonModel; try { var dictionary = new Dictionary <string, int>(); dictionary.Add("Mount Everest", 8848); dictionary.Add("Kilimanjaro", 5892); dictionary.Add("Kebnekaise", 2102); jsonModel = JsonModel.CreateFromObject(dictionary); } 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> /// 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 ActivateDeactivateSetting(MySettingsSummaryItemIdentifier identifier, bool checkValue) { JsonModel jsonModel; try { var model = new MySettingsSummaryViewModel(); var setting = (from sg in model.SettingGroups from i in sg.Items where i.Identifier == identifier select i).FirstOrDefault(); setting.IsActive = checkValue; jsonModel = JsonModel.CreateFromObject(true); } 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 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)); }
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 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 GetObservations() { JsonModel jsonModel; try { IUserContext user = CoreData.UserManager.GetCurrentUser(); var obsSearchCriteria = new SpeciesObservationSearchCriteria { TaxonIds = new List <int> { 100573 }, IncludePositiveObservations = true }; var coordinateSystem = new CoordinateSystem { Id = CoordinateSystemId.GoogleMercator }; //CoordinateSystemId.SWEREF99 user.CurrentRole = user.CurrentRoles[0]; var obsList = new SpeciesObservationList(); SpeciesObservationFieldList fieldList = new SpeciesObservationFieldList(); if (obsSearchCriteria.TaxonIds.Count > 0) { obsList = CoreData.SpeciesObservationManager.GetSpeciesObservations(user, obsSearchCriteria, coordinateSystem); } IList <ISpeciesObservation> resultList = obsList.GetGenericList(); var observationObject = GetObservationsObject(resultList); jsonModel = JsonModel.CreateFromObject(observationObject); } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } return(new JsonNetResult(jsonModel)); }
public JsonNetResult GetJSONExample(int number, string company) { JsonModel jsonModel; try { Thread.Sleep(2000); // simulate processing time if (company == "Saab") { jsonModel = JsonModel.CreateFailure("This company doesn't exist anymore"); } else { var result = new WorkPlaceModel(100 / number, company); jsonModel = JsonModel.CreateFromObject(result); } } catch (Exception ex) { jsonModel = JsonModel.CreateFailure(ex.Message); } 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)); }