Exemple #1
0
        public async Task <CoordinateSystemSettings> Post([FromBody] CoordinateSystemFile request)
        {
            request.Validate();

            return(await RequestExecutorContainerFactory.Build <CoordinateSystemExecutorPost>(logger,
                                                                                              configStore : configStore, trexCompactionDataProxy : trexCompactionDataProxy, customHeaders : CustomHeaders).ProcessAsync(request) as CoordinateSystemSettings);
        }
Exemple #2
0
        public CoordinateSystemSettingsResult DummyCoordsystemPost([FromBody] CoordinateSystemFile request)
        {
            var cs = CoordinateSystemSettingsResult.CreateCoordinateSystemSettings
                     (
                csName: "Mock generated by DummyCoordsystemPost",
                csGroup: "Projection from Data Collector",
                csib: new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 },
                datumName: "Datum Grid",
                siteCalibration: false,
                geoidFileName: "NZ2009.GGF",
                geoidName: "New Zealand Geoid 2009",
                isDatumGrid: true,
                latitudeDatumGridFileName: "NZNATlat.DGF",
                longitudeDatumGridFileName: "NZNATlon.DGF",
                heightDatumGridFileName: null,
                shiftGridName: null,
                snakeGridName: null,
                verticalDatumName: null,
                unsupportedProjection: false
                     );

            Logger.LogInformation("DummyCoordsystemPost: CoordinateSystemFile {0}. CoordinateSystemSettings {1}",
                                  JsonConvert.SerializeObject(request), JsonConvert.SerializeObject(cs));
            return(cs);
        }
Exemple #3
0
        public void CS_CoordinateSystemControllerPostFailed()
        {
            byte[] csFileContent = { 0, 1, 2, 3, 4, 5, 6, 7 };

            var request = new CoordinateSystemFile(PD_MODEL_ID, csFileContent, "dummy.dc");

            // Create the mock PDSClient with unsuccessful result...
            var mockRaptorClient = new Mock <IASNodeClient>();
            var mockLogger       = new Mock <ILoggerFactory>();
            var mockConfigStore  = new Mock <IConfigurationStore>();

            var raptorResult = TASNodeErrorStatus.asneCouldNotConvertCSDFile;

            TCoordinateSystemSettings csSettings;

            mockRaptorClient.Setup(prj => prj.PassSelectedCoordinateSystemFile(
                                       It.IsAny <MemoryStream>(),
                                       request.CSFileName,
                                       request.ProjectId ?? VelociraptorConstants.NO_PROJECT_ID, out csSettings)).Returns(raptorResult);

            // Create an executor...
            var executor = RequestExecutorContainerFactory.Build <CoordinateSystemExecutorPost>(mockLogger.Object, mockRaptorClient.Object, configStore: mockConfigStore.Object);

            Assert.ThrowsExceptionAsync <ServiceException>(async() => await executor.ProcessAsync(request));
        }
Exemple #4
0
        public async Task CS_CoordinateSystemControllerPostSuccessful()
        {
            byte[] csFileContent = { 0, 1, 2, 3, 4, 5, 6, 7 };

            var request = new CoordinateSystemFile(PD_MODEL_ID, csFileContent, "dummy.dc");

            // Create the mock PDSClient with successful result...
            var mockRaptorClient = new Mock <IASNodeClient>();
            var mockLogger       = new Mock <ILoggerFactory>();
            var mockConfigStore  = new Mock <IConfigurationStore>();

            var raptorResult = TASNodeErrorStatus.asneOK;

            TCoordinateSystemSettings csSettings;

            mockRaptorClient.Setup(prj => prj.PassSelectedCoordinateSystemFile(
                                       new MemoryStream(request.CSFileContent),
                                       request.CSFileName,
                                       request.ProjectId ?? VelociraptorConstants.NO_PROJECT_ID, out csSettings)).Returns(raptorResult);

            // Create an executor...
            var executor = RequestExecutorContainerFactory.Build <CoordinateSystemExecutorPost>(mockLogger.Object, mockRaptorClient.Object, configStore: mockConfigStore.Object);

            var result = await executor.ProcessAsync(request);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Message == ContractExecutionResult.DefaultMessage, result.Message);
        }
