Exemplo n.º 1
0
        public HttpResponseMessage UploadFileChunk()
        {
            var databaseInteractionHandler = new DomainInstance();

            string directoryName = $"{ConfigurationManager.AppSettings["PointsDatasetsCheckpointFolder"]}\\{RouteConfig.CurrentUser.Username}";

            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }


            foreach (string file in HttpContext.Current.Request.Files)
            {
                var FileData = HttpContext.Current.Request.Files[file];

                string[] checkoutData = FileData.FileName.Split(new char[] { '_' }, 2, StringSplitOptions.RemoveEmptyEntries);

                //fileFolderName represents the path to the folder where the dataset will be stored
                string fileFolderName = $"{directoryName}\\{checkoutData[0]}";

                //If the directory for the requested file doesnt has an entry in databse, create one
                if (!Directory.Exists(fileFolderName))
                {
                    Directory.CreateDirectory(fileFolderName);
                    databaseInteractionHandler.CreateDataSet(
                        checkoutData[0],
                        RouteConfig.CurrentUser.Username,
                        PointsSource.Cassandra
                        );
                }


                if (FileData?.ContentLength > 0)
                {
                    using (var fileStream = File.Create($"{fileFolderName}\\{checkoutData[1]}"))
                        FileData.InputStream.CopyTo(fileStream);
                }
            }

            return(new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content = new StringContent("Chunk uploaded")
            });
        }
        public HttpResponseMessage UploadGeoserverLayer([FromBody] JObject data)
        {
            DomainInstance handler = new DomainInstance();


            var insertResult = handler.CreateDataSet(
                datasetName: data["name"].ToObject <string>(),
                username: RouteConfig.CurrentUser.Username,
                pointsSource: PointsSource.Geoserver,
                serviceUrl: data["apiUrl"].ToObject <string>(),
                colorPaletteName: data["defaultColorPaletteName"].ToObject <string>(),
                colorPaletteUser: data["defaultColorPaletteUser"].ToObject <string>());


            if (insertResult == Domain.ViewModel.CreateDatasetResultCode.Ok)
            {
                handler.UpdateDatasetStatus(data["name"].ToObject <string>(),
                                            DatasetStatus.Generated,
                                            RouteConfig.CurrentUser.Username);

                return(new HttpResponseMessage()
                {
                    StatusCode = System.Net.HttpStatusCode.OK,
                    Content = new StringContent(MessageBoxBuilder.Create(TextDictionary.OverlayMFSuccesTitle,
                                                                         TextDictionary.OverlayMFSuccesText,
                                                                         true))
                });
            }

            //Log a warning message
            Core.CoreContainers.LogsRepository.LogWarning($"Failed to insert geoserver layer ( ({ insertResult.ToString()} ) with data provided: {data}", Core.Database.Logs.LogTrigger.Controllers);

            return(new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content = new StringContent(MessageBoxBuilder.Create(
                                                insertResult == Domain.ViewModel.CreateDatasetResultCode.GeoserverError ?
                                                TextDictionary.OverlayCDGeoserverFailTitle :
                                                TextDictionary.OverlayCDFailTitle,
                                                insertResult == Domain.ViewModel.CreateDatasetResultCode.GeoserverError ?
                                                string.Format(TextDictionary.OverlayCDGeoserverFailText, data["name"].ToObject <string>()) :
                                                TextDictionary.OverlayCDFailText))
            });
        }