/// <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)); }
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); }
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 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 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)); }
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)); }
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)); }
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)); }