コード例 #1
0
        private async Task <Challenge> MapChallenge(Maze maze)
        {
            String solution         = null;
            String renderedSolution = null;

            if (maze.SysId == 1)
            {
                var mazeData = maze.Data.Base64Decode();
                solution = Solve(mazeData);

                var solutionImageId = await _imageLogic.GetImageByChecksum(solution);

                if (!solutionImageId.HasValue)
                {
                    byte[] renderingData = _renderingLogic.RenderMaze(mazeData, solution);
                    solutionImageId = await _imageLogic.StoreImage(renderingData, solution);
                }

                renderedSolution = $"http://{_mazeRetreatContext.HostUri}/api/rendering/{solutionImageId}";
            }

            var imageId = await _imageLogic.GetImageByChecksum(maze.Data);

            if (!imageId.HasValue)
            {
                var    mazeData      = maze.Data.Base64Decode();
                byte[] renderingData = _renderingLogic.RenderMaze(mazeData, null);
                imageId = await _imageLogic.StoreImage(renderingData, maze.Data);
            }

            return(new Challenge
            {
                Id = maze.Id,
                Description = maze.Description,
                Maze = maze.Data,
                Solution = solution,
                RenderedMaze = $"http://{_mazeRetreatContext.HostUri}/api/rendering/{imageId}",
                RenderedSolution = renderedSolution
            });
        }
コード例 #2
0
        private async Task <String> GetRenderedMaze(Maze maze, String solutionData = null)
        {
            if (maze != null)
            {
                if (solutionData != null)
                {
                    solutionData = $"{maze.Data}-{solutionData}";
                }
                var mazeData = maze.Data.Base64Decode();
                var imageId  = await _imageLogic.GetImageByChecksum(solutionData ?? maze.Data);

                if (!imageId.HasValue)
                {
                    byte[] renderingData = _renderingLogic.RenderMaze(mazeData, solutionData);
                    imageId = await _imageLogic.StoreImage(renderingData, solutionData ?? maze.Data);
                }

                return($"http://{_mazeRetreatContext.HostUri}/api/rendering/{imageId}");
            }

            return(null);
        }