mirror of
https://github.com/farcasclaudiu/MartianRobots.git
synced 2026-06-28 23:01:20 +03:00
Add project files.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using MartianRobots.Web.Server.Data;
|
||||
using MartianRobots.Web.Shared;
|
||||
using MartianRobotsSolver;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace MartianRobots.Web.Server.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class MartianRobotsController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<MartianRobotsController> logger;
|
||||
private readonly IRobotSolutionStorage storage;
|
||||
|
||||
public MartianRobotsController(ILogger<MartianRobotsController> logger, IRobotSolutionStorage storage)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Solves Martian Robots
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <example>"5 3\n1 1 E\nRFRFRFRF\n3 2 N\nFRRFLLFFRRFLL\n0 3 W\nLLFFFRFLFL"</example>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Solve")]
|
||||
[Description("Solves Martian Robots")]
|
||||
public IActionResult Solve([FromBody] string input)
|
||||
{
|
||||
var result = new MarsSolver().Process(input);
|
||||
var model = new RobotSolutionModel {
|
||||
Input = result.Input,
|
||||
Output = result.Output,
|
||||
RobotLosts = result.Robots.Count(r=>r.IsLost)
|
||||
};
|
||||
storage.Add(model);
|
||||
return Ok(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the list of solutions
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet()]
|
||||
[Description("Get the list of solutions")]
|
||||
public IActionResult GetList()
|
||||
{
|
||||
return Ok(storage.List());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Number of all lost robots
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("LostRobots")]
|
||||
[Description("Number of all lost robots")]
|
||||
public IActionResult LostRobots()
|
||||
{
|
||||
return Ok(storage.List().Sum(r=>r.RobotLosts));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using MartianRobots.Web.Shared;
|
||||
using MartianRobotsSolver;
|
||||
|
||||
namespace MartianRobots.Web.Server.Data
|
||||
{
|
||||
public interface IRobotSolutionStorage
|
||||
{
|
||||
void Add(RobotSolutionModel solution);
|
||||
List<RobotSolutionModel> List();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using MartianRobots.Web.Shared;
|
||||
|
||||
namespace MartianRobots.Web.Server.Data
|
||||
{
|
||||
public class RobotSolutionStorage : IRobotSolutionStorage
|
||||
{
|
||||
private List<RobotSolutionModel> solutions = new List<RobotSolutionModel>
|
||||
{
|
||||
new RobotSolutionModel{ Input = "5 3\n1 1 E\nRFRFRFRF\n3 2 N\nFRRFLLFFRRFLL\n0 3 W\nLLFFFRFLFL" }
|
||||
};
|
||||
|
||||
public void Add(RobotSolutionModel solution)
|
||||
{
|
||||
solutions.Insert(0,solution);
|
||||
}
|
||||
|
||||
public List<RobotSolutionModel> List()
|
||||
{
|
||||
return solutions;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["MartianRobots.Web/Server/MartianRobots.Web.Server.csproj", "MartianRobots.Web/Server/"]
|
||||
COPY ["MartianRobotsSolver/MartianRobotsSolver.csproj", "MartianRobotsSolver/"]
|
||||
COPY ["MartianRobots.Web/Shared/MartianRobots.Web.Shared.csproj", "MartianRobots.Web/Shared/"]
|
||||
COPY ["MartianRobots.Web/Client/MartianRobots.Web.Client.csproj", "MartianRobots.Web/Client/"]
|
||||
RUN dotnet restore "MartianRobots.Web/Server/MartianRobots.Web.Server.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/MartianRobots.Web/Server"
|
||||
RUN dotnet build "MartianRobots.Web.Server.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "MartianRobots.Web.Server.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "MartianRobots.Web.Server.dll"]
|
||||
@@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<DockerfileContext>..\..</DockerfileContext>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.8" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MartianRobotsSolver\MartianRobotsSolver.csproj" />
|
||||
<ProjectReference Include="..\Client\MartianRobots.Web.Client.csproj" />
|
||||
<ProjectReference Include="..\Shared\MartianRobots.Web.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,42 @@
|
||||
@page
|
||||
@model MartianRobots.Web.Server.Pages.ErrorModel
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||
<title>Error</title>
|
||||
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
|
||||
<link href="~/css/app.css" rel="stylesheet" asp-append-version="true" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="main">
|
||||
<div class="content px-4">
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,27 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace MartianRobots.Web.Server.Pages
|
||||
{
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class ErrorModel : PageModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
private readonly ILogger<ErrorModel> _logger;
|
||||
|
||||
public ErrorModel(ILogger<ErrorModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using MartianRobots.Web.Server.Data;
|
||||
using Microsoft.AspNetCore.ResponseCompression;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Reflection;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddRazorPages();
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(options => {
|
||||
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
|
||||
});
|
||||
//storage
|
||||
builder.Services.AddSingleton<IRobotSolutionStorage, RobotSolutionStorage>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
//if (app.Environment.IsDevelopment())
|
||||
//{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseWebAssemblyDebugging();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// app.UseExceptionHandler("/Error");
|
||||
//}
|
||||
|
||||
app.UseBlazorFrameworkFiles();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
|
||||
app.MapRazorPages();
|
||||
app.MapControllers();
|
||||
app.MapFallbackToFile("index.html");
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"profiles": {
|
||||
"MartianRobots.Web.Server": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
|
||||
"applicationUrl": "http://localhost:5003"
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
|
||||
},
|
||||
"Docker": {
|
||||
"commandName": "Docker",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
|
||||
"publishAllPorts": true
|
||||
}
|
||||
},
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:1736",
|
||||
"sslPort": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user