Initial commit

This commit is contained in:
Matthias Heil
2026-11-10 09:23:35 +01:00
commit d14a20dfac
9 changed files with 244 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
using System.Numerics;
using Shared;
namespace Server;
public class Calculator : ICalculator
{
public int Add(int a, int b) => a + b;
public Vector3 AddVector(Vector3 a, Vector3 b) => a + b;
public double Divide(double a, double b)
{
if (b == 0)
throw new DivideByZeroException("Division durch 0 ist nicht erlaubt.");
return a / b;
}
public async Task<string> EchoAsync(string text)
{
await Task.Delay(50);
if (string.IsNullOrEmpty(text))
throw new ArgumentException("Text darf nicht leer sein.", nameof(text));
return $"Echo: {text}";
}
public void Crash(int exitCode) => Environment.Exit(exitCode);
}
+21
View File
@@ -0,0 +1,21 @@
using PipeMethodCalls;
using Server;
using Shared;
string pipeName = args.FirstOrDefault(a => a.StartsWith(PipeConstants.PipeNameArgPrefix))?
[PipeConstants.PipeNameArgPrefix.Length..] ?? "PipeDemo";
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>(
new JsonFieldsPipeSerializer(),
pipeName,
() => new Calculator());
await server.WaitForConnectionAsync();
Console.WriteLine("Client connected.");
await server.WaitForRemotePipeCloseAsync();
Console.WriteLine("Client disconnected. Server exiting.");
+14
View File
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>