From d618bac6799abb67a3542f3278fea72bdc18a7ed Mon Sep 17 00:00:00 2001 From: Matthias Heil Date: Tue, 10 Nov 2026 10:42:57 +0100 Subject: [PATCH] Replace ICalculator with IServerMethods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Client/Program.cs | 4 ++-- Server/Program.cs | 4 ++-- Server/{Calculator.cs => ServerMethods.cs} | 6 +++--- Shared/{ICalculator.cs => IServerMethods.cs} | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) rename Server/{Calculator.cs => ServerMethods.cs} (93%) rename Shared/{ICalculator.cs => IServerMethods.cs} (93%) diff --git a/Client/Program.cs b/Client/Program.cs index fe5cb9d..b53e89a 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -13,7 +13,7 @@ Log("Client started."); string pipeName = $"PipeDemo-{Environment.ProcessId}-{Guid.NewGuid():N}"; Process? serverProcess = null; -PipeClient client = null!; +PipeClient client = null!; try { @@ -154,7 +154,7 @@ async Task StartServerAndConnectAsync(string pipeName) }; serverProcess = process; - client = new PipeClient(new JsonFieldsPipeSerializer(), pipeName); + client = new PipeClient(new JsonFieldsPipeSerializer(), pipeName); using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); await client.ConnectAsync(cts.Token); } diff --git a/Server/Program.cs b/Server/Program.cs index f08e1ad..f94db88 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -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( +var server = new PipeServer( new JsonFieldsPipeSerializer(), pipeName, - () => new Calculator()); + () => new ServerMethods()); await server.WaitForConnectionAsync(); Console.WriteLine("Client connected."); diff --git a/Server/Calculator.cs b/Server/ServerMethods.cs similarity index 93% rename from Server/Calculator.cs rename to Server/ServerMethods.cs index 2ae8928..0a3df13 100644 --- a/Server/Calculator.cs +++ b/Server/ServerMethods.cs @@ -1,10 +1,10 @@ -using System.Collections.Concurrent; +using ClientServerShared; +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; diff --git a/Shared/ICalculator.cs b/Shared/IServerMethods.cs similarity index 93% rename from Shared/ICalculator.cs rename to Shared/IServerMethods.cs index a8c547c..53f9699 100644 --- a/Shared/ICalculator.cs +++ b/Shared/IServerMethods.cs @@ -2,7 +2,7 @@ using System.Numerics; namespace ClientServerShared; -public interface ICalculator +public interface IServerMethods { int Add(int a, int b); Vector3 AddVector(Vector3 a, Vector3 b);