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> <ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" /> <ProjectReference Include="..\PipeShared\PipeShared.csproj" />
<ProjectReference Include="..\Server\Server.csproj" /> <ProjectReference Include="..\PipeServer\PipeServer.csproj" />
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>
+18 -7
View File
@@ -1,11 +1,12 @@
using System.Diagnostics; using PipeMethodCalls;
using PipeShared;
using System.Diagnostics;
using System.Xml.Linq; using System.Xml.Linq;
using PipeMethodCalls;
using ClientServerShared;
// All output is written to an XML report next to the executable // All output is written to an XML report next to the executable
string reportPath = Path.Combine(AppContext.BaseDirectory, "ClientReport.xml"); string reportPath = Path.Combine(AppContext.BaseDirectory, "ClientReport.xml");
var report = new XElement("Report", new XAttribute("Started", DateTime.Now.ToString("O"))); var report = new XElement("Report", new XAttribute("Started", DateTime.Now.ToString("O")));
bool colorSwitch = false;
Log("Client started."); Log("Client started.");
@@ -13,7 +14,7 @@ Log("Client started.");
string pipeName = $"PipeDemo-{Environment.ProcessId}-{Guid.NewGuid():N}"; string pipeName = $"PipeDemo-{Environment.ProcessId}-{Guid.NewGuid():N}";
Process? serverProcess = null; Process? serverProcess = null;
PipeClient<ICalculator> client = null!; PipeClient<IServerMethods> client = null!;
try try
{ {
@@ -52,10 +53,20 @@ lock (report)
new XDocument(report).Save(reportPath); new XDocument(report).Save(reportPath);
// Thread-safe: also called from the Process.Exited event // Thread-safe: also called from the Process.Exited event
void Log(string message) void Log(string message)
{ {
lock (report) lock (report)
report.Add(new XElement("Entry", new XAttribute("Time", DateTime.Now.ToString("O")), message)); 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() async Task BasicCallsExampleAsync()
@@ -150,7 +161,7 @@ async Task StartServerAndConnectAsync(string pipeName)
}; };
serverProcess = process; serverProcess = process;
client = new PipeClient<ICalculator>(new JsonFieldsPipeSerializer(), pipeName); client = new PipeClient<IServerMethods>(new JsonFieldsPipeSerializer(), pipeName);
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
await client.ConnectAsync(cts.Token); await client.ConnectAsync(cts.Token);
} }
@@ -159,7 +170,7 @@ async Task StartServerAndConnectAsync(string pipeName)
static Process StartServer(string pipeName) static Process StartServer(string pipeName)
{ {
string baseDir = AppContext.BaseDirectory; 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; ProcessStartInfo startInfo;
if (File.Exists(serverExe)) if (File.Exists(serverExe))
{ {
@@ -168,7 +179,7 @@ static Process StartServer(string pipeName)
else else
{ {
startInfo = new ProcessStartInfo("dotnet"); 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.ArgumentList.Add($"{PipeConstants.PipeNameArgPrefix}{pipeName}");
startInfo.UseShellExecute = false; startInfo.UseShellExecute = false;
+3 -3
View File
@@ -1,5 +1,5 @@
<Solution> <Solution>
<Project Path="Client/Client.csproj" /> <Project Path="PipeClient/PipeClient.csproj" />
<Project Path="Server/Server.csproj" /> <Project Path="PipeServer/PipeServer.csproj" />
<Project Path="Shared/Shared.csproj" /> <Project Path="PipeShared/PipeShared.csproj" />
</Solution> </Solution>
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" /> <ProjectReference Include="..\PipeShared\PipeShared.csproj" />
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>
+3 -3
View File
@@ -1,4 +1,4 @@
using ClientServerShared; using PipeShared;
using PipeMethodCalls; using PipeMethodCalls;
using Server; 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 // Exceptions in handler methods are caught by PipeMethodCalls and sent to the client
// (client receives PipeInvokeFailedException with the server exception details). // (client receives PipeInvokeFailedException with the server exception details).
var server = new PipeServer<ICalculator>( var server = new PipeServer<IServerMethods>(
new JsonFieldsPipeSerializer(), new JsonFieldsPipeSerializer(),
pipeName, pipeName,
() => new Calculator()); () => new ServerMethods());
await server.WaitForConnectionAsync(); await server.WaitForConnectionAsync();
Console.WriteLine("Client connected."); Console.WriteLine("Client connected.");
@@ -1,10 +1,10 @@
using System.Collections.Concurrent; using PipeShared;
using System.Collections.Concurrent;
using System.Numerics; using System.Numerics;
using ClientServerShared;
namespace Server; namespace Server;
public class Calculator : ICalculator public class ServerMethods : IServerMethods
{ {
public int Add(int a, int b) => a + b; public int Add(int a, int b) => a + b;
@@ -1,8 +1,8 @@
using System.Numerics; using System.Numerics;
namespace ClientServerShared; namespace PipeShared;
public interface ICalculator public interface IServerMethods
{ {
int Add(int a, int b); int Add(int a, int b);
Vector3 AddVector(Vector3 a, Vector3 b); Vector3 AddVector(Vector3 a, Vector3 b);
@@ -1,7 +1,7 @@
using PipeMethodCalls; using PipeMethodCalls;
using System.Text.Json; using System.Text.Json;
namespace ClientServerShared; namespace PipeShared;
/// <summary> /// <summary>
/// JSON serializer that also includes public fields (required for System.Numerics.Vector3). /// JSON serializer that also includes public fields (required for System.Numerics.Vector3).