Created Testapp

This commit is contained in:
glax 2024-01-15 23:03:45 +01:00
parent 8b374e73a9
commit b5b65dbe45
22 changed files with 102 additions and 7 deletions

View File

@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CS2GSI", "CS2GSI.csproj", "{F2272524-6CDD-4ACD-8CFF-64B9AF98D54A}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CS2GSI", "CS2GSI\CS2GSI.csproj", "{F2272524-6CDD-4ACD-8CFF-64B9AF98D54A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "TestApp\TestApp.csproj", "{A4FE89AD-F89B-4ABC-BA88-DF4AC2CADE09}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -12,5 +14,9 @@ Global
{F2272524-6CDD-4ACD-8CFF-64B9AF98D54A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2272524-6CDD-4ACD-8CFF-64B9AF98D54A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2272524-6CDD-4ACD-8CFF-64B9AF98D54A}.Release|Any CPU.Build.0 = Release|Any CPU
{A4FE89AD-F89B-4ABC-BA88-DF4AC2CADE09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4FE89AD-F89B-4ABC-BA88-DF4AC2CADE09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4FE89AD-F89B-4ABC-BA88-DF4AC2CADE09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4FE89AD-F89B-4ABC-BA88-DF4AC2CADE09}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -25,7 +25,7 @@ public class CS2GSI
this.logger?.Log(LogLevel.Critical, "Could not install GSI-Configfile. Exiting.");
return;
}
this._gsiServer = new GSIServer(3000);
this._gsiServer = new GSIServer(3000, logger);
this._gsiServer.OnMessage += GsiServerOnOnMessage;
while(this._gsiServer.IsRunning)

View File

@ -6,6 +6,11 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
@ -21,9 +26,4 @@
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>

60
TestApp/Logger.cs Normal file
View File

@ -0,0 +1,60 @@
using Microsoft.Extensions.Logging;
namespace CS2GSI.TestApp;
public class Logger : ILogger
{
private readonly LogLevel _enabledLoglevel;
private readonly ConsoleColor _defaultForegroundColor = Console.ForegroundColor;
private readonly ConsoleColor _defaultBackgroundColor = Console.BackgroundColor;
public Logger(LogLevel logLevel = LogLevel.Information)
{
_enabledLoglevel = logLevel;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel))
return;
Console.ForegroundColor = ForegroundColorForLogLevel(logLevel);
Console.BackgroundColor = BackgroundColorForLogLevel(logLevel);
Console.Write(logLevel.ToString()[..3].ToUpper());
Console.ResetColor();
// ReSharper disable once LocalizableElement
Console.Write($" [{DateTime.UtcNow:HH:mm:ss.fff}] ");
Console.WriteLine(formatter.Invoke(state, exception));
}
public bool IsEnabled(LogLevel logLevel)
{
return logLevel >= _enabledLoglevel;
}
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
{
return null;
}
private ConsoleColor ForegroundColorForLogLevel(LogLevel logLevel)
{
return logLevel switch
{
LogLevel.Error or LogLevel.Critical => ConsoleColor.Black,
LogLevel.Debug => ConsoleColor.Black,
LogLevel.Information => ConsoleColor.White,
_ => _defaultForegroundColor
};
}
private ConsoleColor BackgroundColorForLogLevel(LogLevel logLevel)
{
return logLevel switch
{
LogLevel.Error or LogLevel.Critical => ConsoleColor.Red,
LogLevel.Debug => ConsoleColor.Yellow,
LogLevel.Information => ConsoleColor.Black,
_ => _defaultBackgroundColor
};
}
}

11
TestApp/Program.cs Normal file
View File

@ -0,0 +1,11 @@
// See https://aka.ms/new-console-template for more information
using CS2GSI.TestApp;
public class TestApp
{
public static void Main(string[] args)
{
new CS2GSI.CS2GSI(new Logger());
}
}

18
TestApp/TestApp.csproj Normal file
View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CS2GSI\CS2GSI.csproj" />
</ItemGroup>
</Project>