/// <summary> /// </summary> /// <param name="Command"></param> /// <param name="Args"></param> /// <returns></returns> public bool Send(string Command, string[] Args, out string Result, RecievePartialIPCResponseEventHandler StreamHandler = null) { Result = ""; try { using (NamedPipeClientStream PipeClient = new NamedPipeClientStream(".", PipeName, PipeDirection.InOut, PipeOptions.Asynchronous)) { PipeClient.Connect(3000); using (BinaryWriter Writer = new BinaryWriter(PipeClient)) { using (BinaryReader Reader = new BinaryReader(PipeClient)) { // Send command. //Console.WriteLine("Sending: " + Command); Writer.Write(Command); Writer.Write(Args.Length); foreach (string arg in Args) { Writer.Write(arg); } Writer.Flush(); // Read response. while (true) { bool Final = Reader.ReadBoolean(); if (!Final) { string Block = Reader.ReadString(); StreamHandler?.Invoke(Block); Result += Block; } else { break; } } //Console.WriteLine("Response: " + Result); } } } } catch (Exception Ex) { Logger.Log(LogLevel.Error, LogCategory.Transport, "Failed to send ipc command with error: {0}", Ex.Message); return(false); } return(true); }
/// <summary> /// Entry point. /// /// Usage syntax: BuildSync.Client.Cmd.exe [Arguments to pass to server] /// </summary> /// <param name="Args">Command line arguments provided.</param> public static void Main(string[] Args) { try { CommandIPC Ipc = new CommandIPC("buildsync-client", true); RecievePartialIPCResponseEventHandler ResponseHandler = Response => { Console.Write(Response); }; string Result = ""; if (!Ipc.Send("RunCommand", Args, out Result, ResponseHandler)) { Console.WriteLine("FAILURE: Failed to execute ipc command on client."); } } catch (Exception) { Console.WriteLine("FAILURE: Could not connect to ipc client, make sure buildsync client is running."); } }