From 4ec647cae21f051685ba74ec16b2bf426d8334d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Qui=C3=B1ones?= Date: Sun, 3 Jul 2022 15:07:48 +0200 Subject: [PATCH] Modified webapp launch --- .../Commands/DebugStartCommand.cs | 9 ++--- .../Models/VisualStudio/ProjectProperties.cs | 30 +++++++++++++++-- Test/Blinkie/Blinky.sln | 10 ++++-- .../Controllers/WeatherForecastController.cs | 33 +++++++++++++++++++ Test/Blinkie/WebApi/Program.cs | 25 ++++++++++++++ .../WebApi/Properties/launchSettings.json | 15 +++++++++ Test/Blinkie/WebApi/WeatherForecast.cs | 13 ++++++++ Test/Blinkie/WebApi/WebApi.csproj | 15 +++++++++ .../WebApi/appsettings.Development.json | 8 +++++ Test/Blinkie/WebApi/appsettings.json | 9 +++++ .../WebApp/Properties/launchSettings.json | 8 ----- Test/Blinkie/WebApp/WebApp.csproj | 2 ++ 12 files changed, 160 insertions(+), 17 deletions(-) create mode 100644 Test/Blinkie/WebApi/Controllers/WeatherForecastController.cs create mode 100644 Test/Blinkie/WebApi/Program.cs create mode 100644 Test/Blinkie/WebApi/Properties/launchSettings.json create mode 100644 Test/Blinkie/WebApi/WeatherForecast.cs create mode 100644 Test/Blinkie/WebApi/WebApi.csproj create mode 100644 Test/Blinkie/WebApi/appsettings.Development.json create mode 100644 Test/Blinkie/WebApi/appsettings.json diff --git a/RaspberryDebugger/Commands/DebugStartCommand.cs b/RaspberryDebugger/Commands/DebugStartCommand.cs index a2e1c26..6ac0ef0 100644 --- a/RaspberryDebugger/Commands/DebugStartCommand.cs +++ b/RaspberryDebugger/Commands/DebugStartCommand.cs @@ -163,7 +163,7 @@ private async void Execute(object sender, EventArgs e) if (!projectProperties.IsAspNet || !projectProperties.AspLaunchBrowser) return; - var baseUri = $"http://{connection.Name}.local"; + var baseUri = $"http://{connection.Name}"; var launchReady = false; await NeonHelper.WaitForAsync( @@ -180,7 +180,7 @@ await NeonHelper.WaitForAsync( { var appListeningScript = $@" - if lsof -i -P -n | grep --quiet 'TCP 127.0.0.1:{projectProperties.AspPort}' ; then + if lsof -i -P -n | grep -q 'TCP 127.0.0.1:{projectProperties.AspPort}\|TCP 0.0.0.0:{projectProperties.AspPort}\|TCP \*:{projectProperties.AspPort}' ; then exit 0 else exit 1 @@ -212,7 +212,7 @@ exit 1 if (launchReady) { - NeonHelper.OpenBrowser($"{baseUri}{projectProperties.AspRelativeBrowserUri}"); + NeonHelper.OpenBrowser($"{baseUri}:{projectProperties.AspPort}/{projectProperties.AspRelativeBrowserUri}"); } } } @@ -277,7 +277,7 @@ private async Task CreateLaunchSettingsAsync(ConnectionInfo connection if (projectProperties?.IsAspNet == true) { - environmentVariables["ASPNETCORE_URLS"] = $"http://127.0.0.1:{projectProperties.AspPort}"; + environmentVariables["ASPNETCORE_URLS"] = $"http://0.0.0.0:{projectProperties.AspPort}"; } // Construct the debug launch JSON file. @@ -288,6 +288,7 @@ private async Task CreateLaunchSettingsAsync(ConnectionInfo connection // sees from Visual Studio for debugging purposes. The log file // is persisted to the program folder on the Raspberry. + engineLogging = $"--engineLogging={debugFolder}/__vsdbg-log.txt"; #endif var settings = diff --git a/RaspberryDebugger/Models/VisualStudio/ProjectProperties.cs b/RaspberryDebugger/Models/VisualStudio/ProjectProperties.cs index 8106bdc..453df7a 100644 --- a/RaspberryDebugger/Models/VisualStudio/ProjectProperties.cs +++ b/RaspberryDebugger/Models/VisualStudio/ProjectProperties.cs @@ -173,7 +173,8 @@ public static ProjectProperties CopyFrom(Solution solution, EnvDTE.Project proje } // Extract additional settings for ASPNET projects. - if (settings.Property("iisSettings") == null) continue; + var jProperty = profileObject.Property("applicationUrl"); + if (jProperty == null) continue; isAspNet = true; @@ -181,9 +182,8 @@ public static ProjectProperties CopyFrom(Solution solution, EnvDTE.Project proje // issues parsing the application URL. const int fallbackPort = 5000; - var jProperty = profileObject.Property("applicationUrl"); - if (jProperty != null && jProperty.Value.Type == JTokenType.String) + if (jProperty.Value.Type == JTokenType.String) { try { @@ -212,6 +212,30 @@ public static ProjectProperties CopyFrom(Solution solution, EnvDTE.Project proje { aspLaunchBrowser = (bool)jProperty.Value; } + + jProperty = profileObject.Property("launchUrl"); + + if (jProperty == null || + jProperty.Value.Type != JTokenType.String) + continue; + + var launchUri = (string)jProperty.Value; + + if (string.IsNullOrEmpty(launchUri)) continue; + + try + { + var uri = new Uri(launchUri, UriKind.RelativeOrAbsolute); + + aspRelativeBrowserUri = uri.IsAbsoluteUri + ? uri.PathAndQuery + : launchUri; + } + catch + { + // We'll fall back to "/" for any URI parsing errors. + aspRelativeBrowserUri = "/"; + } } else if (profile.Name == "IIS Express") { diff --git a/Test/Blinkie/Blinky.sln b/Test/Blinkie/Blinky.sln index e737e4a..32a007e 100644 --- a/Test/Blinkie/Blinky.sln +++ b/Test/Blinkie/Blinky.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30523.141 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32616.157 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blinkie", "Blinkie\Blinkie.csproj", "{B1E5A334-F139-496D-ACF7-1CCB6840DACA}" EndProject @@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blinkie31", "Blinkie31\Blin EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFolder", "SolutionFolder", "{F415615A-B38A-49E0-8296-D81F9B97E352}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi", "WebApi\WebApi.csproj", "{A3D15A5D-3BB4-4E93-BDFD-711BC97B1374}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,6 +51,10 @@ Global {6EEFF8C7-49AA-4A94-84DA-B7E9CAE34160}.Debug|Any CPU.Build.0 = Debug|Any CPU {6EEFF8C7-49AA-4A94-84DA-B7E9CAE34160}.Release|Any CPU.ActiveCfg = Release|Any CPU {6EEFF8C7-49AA-4A94-84DA-B7E9CAE34160}.Release|Any CPU.Build.0 = Release|Any CPU + {A3D15A5D-3BB4-4E93-BDFD-711BC97B1374}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3D15A5D-3BB4-4E93-BDFD-711BC97B1374}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3D15A5D-3BB4-4E93-BDFD-711BC97B1374}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3D15A5D-3BB4-4E93-BDFD-711BC97B1374}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Test/Blinkie/WebApi/Controllers/WeatherForecastController.cs b/Test/Blinkie/WebApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..8f2f77f --- /dev/null +++ b/Test/Blinkie/WebApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WebApi.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 = DateTime.Now.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} \ No newline at end of file diff --git a/Test/Blinkie/WebApi/Program.cs b/Test/Blinkie/WebApi/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/Test/Blinkie/WebApi/Program.cs @@ -0,0 +1,25 @@ +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.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Test/Blinkie/WebApi/Properties/launchSettings.json b/Test/Blinkie/WebApi/Properties/launchSettings.json new file mode 100644 index 0000000..ad5b0c7 --- /dev/null +++ b/Test/Blinkie/WebApi/Properties/launchSettings.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "WebApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5098", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Test/Blinkie/WebApi/WeatherForecast.cs b/Test/Blinkie/WebApi/WeatherForecast.cs new file mode 100644 index 0000000..528d970 --- /dev/null +++ b/Test/Blinkie/WebApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace WebApi +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} \ No newline at end of file diff --git a/Test/Blinkie/WebApi/WebApi.csproj b/Test/Blinkie/WebApi/WebApi.csproj new file mode 100644 index 0000000..116271a --- /dev/null +++ b/Test/Blinkie/WebApi/WebApi.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + enable + enable + linux-arm + AnyCPU + + + + + + + diff --git a/Test/Blinkie/WebApi/appsettings.Development.json b/Test/Blinkie/WebApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Test/Blinkie/WebApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Test/Blinkie/WebApi/appsettings.json b/Test/Blinkie/WebApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Test/Blinkie/WebApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Test/Blinkie/WebApp/Properties/launchSettings.json b/Test/Blinkie/WebApp/Properties/launchSettings.json index 0d323e4..266a7cd 100644 --- a/Test/Blinkie/WebApp/Properties/launchSettings.json +++ b/Test/Blinkie/WebApp/Properties/launchSettings.json @@ -8,14 +8,6 @@ } }, "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "http://localhost:5000/Privacy", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, "WebApp": { "commandName": "Project", "launchBrowser": true, diff --git a/Test/Blinkie/WebApp/WebApp.csproj b/Test/Blinkie/WebApp/WebApp.csproj index 84b1712..71dd3a0 100644 --- a/Test/Blinkie/WebApp/WebApp.csproj +++ b/Test/Blinkie/WebApp/WebApp.csproj @@ -2,5 +2,7 @@ net6.0 linux-arm + AnyCPU + True