Using static NamedPipeClient? PipeClient { get; set; } in Vector3DebuggerVisualizerProvider works.
new VisualizerTargetType("Frame Array Visualizer", "Num.Roto.Visualization.Math.Geometry.Frame[]
This commit is contained in:
@@ -9,7 +9,7 @@ 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 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));
|
||||
@@ -19,29 +19,40 @@ public class NamedPipeClient (string pipeName,string? serverLocation = null, st
|
||||
if (IsConnected) return;
|
||||
PipeClient.SetLogger((m) => Trace.WriteLine(m));
|
||||
var serverAvailable = Process.GetProcessesByName(ServerName).Length > 0;
|
||||
Logger($"Server available: {serverAvailable}");
|
||||
if (!serverAvailable)
|
||||
{
|
||||
var serverPath = ServerLocation + ServerName + ".exe";
|
||||
if (!File.Exists(serverPath)) throw new FileNotFoundException(serverPath);
|
||||
if (!File.Exists(serverPath)) throw new FileNotFoundException($"{nameof(StartServerAsync)}, Server does not exist, Path = {serverPath}");
|
||||
var server = new Process { StartInfo = { FileName = serverPath } };
|
||||
server.Start();
|
||||
}
|
||||
await PipeClient.ConnectAsync();
|
||||
}
|
||||
try
|
||||
{
|
||||
await PipeClient.ConnectAsync().ConfigureAwait(true);
|
||||
Logger("NamedPipeClient.StartServerAsync succeded.");
|
||||
return;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Logger(e.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> SetDebugObjectAsync(DebugObject debugObject)
|
||||
{
|
||||
await StartServerAsync();
|
||||
var result = PipeClient.InvokeAsync(server => server.SetDebugObjectAsync(debugObject)).Result;
|
||||
Logger("NamedPipeClient.SetDebugObject: result = " + result);
|
||||
await StartServerAsync().ConfigureAwait(true);
|
||||
var result = await PipeClient.InvokeAsync(server => server.SetDebugObjectAsync(debugObject));
|
||||
Logger("NamedPipeClient.SetDebugObjectAsync: 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);
|
||||
await StartServerAsync().ConfigureAwait(true);
|
||||
var result = await PipeClient.InvokeAsync(server => server.SetMessageAsync(message));
|
||||
Logger("NamedPipeClient.SetMessageAsync: result = " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@ using PipeMethodCalls;
|
||||
namespace NamedPipes;
|
||||
public partial class NamedPipesServer(string pipeName,Action<string>? logger = null) : ObservableObject,IDebugVisualizer, IDisposable
|
||||
{
|
||||
~NamedPipesServer()
|
||||
{
|
||||
Logger(@"~NamedPipesServer called!");
|
||||
|
||||
}
|
||||
public bool IsConnected => PipeServer is { State: PipeState.Connected };
|
||||
private PipeServer<IDebugVisualizer>? PipeServer {get; set;}
|
||||
private string PipeName { get; } = pipeName;
|
||||
@@ -15,15 +20,28 @@ public partial class NamedPipesServer(string pipeName,Action<string>? logger = n
|
||||
public async Task WaitForConnectionAsync()
|
||||
{
|
||||
if(IsConnected) return;
|
||||
if (PipeServer == null || PipeServer.State == PipeState.Closed)
|
||||
if (PipeServer == null || PipeServer.State != PipeState.Connected)
|
||||
{
|
||||
PipeServer?.Dispose();
|
||||
PipeServer = new PipeServer<IDebugVisualizer>(new PipeSerializer(), PipeName, () => this);
|
||||
PipeServer.SetLogger((m) => Trace.WriteLine(m));
|
||||
}
|
||||
await PipeServer.WaitForConnectionAsync();
|
||||
}
|
||||
Logger("Waiting for client connection...");
|
||||
await PipeServer.WaitForConnectionAsync().ConfigureAwait(true);
|
||||
}
|
||||
public async Task RunAsync()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
await WaitForConnectionAsync().ConfigureAwait(true);
|
||||
Logger("Client connected.");
|
||||
while (IsConnected)
|
||||
{
|
||||
await Task.Delay(100).ConfigureAwait(true);
|
||||
}
|
||||
Logger("Client disconnected.");
|
||||
}
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
public partial DebugObject? DebugObject { get; private set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user