Exemple #5
0
        /// <summary>
        /// Validates and posts to TRex, the CoordinateSystem for the project.
        ///  COORDSYSPOST_API_URL HttpPost "api/v1/coordsystem"
        /// </summary>
        public async Task <CoordinateSystemSettingsResult> CoordinateSystemPost(Guid projectUid, byte[] coordinateSystemFileContent, string coordinateSystemFileName, IHeaderDictionary customHeaders = null)
        {
            log.LogDebug($"{nameof(CoordinateSystemPost)} coordinateSystemFileName: {coordinateSystemFileName}");
            var payLoadToSend = CoordinateSystemFile.CreateCoordinateSystemFile(projectUid, coordinateSystemFileContent, coordinateSystemFileName);

            return(await CoordSystemPost(JsonConvert.SerializeObject(payLoadToSend), customHeaders, "/coordsystem"));
        }
Exemple #6
0
        public Task <ContractExecutionResult> PostCoordinateSystem([FromBody] CoordinateSystemFile request)
        {
            Log.LogInformation($"{nameof(PostCoordinateSystem)}: {Request.QueryString}");

            request.Validate();

            return(WithServiceExceptionTryExecuteAsync(() =>
                                                       RequestExecutorContainer
                                                       .Build <CoordinateSystemPostExecutor>(ConfigStore, LoggerFactory, ServiceExceptionHandler)
                                                       .ProcessAsync(request)));
        }
Exemple #7
0
        public async Task <JsonResult> PostCoordinateSystem([FromBody] CoordinateSystemFile request)
        {
            string resultToReturn = null;

            var dcFileContentString = System.Text.Encoding.UTF8.GetString(request.CSFileContent, 0, request.CSFileContent.Length);
            var coreXWrapper        = DIContext.Obtain <ICoreXWrapper>();

            var csd = coreXWrapper.GetCSDFromDCFileContent(dcFileContentString);

            if (csd == null || csd.ZoneInfo == null || csd.DatumInfo == null)
            {
                resultToReturn = $"<b>Failed to convert DC File {request.CSFileName} content to Coordinate System definition data.</b>";
            }
            else
            {
                var sw = new Stopwatch();
                sw.Start();

                var projectUid = request.ProjectUid ?? Guid.Empty;
                var addCoordinateSystemRequest = new AddCoordinateSystemRequest();

                var csib = coreXWrapper.GetCSIBFromDCFileContent(dcFileContentString);

                var addCoordSystemResponse = await addCoordinateSystemRequest.ExecuteAsync(new AddCoordinateSystemArgument()
                {
                    ProjectID = projectUid,
                    CSIB      = csib
                });

                if (addCoordSystemResponse?.Succeeded ?? false)
                {
                    resultToReturn  = $"<b>Coordinate System Settings (in {sw.Elapsed}) :</b><br/>";
                    resultToReturn += "<b>================================================</b><br/>";
                    resultToReturn += ConvertCSResult(request.CSFileName, csd);
                }
            }

            return(new JsonResult(resultToReturn));
        }
Exemple #8
0
        public void CanCreateCoordinateSystemFileTest()
        {
            var    validator = new DataAnnotationsValidator();
            string fileName  = "test.dc";

            byte[] fileContent = { 0, 1, 2, 3, 4, 5, 6, 7 };

            // Test the CreateCoordinateSystemFile() method with valid parameters...
            CoordinateSystemFile coordSystemFile = new CoordinateSystemFile(1, fileContent, "test.dc");

            Assert.IsTrue(validator.TryValidate(coordSystemFile, out ICollection <ValidationResult> results));

            // Test the CreateCoordinateSystemFile() method with an invalid projectID...
            coordSystemFile = new CoordinateSystemFile(-1, fileContent, fileName);
            Assert.IsFalse(validator.TryValidate(coordSystemFile, out results));

            // Test the CreateCoordinateSystemFile() method with a file name length exceeds 256 characters...
            string prefix = "overlimit";

            //int maxCount = (int)(CoordinateSystemFile.MAX_FILE_NAME_LENGTH / prefix.Length);

            for (int i = 1; prefix.Length <= CoordinateSystemFile.MAX_FILE_NAME_LENGTH; i++)
            {
                prefix += prefix;
            }

            coordSystemFile = new CoordinateSystemFile(1, fileContent, prefix + fileName);
            Assert.IsFalse(validator.TryValidate(coordSystemFile, out results));

            // Test the CreateCoordinateSystemFile() method with no file name provided...
            coordSystemFile = new CoordinateSystemFile(1, fileContent, string.Empty);
            Assert.IsFalse(validator.TryValidate(coordSystemFile, out results));

            // Test the CreateCoordinateSystemFile() method with no content provided...
            coordSystemFile = new CoordinateSystemFile(1, null, fileName);
            Assert.IsFalse(validator.TryValidate(coordSystemFile, out results));
        }