public HttpResponseMessage RequestPointDetails(decimal latitude, decimal longitude, int identifier, decimal zoomLevel, string username, string datasetName, PointsSource pointsSource) { DomainInstance databaseInteractionHandler = new DomainInstance(); //*zoomLevel is not required anymore var point = databaseInteractionHandler.RequestPointDetails(datasetName, username, new PointBase() { Latitude = latitude, Longitude = longitude, Number = identifier }, pointsSource ); var response = new HttpResponseMessage(); response.Content = new StringContent(point.JSONSerialize()); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); return(response); }
/// <summary> /// Create an empty dataset in the database. Created dataset will wave status Pending /// </summary> /// <param name="datasetName">Name of the dataset</param> /// <param name="username">The username of the user which create the dataset</param> /// <returns>A boolean which indicates if the insert was succesufully and a return message</returns> public CreateDatasetResultCode CreateDataSet(string datasetName, string username, PointsSource pointsSource, string serviceUrl = null, string colorPaletteUser = null, string colorPaletteName = null) { int datasetId = this.userRepository.CreateUserPointsDataset(username, datasetName, pointsSource); if (pointsSource == PointsSource.Geoserver) { LayersBuilder builder = new LayersBuilder { LayerName = datasetName, SingleLayer = true }; string serverUrl = Helper.GetSourceFromUrl(serviceUrl); GeoserverClient client = geoserverClient(serverUrl, null, null); if (client.Get <Layer>(new ModulesFactory().CreateLayerModule(builder)) == null) { CoreContainers.LogsRepository.LogWarning($"Failed to get {datasetName} from Geoserver: {Helper.GetSourceFromUrl(serverUrl)}."); return(CreateDatasetResultCode.GeoserverError); } //if dataset already exists in database if (datasetId == -1) { datasetId = this.userRepository.GetDatasetID(username, datasetName); } int defaultColorPaletteId = this.userRepository.GetColorMapID(colorPaletteUser, colorPaletteName); if (defaultColorPaletteId == -1) { return(CreateDatasetResultCode.BadPaletteError); } datasetId = this.userRepository.RaiseToGeoserverDataset(datasetId, defaultColorPaletteId, serviceUrl); } return(datasetId != -1 ? CreateDatasetResultCode.Ok : CreateDatasetResultCode.DatasetError); }
public int CreateUserPointsDataset(string username, string datasetName, PointsSource pointsSource) { try { return(Convert.ToInt32(SqlExecutionInstance.ExecuteScalar(new SqlCommand("InsertPointsDataset") { CommandType = System.Data.CommandType.StoredProcedure }, new SqlParameter[] { new SqlParameter("username", username), new SqlParameter("dataset_name", datasetName), new SqlParameter("source_name", pointsSource.ToString()) }, new SqlConnection(this.connectionString)))); } catch (Exception exception) { CoreContainers.LogsRepository.LogError(exception, Core.Database.Logs.LogTrigger.DataAccess); return(-1); } }
/// <summary> /// Use this method to request details about a selected point /// </summary> /// <param name="dataSet"></param> /// <param name="username"></param> /// <param name="basicPoint"></param> /// <param name="pointsSource"></param> /// <returns></returns> public Point RequestPointDetails(string dataSet, string username, PointBase basicPoint, PointsSource pointsSource = PointsSource.Cassandra) { int dataSetID = this.userRepository.GetDatasetID(username, dataSet); if (dataSetID == -1) { throw new ApplicationException($"User do not have a dataset with name {dataSet}"); } //datasource can be switched between current dataPointsRepository and other repos IDataPointsRepository detailsSource = this.dataPointsRepository; switch (pointsSource) { case PointsSource.Geoserver: detailsSource = new PostgreSQLDataPointsRepository(); break; case PointsSource.Cassandra: default: break; } return(detailsSource.GetPointDetails(dataSetID, basicPoint)); }