From 04d46cb953c60653df54aa9ab22d64582adcba7e Mon Sep 17 00:00:00 2001 From: eeoooue Date: Fri, 23 May 2025 12:32:22 +0100 Subject: [PATCH 1/8] created CubeProxy project --- .../Controllers/WeatherForecastController.cs | 33 ++++++++++++++++++ Solution/CubeProxy/CubeProxy.csproj | 13 +++++++ Solution/CubeProxy/CubeProxy.http | 6 ++++ Solution/CubeProxy/Program.cs | 34 +++++++++++++++++++ .../CubeProxy/Properties/launchSettings.json | 31 +++++++++++++++++ Solution/CubeProxy/WeatherForecast.cs | 13 +++++++ .../CubeProxy/appsettings.Development.json | 8 +++++ Solution/CubeProxy/appsettings.json | 9 +++++ 8 files changed, 147 insertions(+) create mode 100644 Solution/CubeProxy/Controllers/WeatherForecastController.cs create mode 100644 Solution/CubeProxy/CubeProxy.csproj create mode 100644 Solution/CubeProxy/CubeProxy.http create mode 100644 Solution/CubeProxy/Program.cs create mode 100644 Solution/CubeProxy/Properties/launchSettings.json create mode 100644 Solution/CubeProxy/WeatherForecast.cs create mode 100644 Solution/CubeProxy/appsettings.Development.json create mode 100644 Solution/CubeProxy/appsettings.json diff --git a/Solution/CubeProxy/Controllers/WeatherForecastController.cs b/Solution/CubeProxy/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..129b092 --- /dev/null +++ b/Solution/CubeProxy/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace CubeProxy.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/Solution/CubeProxy/CubeProxy.csproj b/Solution/CubeProxy/CubeProxy.csproj new file mode 100644 index 0000000..5419ef0 --- /dev/null +++ b/Solution/CubeProxy/CubeProxy.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Solution/CubeProxy/CubeProxy.http b/Solution/CubeProxy/CubeProxy.http new file mode 100644 index 0000000..a99eb0a --- /dev/null +++ b/Solution/CubeProxy/CubeProxy.http @@ -0,0 +1,6 @@ +@CubeProxy_HostAddress = http://localhost:5290 + +GET {{CubeProxy_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Solution/CubeProxy/Program.cs b/Solution/CubeProxy/Program.cs new file mode 100644 index 0000000..baff427 --- /dev/null +++ b/Solution/CubeProxy/Program.cs @@ -0,0 +1,34 @@ + +namespace CubeProxy +{ + public class Program + { + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + + builder.Services.AddControllers(); + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(); + + var app = builder.Build(); + + // Configure the HTTP request pipeline. + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(); + } + + app.UseAuthorization(); + + + app.MapControllers(); + + app.Run(); + } + } +} diff --git a/Solution/CubeProxy/Properties/launchSettings.json b/Solution/CubeProxy/Properties/launchSettings.json new file mode 100644 index 0000000..ecd0366 --- /dev/null +++ b/Solution/CubeProxy/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:57278", + "sslPort": 0 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5290", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Solution/CubeProxy/WeatherForecast.cs b/Solution/CubeProxy/WeatherForecast.cs new file mode 100644 index 0000000..7eaff5a --- /dev/null +++ b/Solution/CubeProxy/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace CubeProxy +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/Solution/CubeProxy/appsettings.Development.json b/Solution/CubeProxy/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Solution/CubeProxy/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Solution/CubeProxy/appsettings.json b/Solution/CubeProxy/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Solution/CubeProxy/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} From a664170484fc19cd62ca902e908951a84a22eed3 Mon Sep 17 00:00:00 2001 From: eeoooue Date: Fri, 23 May 2025 12:33:36 +0100 Subject: [PATCH 2/8] Update Solution.sln --- Solution/Solution.sln | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Solution/Solution.sln b/Solution/Solution.sln index ecb8e4d..cea53e2 100644 --- a/Solution/Solution.sln +++ b/Solution/Solution.sln @@ -29,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CubeVisualizer", "CubeVisua EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CubeStatePublisher", "CubeStatePublisher\CubeStatePublisher.csproj", "{7D02ECFC-C216-4E83-928A-08C7CBE652DA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CubeProxy", "CubeProxy\CubeProxy.csproj", "{BBC773F5-B0E2-4337-B942-24EDEF6807C7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -79,6 +81,10 @@ Global {7D02ECFC-C216-4E83-928A-08C7CBE652DA}.Debug|Any CPU.Build.0 = Debug|Any CPU {7D02ECFC-C216-4E83-928A-08C7CBE652DA}.Release|Any CPU.ActiveCfg = Release|Any CPU {7D02ECFC-C216-4E83-928A-08C7CBE652DA}.Release|Any CPU.Build.0 = Release|Any CPU + {BBC773F5-B0E2-4337-B942-24EDEF6807C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BBC773F5-B0E2-4337-B942-24EDEF6807C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BBC773F5-B0E2-4337-B942-24EDEF6807C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BBC773F5-B0E2-4337-B942-24EDEF6807C7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 8c71bf3a073eb83b33ed11c7db7ab2ff8e300e11 Mon Sep 17 00:00:00 2001 From: eeoooue Date: Fri, 23 May 2025 12:33:44 +0100 Subject: [PATCH 3/8] added port to NetworkingConfiguration --- Solution/LibCubeIntegration/NetworkingConfiguration.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Solution/LibCubeIntegration/NetworkingConfiguration.cs b/Solution/LibCubeIntegration/NetworkingConfiguration.cs index 366d695..41b9fe0 100644 --- a/Solution/LibCubeIntegration/NetworkingConfiguration.cs +++ b/Solution/LibCubeIntegration/NetworkingConfiguration.cs @@ -44,6 +44,8 @@ public static int GetPortForServer(string project) { case "DummyService": return 5000; + case "CubeProxy": + return 5290; case "CubeService": return 5295; case "CubeStatePublisher": From 26c7d740e8a0e6265b14f204fdb088f46d6e3178 Mon Sep 17 00:00:00 2001 From: eeoooue Date: Fri, 23 May 2025 12:47:24 +0100 Subject: [PATCH 4/8] scaffolded CubeController for CubeProxy project --- .../CubeProxy/Controllers/CubeController.cs | 107 ++++++++++++++++++ Solution/CubeProxy/CubeProxy.csproj | 5 + Solution/CubeProxy/WeatherForecast.cs | 13 --- 3 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 Solution/CubeProxy/Controllers/CubeController.cs delete mode 100644 Solution/CubeProxy/WeatherForecast.cs diff --git a/Solution/CubeProxy/Controllers/CubeController.cs b/Solution/CubeProxy/Controllers/CubeController.cs new file mode 100644 index 0000000..4f752c0 --- /dev/null +++ b/Solution/CubeProxy/Controllers/CubeController.cs @@ -0,0 +1,107 @@ +using LibCubeIntegration.Services; +using LibNetCube; +using Microsoft.AspNetCore.Mvc; + +namespace CubeProxy.Controllers +{ + [ApiController] + [Route("api/[controller]")] + + public class CubeController : Controller + { + readonly CubeServiceFacade _cubeService = new CubeServiceFacade("CubeService"); + + [HttpPost("[action]")] + public IActionResult Reset() + { + return Ok(); + } + + [HttpPost("[action]")] + public IActionResult ApplyShuffle([FromQuery] string? shuffle = null) + { + return Ok(); + } + + [HttpPost("[action]")] + public async Task PerformMove([FromQuery] string? move = null) + { + if (move is string) + { + try + { + //attempt to parse move as Enum + CubeMove parsedMove = MoveParser.ParseMove(move)!; + await _cubeService.PerformMoveAsync(move); + + return Ok(); + } + catch + { + //Not a valid move + return BadRequest(); + } + } + + return BadRequest(); + } + + [HttpGet] + [Route("")] //follows base route of api/[controller] + [Route("[action]")] + public async Task State() + { + CubeState? result = await _cubeService.GetStateAsync(); + + if (result is CubeState state) + { + Dictionary faces = CreateDictionaryOfFaces(state); + return Ok(faces); + } + + return NotFound(); + } + + + [HttpGet("[action]")] + public async Task Face([FromQuery] string? face = null) + { + CubeState? result = await _cubeService.GetStateAsync(); + + try + { + if (result is CubeState state) + { + Dictionary faces = CreateDictionaryOfFaces(state); + if (face is string) + { + return Ok(faces[face]); + } + } + else + { + return NotFound(); + } + + return BadRequest(); + } + catch + { + return BadRequest(); + } + } + + private Dictionary CreateDictionaryOfFaces(CubeState state) + { + Dictionary faces = new Dictionary(); + foreach (CubeFace face in CubeState.GetFaceNames()) + { + int[,] ints = state.ReadFace(face); + int[] formattedInts = ints.Cast().ToArray(); + faces.Add(face.ToString(), formattedInts); + } + + return faces; + } + } +} diff --git a/Solution/CubeProxy/CubeProxy.csproj b/Solution/CubeProxy/CubeProxy.csproj index 5419ef0..dac6d42 100644 --- a/Solution/CubeProxy/CubeProxy.csproj +++ b/Solution/CubeProxy/CubeProxy.csproj @@ -10,4 +10,9 @@ + + + + + diff --git a/Solution/CubeProxy/WeatherForecast.cs b/Solution/CubeProxy/WeatherForecast.cs deleted file mode 100644 index 7eaff5a..0000000 --- a/Solution/CubeProxy/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CubeProxy -{ - public class WeatherForecast - { - public DateOnly Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -} From 7505b7bfeb428538b77393214a8c82b31f4b0dde Mon Sep 17 00:00:00 2001 From: eeoooue Date: Fri, 23 May 2025 12:54:10 +0100 Subject: [PATCH 5/8] Delete WeatherForecastController.cs --- .../Controllers/WeatherForecastController.cs | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 Solution/CubeProxy/Controllers/WeatherForecastController.cs diff --git a/Solution/CubeProxy/Controllers/WeatherForecastController.cs b/Solution/CubeProxy/Controllers/WeatherForecastController.cs deleted file mode 100644 index 129b092..0000000 --- a/Solution/CubeProxy/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace CubeProxy.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} From a4026daa50f6fe7c8fe01f0cd0d4e5a49d76ecdb Mon Sep 17 00:00:00 2001 From: eeoooue Date: Fri, 23 May 2025 12:54:23 +0100 Subject: [PATCH 6/8] PublishCubeService now connects to CubeProxy --- Solution/CubeStatePublisher/PublishCubeService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Solution/CubeStatePublisher/PublishCubeService.cs b/Solution/CubeStatePublisher/PublishCubeService.cs index 4bf9df5..efaa8ca 100644 --- a/Solution/CubeStatePublisher/PublishCubeService.cs +++ b/Solution/CubeStatePublisher/PublishCubeService.cs @@ -20,7 +20,7 @@ public class PublishCubeService : BackgroundService public PublishCubeService(IHubContext hubContext) { _hubContext = hubContext; - _getCubeStrategy = new GetCubeViaApiStrategy("CubeService"); + _getCubeStrategy = new GetCubeViaApiStrategy("CubeProxy"); } protected override async Task ExecuteAsync(CancellationToken stoppingToken) From 46e374b73af67859a374429580d5144d32f3b7b2 Mon Sep 17 00:00:00 2001 From: eeoooue Date: Fri, 23 May 2025 12:54:32 +0100 Subject: [PATCH 7/8] CubeManipulator now connects to CubeProxy --- Solution/CubeManipulator/CubeManipulatorViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Solution/CubeManipulator/CubeManipulatorViewModel.cs b/Solution/CubeManipulator/CubeManipulatorViewModel.cs index 615ea7c..d4b01a8 100644 --- a/Solution/CubeManipulator/CubeManipulatorViewModel.cs +++ b/Solution/CubeManipulator/CubeManipulatorViewModel.cs @@ -5,7 +5,7 @@ namespace CubeManipulator public class CubeManipulatorViewModel { //full path MoveViaApi - LibCubeIntegration.PerformMoveStrategies.MoveViaApiStrategy moveStrategy = new MoveViaApiStrategy(); + LibCubeIntegration.PerformMoveStrategies.MoveViaApiStrategy moveStrategy = new MoveViaApiStrategy("CubeProxy"); private RelayCommand moveCommand; public RelayCommand MoveCommand //Get command result From 2e8d6c76b28a281663a2869115ba8b908fccfbbd Mon Sep 17 00:00:00 2001 From: eeoooue Date: Fri, 23 May 2025 12:55:48 +0100 Subject: [PATCH 8/8] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 78665a7..7fb2f01 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,9 @@ The puzzle is presented as a cube map in the same manner as in [Old Pochman](htt 1. Open ```Solution/Solution.sln``` in Visual Studio 2. Run **CubeService** to make the cube available via the API. -3. Run **CubeStatePublisher** to make the cube state available to frontends over SignalR. -4. Run front end application(s) of your choosing to view the cube and interact with it: +3. Run **CubeProxy** to make the CubeService API available to other components. +4. Run **CubeStatePublisher** to make the cube state available to frontends over SignalR. +5. Run front end application(s) of your choosing to view the cube and interact with it: - Try **CubeVisualizer** to view the cube in 3D - Try **FaceViewer** instances to view individual faces of the cube - Try **FaceViewerCLI** to view the cube within the command line and input moves