示例#1
0
        public async Task SinglePatchRequest_Invalid_TRex_NoResult()
        {
            var projectId  = 999;
            var projectUid = Guid.NewGuid();
            var request    = new PatchesRequest("ec520SerialNumber",
                                                90, 180, new BoundingBox2DGrid(1, 200, 10, 210));
            var mockConfigStore = new Mock <IConfigurationStore>();

            mockConfigStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_PATCHES")).Returns(true);

            var filterResult = new FilterResult();

            filterResult.SetBoundary(new List <Point>()
            {
                new Point(request.BoundingBox.BottomleftY, request.BoundingBox.BottomLeftX),
                new Point(request.BoundingBox.BottomleftY, request.BoundingBox.TopRightX),
                new Point(request.BoundingBox.TopRightY, request.BoundingBox.TopRightX),
                new Point(request.BoundingBox.TopRightY, request.BoundingBox.BottomLeftX)
            });
            var patchRequest = new PatchRequest(
                projectId,
                projectUid,
                new Guid(),
                DisplayMode.Height,
                null,
                new LiftBuildSettings(),
                false,
                VolumesType.None,
                VelociraptorConstants.VOLUME_CHANGE_TOLERANCE,
                null, filterResult, null, FilterLayerMethod.AutoMapReset,
                0, 1000, true);

            patchRequest.Validate();

            var exception = new ServiceException(HttpStatusCode.InternalServerError,
                                                 new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError,
                                                                             $"SinglePatch request failed somehow. ProjectUid: {projectUid}"));

            var tRexProxy = new Mock <ITRexCompactionDataProxy>();

            tRexProxy.Setup(x => x.SendDataPostRequestWithStreamResponse(It.IsAny <PatchDataRequest>(), "/patches", It.IsAny <IHeaderDictionary>()))
            .Throws(exception);

            var executor = RequestExecutorContainerFactory
                           .Build <CompactionSinglePatchExecutor>(_logger, configStore: mockConfigStore.Object,
                                                                  trexCompactionDataProxy: tRexProxy.Object);
            var result = await Assert.ThrowsExceptionAsync <ServiceException>(async() => await executor.ProcessAsync(patchRequest));

            result.Code.Should().Be(HttpStatusCode.InternalServerError);
            result.GetResult.Code.Should().Be(ContractExecutionStatesEnum.InternalProcessingError);
            result.GetResult.Message.Should().Be(exception.GetResult.Message);
        }
示例#2
0
        protected FilterResult SetupCompactionFilter(Guid projectUid, BoundingBox2DGrid boundingBox)
        {
            var filterResult = new FilterResult();

            filterResult.SetBoundary(new List <Point>
            {
                new Point(boundingBox.BottomleftY, boundingBox.BottomLeftX),
                new Point(boundingBox.BottomleftY, boundingBox.TopRightX),
                new Point(boundingBox.TopRightY, boundingBox.TopRightX),
                new Point(boundingBox.TopRightY, boundingBox.BottomLeftX)
            });
            return(filterResult);
        }
