Compare commits

...
5 Commits
Author SHA1 Message Date
Matthias Heil 3fe7fa42e5 Alternate server exception log colors
Use red and dark red alternation for server exceptions, green for other messages, and reorder the related using directives.
2026-11-10 11:06:10 +01:00
Matthias Heil ae723b9bea Align client and solution with renamed projects
Update project references and solution entries to use
`PipeClient` and `PipeServer`, and launch the renamed
`PipeServer.exe` or `PipeServer.dll`.
2026-11-10 10:57:10 +01:00
Matthias Heil f00e3298b1 Rename projects 2026-11-10 10:54:46 +01:00
Matthias Heil d618bac679 Replace ICalculator with IServerMethods
Rename the server implementation and update client/server pipes to use
the shared server-methods interface. Move PipeConstants alongside it and
log “Client started.” during client startup.
2026-11-10 10:42:57 +01:00
Matthias Heil 23c2a9ea16 Add colored console output to logging
Update `Log` to write messages to the console, using red for server exceptions and blue for other messages. Preserve thread-safe XML report logging and reorder `using` directives.
2026-11-10 10:38:20 +01:00
9 changed files with 35 additions and 24 deletions
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\Server\Server.csproj" />
<ProjectReference Include="..\PipeShared\PipeShared.csproj" />
<ProjectReference Include="..\PipeServer\PipeServer.csproj" />
</ItemGroup>
<PropertyGroup>
+18 -7
View File
@@ -1,11 +1,12 @@
using System.Diagnostics;
using PipeMethodCalls;
using PipeShared;
using System.Diagnostics;
using System.Xml.Linq;
using PipeMethodCalls;
using ClientServerShared;
// All output is written to an XML report next to the executable
string reportPath = Path.Combine(AppContext.BaseDirectory, "ClientReport.xml");
var report = new XElement("Report", new XAttribute("Started", DateTime.Now.ToString("O")));
bool colorSwitch = false;
Log("Client started.");
@@ -13,7 +14,7 @@ Log("Client started.");
string pipeName = $"PipeDemo-{Environment.ProcessId}-{Guid.NewGuid():N}";
Process? serverProcess = null;
PipeClient<ICalculator> client = null!;
PipeClient<IServerMethods> client = null!;
try
{
@@ -52,10 +53,20 @@ lock (report)
new XDocument(report).Save(reportPath);
// Thread-safe: also called from the Process.Exited event
void Log(string message)
{
lock (report)
report.Add(new XElement("Entry", new XAttribute("Time", DateTime.Now.ToString("O")), message));
if (message.Contains("Server exception"))
{
Console.ForegroundColor = colorSwitch ? ConsoleColor.DarkRed : ConsoleColor.Red;
colorSwitch = !colorSwitch;
}
else
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(message);
Console.ResetColor();
}
async Task BasicCallsExampleAsync()
@@ -150,7 +161,7 @@ async Task StartServerAndConnectAsync(string pipeName)
};
serverProcess = process;
client = new PipeClient<ICalculator>(new JsonFieldsPipeSerializer(), pipeName);
client = new PipeClient<IServerMethods>(new JsonFieldsPipeSerializer(), pipeName);
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
await client.ConnectAsync(cts.Token);
}
@@ -159,7 +170,7 @@ async Task StartServerAndConnectAsync(string pipeName)
static Process StartServer(string pipeName)
{
string baseDir = AppContext.BaseDirectory;
string serverExe = Path.Combine(baseDir, OperatingSystem.IsWindows() ? "Server.exe" : "Server");
string serverExe = Path.Combine(baseDir, OperatingSystem.IsWindows() ? "PipeServer.exe" : "PipeServer");
ProcessStartInfo startInfo;
if (File.Exists(serverExe))
{
@@ -168,7 +179,7 @@ static Process StartServer(string pipeName)
else
{
startInfo = new ProcessStartInfo("dotnet");
startInfo.ArgumentList.Add(Path.Combine(baseDir, "Server.dll"));
startInfo.ArgumentList.Add(Path.Combine(baseDir, "PipeServer.dll"));
}
startInfo.ArgumentList.Add($"{PipeConstants.PipeNameArgPrefix}{pipeName}");
startInfo.UseShellExecute = false;
+3 -3
View File
@@ -1,5 +1,5 @@
<Solution>
<Project Path="Client/Client.csproj" />
<Project Path="Server/Server.csproj" />
<Project Path="Shared/Shared.csproj" />
<Project Path="PipeClient/PipeClient.csproj" />
<Project Path="PipeServer/PipeServer.csproj" />
<Project Path="PipeShared/PipeShared.csproj" />
</Solution>
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\PipeShared\PipeShared.csproj" />
</ItemGroup>
<PropertyGroup>
+3 -3
View File
@@ -1,4 +1,4 @@
using ClientServerShared;
using PipeShared;
using PipeMethodCalls;
using Server;
@@ -9,10 +9,10 @@ Console.WriteLine($"Server started. Pipe: {pipeName}");
// Exceptions in handler methods are caught by PipeMethodCalls and sent to the client
// (client receives PipeInvokeFailedException with the server exception details).
var server = new PipeServer<ICalculator>(
var server = new PipeServer<IServerMethods>(
new JsonFieldsPipeSerializer(),
pipeName,
() => new Calculator());
() => new ServerMethods());
await server.WaitForConnectionAsync();
Console.WriteLine("Client connected.");
@@ -1,10 +1,10 @@
using System.Collections.Concurrent;
using PipeShared;
using System.Collections.Concurrent;
using System.Numerics;
using ClientServerShared;
namespace Server;
public class Calculator : ICalculator
public class ServerMethods : IServerMethods
{
public int Add(int a, int b) => a + b;
@@ -1,8 +1,8 @@
using System.Numerics;
namespace ClientServerShared;
namespace PipeShared;
public interface ICalculator
public interface IServerMethods
{
int Add(int a, int b);
Vector3 AddVector(Vector3 a, Vector3 b);
@@ -1,7 +1,7 @@
using PipeMethodCalls;
using System.Text.Json;
namespace ClientServerShared;
namespace PipeShared;
/// <summary>
/// JSON serializer that also includes public fields (required for System.Numerics.Vector3).