Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support to aspire #592

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class LoggerExtensions
public static void Step<T>(this ILogger logger, string beforeMessage, string afterMessage, Func<T> func,
params object[] @params)
{
var lastRow = Console.CursorTop;
var lastRow = GetCursorTop();

if (@params is null || @params.Length == 0)
logger.Information(beforeMessage);
Expand All @@ -23,22 +23,22 @@ public static void Step<T>(this ILogger logger, string beforeMessage, string aft

var result = func();

var currentRow = Console.CursorTop;
Console.SetCursorPosition(0, lastRow);
var currentRow = GetCursorTop();
SetCursorPosition(0, lastRow);
if (@params is null || @params.Length == 0)
logger.Information($"{afterMessage} in {{elapsed}} secs", result,
Math.Round(Sw.ElapsedMilliseconds / 1000d, 2));
else
logger.Information($"{afterMessage} in {{elapsed}} secs",
@params.Concat(new object[] { Math.Round(Sw.ElapsedMilliseconds / 1000d, 2) }).ToArray());

Console.SetCursorPosition(0, currentRow);
SetCursorPosition(0, currentRow);
}

public static void Step(this ILogger logger, string beforeMessage, string afterMessage, Action action,
params object[] @params)
{
var lastRow = Console.CursorTop;
var lastRow = GetCursorTop();

if (@params is null || @params.Length == 0)
logger.Information(beforeMessage);
Expand All @@ -49,30 +49,30 @@ public static void Step(this ILogger logger, string beforeMessage, string afterM

action();

var currentRow = Console.CursorTop;
Console.SetCursorPosition(0, lastRow);
var currentRow = GetCursorTop();
SetCursorPosition(0, lastRow);
if (@params is null || @params.Length == 0)
logger.Information($"{afterMessage} in {{elapsed}} secs",
Math.Round(Sw.ElapsedMilliseconds / 1000d, 2));
else
logger.Information($"{afterMessage} in {{elapsed}} secs",
@params.Concat(new object[] { Math.Round(Sw.ElapsedMilliseconds / 1000d, 2) }).ToArray());

Console.SetCursorPosition(0, currentRow);
SetCursorPosition(0, currentRow);
}

public static void Step(this ILogger logger, string beforeMessage, string afterMessage, Func<object[]> action)
{
var lastRow = Console.CursorTop;
var lastRow = GetCursorTop();

logger.Information(beforeMessage);

Sw.Restart();

var @params = action();

var currentRow = Console.CursorTop;
Console.SetCursorPosition(0, lastRow);
var currentRow = GetCursorTop();
SetCursorPosition(0, lastRow);

if (@params is null || @params.Length == 0)
logger.Information($"{afterMessage} in {{elapsed}} secs",
Expand All @@ -81,6 +81,21 @@ public static void Step(this ILogger logger, string beforeMessage, string afterM
logger.Information($"{afterMessage} in {{elapsed}} secs",
@params.Concat(new object[] { Math.Round(Sw.ElapsedMilliseconds / 1000d, 2) }).ToArray());

Console.SetCursorPosition(0, currentRow);
SetCursorPosition(0, currentRow);
}

private static int GetCursorTop()
{
var cursor = 0;
try { cursor = Console.CursorTop; }
catch { }

return cursor;
}

private static void SetCursorPosition(int position, int lastRow)
{
try { Console.SetCursorPosition(position, lastRow);}
catch { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>024469f1-c30b-4f99-aa0b-686047b99388</UserSecretsId>
<LangVersion>11.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Standalone\NeoServer.Server.Standalone.csproj" />
<ProjectReference Include="..\..\WebAPI\NeoServer.Web.API.csproj" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions src/NeoServer.Aspire/NeoServer.Aspire.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var builder = DistributedApplication.CreateBuilder(args);

var username = builder.AddParameter("username", secret: true);
var password = builder.AddParameter("password", secret: true);

var postgres = builder.AddPostgres("postgres", username, password, port: 5432)
.WithPgAdmin()
.WithVolume("postgres-data-opencoremmo", "/var/lib/postgresql/data");

var standaloneServer = builder.AddProject<Projects.NeoServer_Server_Standalone>("Standalone")
.WaitFor(postgres);

var webApi = builder.AddProject<Projects.NeoServer_Web_API>("webApi")
.WaitFor(postgres);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17153;http://localhost:15215",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21254",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22061"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15215",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19002",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20259"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
13 changes: 13 additions & 0 deletions src/NeoServer.Aspire/NeoServer.Aspire.AppHost/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Parameters": {
"username": "postgres",
"password": "postgres"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
11 changes: 11 additions & 0 deletions src/NeoServer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeoServer.Web.Shared", "Sha
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeoServer.Shared.IoC", "Shared\NeoServer.IoC\NeoServer.Shared.IoC.csproj", "{B0353BE8-6DE2-4D8F-A518-6123B0A34124}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeoServer.Aspire.AppHost", "NeoServer.Aspire\NeoServer.Aspire.AppHost\NeoServer.Aspire.AppHost.csproj", "{BC61E4DA-D4F3-46DC-9B1D-E563BDF45E02}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -421,6 +423,14 @@ Global
{B0353BE8-6DE2-4D8F-A518-6123B0A34124}.Release|Any CPU.Build.0 = Release|Any CPU
{B0353BE8-6DE2-4D8F-A518-6123B0A34124}.Release|x64.ActiveCfg = Release|Any CPU
{B0353BE8-6DE2-4D8F-A518-6123B0A34124}.Release|x64.Build.0 = Release|Any CPU
{BC61E4DA-D4F3-46DC-9B1D-E563BDF45E02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC61E4DA-D4F3-46DC-9B1D-E563BDF45E02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC61E4DA-D4F3-46DC-9B1D-E563BDF45E02}.Debug|x64.ActiveCfg = Debug|Any CPU
{BC61E4DA-D4F3-46DC-9B1D-E563BDF45E02}.Debug|x64.Build.0 = Debug|Any CPU
{BC61E4DA-D4F3-46DC-9B1D-E563BDF45E02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC61E4DA-D4F3-46DC-9B1D-E563BDF45E02}.Release|Any CPU.Build.0 = Release|Any CPU
{BC61E4DA-D4F3-46DC-9B1D-E563BDF45E02}.Release|x64.ActiveCfg = Release|Any CPU
{BC61E4DA-D4F3-46DC-9B1D-E563BDF45E02}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -473,6 +483,7 @@ Global
{ABF0692C-9C53-472D-B960-E4444FE46B2C} = {41D4D3B5-6FC6-48F5-9D05-EA8C293DB44B}
{94C3B154-2E2F-4787-9ECD-A4B217862EC9} = {ABF0692C-9C53-472D-B960-E4444FE46B2C}
{B0353BE8-6DE2-4D8F-A518-6123B0A34124} = {ABF0692C-9C53-472D-B960-E4444FE46B2C}
{BC61E4DA-D4F3-46DC-9B1D-E563BDF45E02} = {41D4D3B5-6FC6-48F5-9D05-EA8C293DB44B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3B3C7097-0071-4218-BE24-5EE9128763B6}
Expand Down
Loading