示例#3
0
        public async Task PatchRequest_TRex_WithResult()
        {
            var projectId  = 999;
            var projectUid = Guid.NewGuid();
            var request    = new PatchesRequest("ec520SerialNumber",
                                                90, 180, new BoundingBox2DGrid(1, 200, 10, 210));
            var mockConfigStore = new Mock <IConfigurationStore>();

            mockConfigStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_PATCHES")).Returns(true);

            var filterResult = new FilterResult();

            filterResult.SetBoundary(new List <Point>
            {
                new Point(request.BoundingBox.BottomleftY, request.BoundingBox.BottomLeftX),
                new Point(request.BoundingBox.BottomleftY, request.BoundingBox.TopRightX),
                new Point(request.BoundingBox.TopRightY, request.BoundingBox.TopRightX),
                new Point(request.BoundingBox.TopRightY, request.BoundingBox.BottomLeftX)
            });


            var tRexProxy = new Mock <ITRexCompactionDataProxy>();

            var  subGridOriginX  = 150.45;
            var  subGridOriginY  = 1400.677;
            var  palette         = new List <ColorPalette>();
            uint paletteColor    = 44444;
            var  elevationOrigin = (float)100.450;
            var  nowTimeOrigin   = new DateTimeOffset(DateTime.UtcNow.AddDays(-5).AddMinutes(100));
            var  timeOrigin      = (uint)(nowTimeOrigin).ToUnixTimeSeconds();
            var  delta           = (uint)0;

            // elevation offsets are in mm
            var elevationOffsets = new ushort[cellSize * cellSize];
            var timeOffsets      = new uint[cellSize * cellSize];

            for (var c = delta; c < (cellSize * cellSize); c++)
            {
                elevationOffsets[c] = (ushort)(c + 6);
                timeOffsets[c]      = c + 3;
                if (((int)c % 10) == 0)
                {
                    palette.Add(new ColorPalette(paletteColor++, elevationOrigin + (elevationOffsets[c] / 1000.0)));
                }
            }

            var patchRequest = new PatchRequest(
                projectId,
                projectUid,
                new Guid(),
                DisplayMode.Height,
                palette,
                new LiftBuildSettings(),
                true,
                VolumesType.None,
                VelociraptorConstants.VOLUME_CHANGE_TOLERANCE,
                null, filterResult, null, FilterLayerMethod.AutoMapReset,
                0, 1000, false);

            patchRequest.Validate();

            var resultStream = WriteAsPerTRex(1, 1, subGridOriginX, subGridOriginY, elevationOrigin, timeOrigin, elevationOffsets, timeOffsets);

            tRexProxy.Setup(x => x.SendDataPostRequestWithStreamResponse(It.IsAny <PatchDataRequest>(), "/patches", It.IsAny <IHeaderDictionary>()))
            .Returns(Task.FromResult <Stream>(resultStream));

            var executor = RequestExecutorContainerFactory
                           .Build <PatchExecutor>(_logger, mockConfigStore.Object,
                                                  trexCompactionDataProxy: tRexProxy.Object);
            var result = await executor.ProcessAsync(patchRequest) as PatchResultRenderedColors;

            result.Should().NotBeNull();
            result.Subgrids.Should().NotBeNull();
            result.Subgrids.Length.Should().Be(1);

            var subGrid = (PatchSubgridResult)result.Subgrids[0];

            subGrid.CellOriginX.Should().Be((int)subGridOriginX);
            subGrid.CellOriginY.Should().Be((int)subGridOriginY);
            subGrid.ElevationOrigin.Should().Be(elevationOrigin);
            subGrid.Cells[0, 0].Elevation.Should().Be((float)(elevationOrigin + ((delta + 6.0) / 1000.0)));
            subGrid.Cells[0, 0].Color.Should().Be(0);
            subGrid.Cells[0, 1].Elevation.Should().Be((float)(elevationOrigin + ((delta + 7.0) / 1000.0)));
            subGrid.Cells[0, 1].Color.Should().Be(44444);
            subGrid.Cells[1, 0].Elevation.Should().Be((float)(elevationOrigin + ((delta + 32.0 + 6.0) / 1000.0)));
            subGrid.Cells[1, 0].Color.Should().Be(44447);
        }
