using System; using System.IO.Pipes; using System.Text; namespace ArchestrAServices.Common.Resolution; public class PipeClient : IDisposable { private string _pipeName; private NamedPipeClientStream _pipeClient; private bool disposed; public PipeClient(string PipeName) { _pipeName = PipeName; _pipeClient = new NamedPipeClientStream(".", _pipeName, PipeDirection.Out); } public bool SendString(string Data) { _pipeClient.Connect(5000); byte[] bytes = Encoding.UTF8.GetBytes(Data); _pipeClient.Write(bytes, 0, bytes.Length); _pipeClient.WaitForPipeDrain(); return true; } public void Dispose() { Dispose(freeManagedObjectsAlso: true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool freeManagedObjectsAlso) { if (!disposed) { if (freeManagedObjectsAlso) { _pipeClient.Dispose(); } disposed = true; } } ~PipeClient() { Dispose(freeManagedObjectsAlso: false); } }