Inheritance: ITileResult
Beispiel #1
0
            public void Should_return_empty_object_When_width_height_are_valid()
            {
                var result = TileResult.EmptyTile(45, 67);

                Assert.IsInstanceOfType(result, typeof(TileResult));
                Assert.AreEqual(ContractExecutionResult.DefaultMessage, result.Message);
                Assert.IsNotNull(result.TileData);
            }
Beispiel #2
0
        private void Dismiss(TileResult result)
        {
            if (_isDismissing)
            {
                return;
            }

            _isDismissing = true;
            _result       = result;

            if (_fadeOutState != null)
            {
                VisualStateManager.GoToState(this, "Faded", true);
            }
            else
            {
                Close(result);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the requested CA data tile from Raptor.
        /// </summary>
        /// <param name="request">HTTP request.</param>
        /// <returns>An HTTP response containing an error code is there is a failure, or a PNG image if the request suceeds.
        /// If the size of a pixel in the rendered tile coveres more than 10.88 meters in width or height, then the pixel will be rendered
        /// in a 'representational style' where black (currently, but there is a work item to allow this to be configurable) is used
        /// to indicate the presense of data. Representational style rendering performs no filtering what so ever on the data.10.88 meters is 32
        /// (number of cells across a subgrid) * 0.34 (default width in meters of a single cell)</returns>
        private async Task <FileResult> GetCCADataTile(TileRequest request)
        {
            var tileResult = await RequestExecutorContainerFactory.Build <TilesExecutor>(logger,
#if RAPTOR
                                                                                         raptorClient,
#endif
                                                                                         configStore : ConfigStore, trexCompactionDataProxy : TRexCompactionDataProxy, customHeaders : CustomHeaders,
                                                                                         userId : UserId, fileImportProxy : FileImportProxy)
                             .ProcessAsync(request) as TileResult;

            if (tileResult?.TileData == null)
            {
                tileResult = TileResult.EmptyTile(WebMercatorProjection.TILE_SIZE, WebMercatorProjection.TILE_SIZE);
            }

            Response.Headers.Add("X-Warning", tileResult.TileOutsideProjectExtents.ToString());

            return(new FileStreamResult(new MemoryStream(tileResult.TileData), ContentTypeConstants.ImagePng));
        }
Beispiel #4
0
        public async Task <FileResult> GetTile([FromBody] TRexTileRequest request)
        {
            Log.LogInformation($"{nameof(GetTile)}: {JsonConvert.SerializeObject(request)}");

            request.Validate();
            ValidateFilterMachines(nameof(GetTile), request.ProjectUid, request.Filter1);
            ValidateFilterMachines(nameof(GetTile), request.ProjectUid, request.Filter2);

            var tileResult = await WithServiceExceptionTryExecuteAsync(() =>
                                                                       RequestExecutorContainer
                                                                       .Build <TileExecutor>(ConfigStore, LoggerFactory, ServiceExceptionHandler)
                                                                       .ProcessAsync(request)) as TileResult;

            if (tileResult?.TileData == null)
            {
                tileResult = TileResult.EmptyTile(WebMercatorProjection.TILE_SIZE, WebMercatorProjection.TILE_SIZE);
            }

            return(new FileStreamResult(new MemoryStream(tileResult.TileData), ContentTypeConstants.ImagePng));
        }
Beispiel #5
0
        private void Close(TileResult result)
        {
            // Remove the popup.
            if (_popup != null)
            {
                _popup.IsOpen = false;
                _popup        = null;
            }

            // Bring the application bar if necessary.
            if (_hasApplicationBar)
            {
                _hasApplicationBar = false;

                // Application bar can be nulled during the Dismissed event
                // so a null check needs to be performed here.
                if (_page.ApplicationBar != null)
                {
                    _page.ApplicationBar.IsVisible = true;
                }
            }

            // Dettach event handlers.
            if (_page != null)
            {
                _page.BackKeyPress -= OnBackKeyPress;
                _page = null;
            }

            if (_frame != null)
            {
                _frame.Navigating -= OnNavigating;
                _frame             = null;
            }

            _tcs.SetResult(result);
        }
Beispiel #6
0
 public void Should_throw_When_width_height_are_invalid(int width, int height)
 {
     Assert.ThrowsException <ArgumentException>(() => TileResult.EmptyTile(width, height));
 }
Beispiel #7
0
        /// <summary>
        /// Gets the requested tile from Raptor
        /// </summary>
        /// <param name="projectSettings">Project settings to use for Raptor</param>
        /// <param name="projectSettingsColors"></param>
        /// <param name="filter">Filter to use for Raptor</param>
        /// <param name="projectId">Legacy project ID</param>
        /// <param name="projectUid">Unique project identifier</param>
        /// <param name="mode">Display mode; type of data requested</param>
        /// <param name="width">Width of the tile</param>
        /// <param name="height">Height of the tile in pixels</param>
        /// <param name="bbox">Bounding box in radians</param>
        /// <param name="cutFillDesign">Design descriptor for cut-fill</param>
        /// <param name="baseFilter">Base filter for  summary volumes</param>
        /// <param name="topFilter">Top filter for  summary volumes</param>
        /// <param name="volumeDesign">Design descriptor for summary volumes design</param>
        /// <param name="volumeCalcType">Type of summary volumes calculation</param>
        /// <param name="customHeaders">Custom request headers</param>
        /// <returns>Tile result</returns>
        public async Task <TileResult> GetProductionDataTile(CompactionProjectSettings projectSettings, CompactionProjectSettingsColors projectSettingsColors, FilterResult filter, long projectId, Guid projectUid, DisplayMode mode, ushort width, ushort height, BoundingBox2DLatLon bbox, DesignDescriptor cutFillDesign, FilterResult baseFilter, FilterResult topFilter, DesignDescriptor volumeDesign, VolumeCalcType?volumeCalcType, IHeaderDictionary customHeaders, string userId, bool explicitFilters = false)
        {
            var getTile = true;
            ElevationStatisticsResult elevationExtents = null;
            TileRequest tileRequest = null;

            try
            {
                elevationExtents = await GetElevationExtents(projectSettings, filter, projectId, projectUid, mode, customHeaders, userId);
            }
            catch (ServiceException se)
            {
                getTile = mode != DisplayMode.Height;
                if (log.IsTraceEnabled())
                {
                    log.LogTrace(
                        $"Failed to get elevation extents for height request with error: {se.GetResult.Code}:{se.GetResult.Message} a transparent tile will be generated");
                }
            }

            if (getTile)
            {
                tileRequest = requestFactory.Create <TileRequestHelper>(r => r
                                                                        .ProjectUid(projectUid)
                                                                        .ProjectId(projectId)
                                                                        .Headers(customHeaders)
                                                                        .ProjectSettings(projectSettings)
                                                                        .ProjectSettingsColors(projectSettingsColors)
                                                                        .Filter(filter)
                                                                        .DesignDescriptor(cutFillDesign))
                              .SetVolumeCalcType(volumeCalcType)
                              .SetVolumeDesign(volumeDesign)
                              .SetBaseFilter(baseFilter)
                              .SetTopFilter(topFilter)
                              .CreateTileRequest(mode, width, height, bbox, elevationExtents, explicitFilters);

                //TileRequest is both v1 and v2 model so cannot change its validation directly.
                //However for v2 we want to return a transparent empty tile for cut-fill if no design specified.
                //So catch the validation exception for this case.
                try
                {
                    tileRequest.Validate();
                }
                catch (ServiceException se)
                {
                    if (tileRequest.Mode == DisplayMode.CutFill &&
                        se.Code == HttpStatusCode.BadRequest &&
                        se.GetResult.Code == ContractExecutionStatesEnum.ValidationError)
                    {
                        if (
                            se is MissingDesignDescriptorException ||
                            se is TwoFiltersRequiredException ||
                            se is SingleFilterRequiredException)
                        {
                            getTile = false;
                        }
                    }
                    //Rethrow any other exception
                    if (getTile)
                    {
                        throw;
                    }
                }
            }

            TileResult tileResult = null;

            if (getTile)
            {
                try
                {
                    tileResult = await RequestExecutorContainerFactory
                                 .Build <CompactionTileExecutor>(logger,
#if RAPTOR
                                                                 raptorClient,
#endif
                                                                 configStore : ConfigStore, trexCompactionDataProxy : TRexCompactionDataProxy, customHeaders : customHeaders,
                                                                 userId : userId, fileImportProxy : FileImportProxy)
                                 .ProcessAsync(tileRequest) as TileResult;
                }
                catch (Exception ex)
                {
                    log.LogWarning($"Exception: {ex.Message} {ex.StackTrace}");
                }
            }

            return(tileResult?.TileData != null
        ? tileResult
        : TileResult.EmptyTile(WebMercatorProjection.TILE_SIZE, WebMercatorProjection.TILE_SIZE));
        }
Beispiel #8
0
    public List <TileResult> GetPath(Tile start, Tile end)
    {
        if (start == end)
        {
            return(new List <TileResult>());
        }

        var visitedTiles = new Dictionary <Tile, int>();

        visitedTiles.Add(start, 0);

        var queue = new Queue <TileResult>();

        queue.Enqueue(new TileResult(start, 0));

        // Explore map recursively and track how far the tiles are from the start.
        while (queue.Count != 0)
        {
            var current = queue.Dequeue();

            for (int i = 0; i < GridHelper.AllDirections.Count(); i++)
            {
                var candidateTile = GetTileInDirection(current.Tile, GridHelper.AllDirections.ToArray()[i]);

                if (candidateTile != null && !candidateTile.Blocked)
                {
                    var tileResult = new TileResult(candidateTile, current.Distance + 1);

                    if (visitedTiles.ContainsKey(candidateTile))
                    {
                        if (visitedTiles[candidateTile] > tileResult.Distance)
                        {
                            visitedTiles[candidateTile] = tileResult.Distance;
                        }
                    }
                    else
                    {
                        visitedTiles.Add(tileResult.Tile, tileResult.Distance);

                        if (candidateTile == end)
                        {
                            break;
                        }

                        queue.Enqueue(tileResult);
                    }
                }
            }
        }

        if (!visitedTiles.ContainsKey(end))
        {
            return(new List <TileResult>());
        }

        // Group tiles by distance.
        var distancesToTilesMap = new Dictionary <int, List <Tile> >();

        foreach (var kvp in visitedTiles)
        {
            if (kvp.Value < visitedTiles[end])
            {
                if (!distancesToTilesMap.ContainsKey(kvp.Value))
                {
                    distancesToTilesMap.Add(kvp.Value, new List <Tile>());
                }

                distancesToTilesMap[kvp.Value].Add(kvp.Key);
            }
        }

        // Start from end tile and move towards the next closest tile.
        var path = new Stack <TileResult>();

        path.Push(new TileResult(end, distancesToTilesMap.Count));

        for (int i = distancesToTilesMap.Count - 1; i > 0; i--)
        {
            Tile closest      = null;
            var  lastDistance = -1f;

            foreach (var candidateTile in distancesToTilesMap[i])
            {
                var distance = Vector2.Distance(candidateTile.transform.GetGridPosition(), path.Peek().Tile.transform.GetGridPosition());

                if (distance < lastDistance || lastDistance == -1f)
                {
                    closest      = candidateTile;
                    lastDistance = distance;
                }
            }

            Assert.IsNotNull(closest, "Failed to find a closest tile. You done goofed, bro.");

            path.Push(new TileResult(closest, i));
        }

        return(path.ToList());
    }
Beispiel #9
0
        private void Dismiss(TileResult result)
        {
            if (_isDismissing)
            {
                return;
            }

            _isDismissing = true;
            _result = result;

            if (_fadeOutState != null)
            {
                VisualStateManager.GoToState(this, "Faded", true);
            }
            else
            {
                Close(result);
            }
        }
Beispiel #10
0
        private void Close(TileResult result)
        {
            // Remove the popup.
            if (_popup != null)
            {
                _popup.IsOpen = false;
                _popup = null;
            }

            // Bring the application bar if necessary.
            if (_hasApplicationBar)
            {
                _hasApplicationBar = false;

                // Application bar can be nulled during the Dismissed event
                // so a null check needs to be performed here.
                if (_page.ApplicationBar != null)
                {
                    _page.ApplicationBar.IsVisible = true;
                }
            }

            // Dettach event handlers.
            if (_page != null)
            {
                _page.BackKeyPress -= OnBackKeyPress;
                _page = null;
            }

            if (_frame != null)
            {
                _frame.Navigating -= OnNavigating;
                _frame = null;
            }

            _tcs.SetResult(result);
        }