示例#4
0
        public async Task SinglePatchRequest_TRex_WithResult()
        {
            var projectId  = 999;
            var projectUid = Guid.NewGuid();
            var request    = new PatchesRequest("ec520SerialNumber",
                                                90, 180, new BoundingBox2DGrid(1, 200, 10, 210));
            var mockConfigStore = new Mock <IConfigurationStore>();

            mockConfigStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_PATCHES")).Returns(true);

            var filterResult = new FilterResult();

            filterResult.SetBoundary(new List <Point>
            {
                new Point(request.BoundingBox.BottomleftY, request.BoundingBox.BottomLeftX),
                new Point(request.BoundingBox.BottomleftY, request.BoundingBox.TopRightX),
                new Point(request.BoundingBox.TopRightY, request.BoundingBox.TopRightX),
                new Point(request.BoundingBox.TopRightY, request.BoundingBox.BottomLeftX)
            });
            var patchRequest = new PatchRequest(
                projectId,
                projectUid,
                new Guid(),
                DisplayMode.Height,
                null,
                new LiftBuildSettings(),
                false,
                VolumesType.None,
                VelociraptorConstants.VOLUME_CHANGE_TOLERANCE,
                null, filterResult, null, FilterLayerMethod.AutoMapReset,
                0, 1000, true);

            patchRequest.Validate();

            var tRexProxy = new Mock <ITRexCompactionDataProxy>();

            var subgridOriginX  = 150.45;
            var subgridOriginY  = 1400.677;
            var elevationOrigin = (float)100.45;
            var nowTimeOrigin   = new DateTimeOffset(DateTime.UtcNow.AddDays(-5).AddMinutes(100));
            var timeOrigin      = (uint)(nowTimeOrigin).ToUnixTimeSeconds();
            var delta           = (uint)0;

            // elevation offsets are in mm
            var elevationOffsets = new ushort[cellSize * cellSize];
            var timeOffsets      = new uint[cellSize * cellSize];

            for (var c = delta; c < (cellSize * cellSize); c++)
            {
                elevationOffsets[c] = (ushort)(c + 6);
                timeOffsets[c]      = c + 3;
            }

            var resultStream = WriteAsPerTRex(1, 1, subgridOriginX, subgridOriginY, elevationOrigin, timeOrigin, elevationOffsets, timeOffsets);

            tRexProxy.Setup(x => x.SendDataPostRequestWithStreamResponse(It.IsAny <PatchDataRequest>(), "/patches", It.IsAny <IHeaderDictionary>()))
            .Returns(Task.FromResult <Stream>(resultStream));

            var executor = RequestExecutorContainerFactory
                           .Build <CompactionSinglePatchExecutor>(_logger, configStore: mockConfigStore.Object,
                                                                  trexCompactionDataProxy: tRexProxy.Object);
            var result = await executor.ProcessAsync(patchRequest) as PatchSubgridsRawResult;

            result.Should().NotBeNull();
            result.Subgrids.Should().NotBeNull();
            result.Subgrids.Length.Should().Be(1);
            result.Subgrids[0].ElevationOffsets.Length.Should().Be(cellSize * cellSize);
            result.Subgrids[0].ElevationOrigin.Should().Be(elevationOrigin);
            result.Subgrids[0].TimeOffsets.Length.Should().Be(cellSize * cellSize);
            result.Subgrids[0].TimeOrigin.Should().Be(timeOrigin);
            result.Subgrids[0].ElevationOffsets[0].Should().Be((ushort)(delta + 6 + 1)); // zero means no offset available
            result.Subgrids[0].TimeOffsets[0].Should().Be(delta + 3);

            var doubleArrayResult = (new CompactionSinglePatchResult()).UnpackSubgrid(cellSize, result.Subgrids[0]);

            doubleArrayResult[0, 0].easting.Should().Be(subgridOriginX + (cellSize / 2));
            doubleArrayResult[0, 0].northing.Should().Be(subgridOriginY + (cellSize / 2));
            doubleArrayResult[0, 0].elevation.Should().Be(Math.Round(elevationOrigin + (ushort)(delta + 6) / 1000.0, 5));
            var actualDateTime = nowTimeOrigin.AddSeconds(delta + 3).DateTime;

            doubleArrayResult[0, 0].dateTime.Should().Be(new DateTime(actualDateTime.Year, actualDateTime.Month, actualDateTime.Day, actualDateTime.Hour, actualDateTime.Minute, actualDateTime.Second));
        }