Test projects are working.
This commit is contained in:
54
NamedPipes/NamedPipeClient.cs
Normal file
54
NamedPipes/NamedPipeClient.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using PipeMethodCalls;
|
||||
|
||||
namespace NamedPipes;
|
||||
|
||||
public class NamedPipeClient (string pipeName,string? serverLocation = null, string? serverName = null,Action<string>? logger = null): IDebugVisualizer, IDisposable
|
||||
{
|
||||
private bool IsConnected => PipeClient.State == PipeState.Connected;
|
||||
private PipeClient<IDebugVisualizer> PipeClient { get; }= new(new PipeSerializer(), pipeName);
|
||||
private string ServerLocation { get; } = serverLocation ?? Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\Visual Studio 2026\Visualizers\Server\NrxVisualizer\";
|
||||
private string ServerName { get; } = serverName ?? "Num.Roto.Nrx.VisualizerServer";
|
||||
private Action<string> Logger { get;} = logger ??((m) => Trace.WriteLine(m));
|
||||
|
||||
private async Task StartServerAsync()
|
||||
{
|
||||
if (IsConnected) return;
|
||||
PipeClient.SetLogger((m) => Trace.WriteLine(m));
|
||||
var serverAvailable = Process.GetProcessesByName(ServerName).Length > 0;
|
||||
if (!serverAvailable)
|
||||
{
|
||||
var serverPath = ServerLocation + ServerName + ".exe";
|
||||
if (!File.Exists(serverPath)) throw new FileNotFoundException(serverPath);
|
||||
var server = new Process { StartInfo = { FileName = serverPath } };
|
||||
server.Start();
|
||||
}
|
||||
await PipeClient.ConnectAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> SetDebugObjectAsync(DebugObject debugObject)
|
||||
{
|
||||
await StartServerAsync();
|
||||
var result = PipeClient.InvokeAsync(server => server.SetDebugObjectAsync(debugObject)).Result;
|
||||
Logger("NamedPipeClient.SetDebugObject: result = " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> SetMessageAsync(string message)
|
||||
{
|
||||
await StartServerAsync();
|
||||
var result = PipeClient.InvokeAsync(server => server.SetMessageAsync(message)).Result;
|
||||
Logger("NamedPipeClient.SetMessage: result = " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
PipeClient.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user