public static void Main() { var client = new IpcClient("ExamplePipeName"); client.Connected += () => Console.WriteLine("Connected"); client.Disconnected += () => Console.WriteLine("Disconnected"); client.Message += message => Console.WriteLine($"Message Received: {message}"); client.Connect(); Thread.Sleep(1000); client.Send("Client 1"); Thread.Sleep(1000); client.Send("Client 2"); Thread.Sleep(1000); client.Send("Client 3"); Thread.Sleep(10000); client.Stop(); Console.WriteLine("End"); }
public void Restart() { // Do not block UI when calling other process via named pipe Task.Run(() => { try { if (!IpcClient.GetRunningApps().Contains("ClientLauncher")) { string clPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Tools", "MP2-ClientLauncher", "MP2-ClientLauncher.exe"); Process.Start(clPath); int waitCounter = 10; // Wait until process is running and the pipe was created. while (waitCounter-- > 0 && !IpcClient.GetRunningApps().Contains("ClientLauncher")) { Thread.Sleep(200); } } // Sends a command to tray launcher that we want to be restarted. using (var client = new IpcClient("ClientLauncher")) { client.Connect(); client.RequestRestart(); } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("Error trying to send restart request.", ex); } }); }
static void Main(string[] args) { InputArguments inputArguments = new InputArguments(args); string scriptBlock = String.Empty; if (!string.IsNullOrEmpty(inputArguments["-Command"])) { scriptBlock = inputArguments["-Command"]; } else if (!string.IsNullOrEmpty(inputArguments["-Define"])) { scriptBlock = inputArguments["-Define"].TransformForBlu(); } else if (!string.IsNullOrEmpty(inputArguments["-Execute"])) { // TODO } else { Console.WriteLine("BluSheel needs to be executed with -Command or -Define or -Execute parameters."); Environment.Exit(1); } try { IpcClient ipcClient = new IpcClient(".", "BluPowerShell"); PipeStream pipe = ipcClient.Connect(1); Byte[] output = Encoding.UTF8.GetBytes(scriptBlock); pipe.Write(output, 0, output.Length); // Read the result Byte[] data = new Byte[IpcClient.ClientInBufferSize]; Int32 bytesRead = pipe.Read(data, 0, data.Length); ExitHandler(Encoding.UTF8.GetString(data, 0, bytesRead)); // Done with pipe pipe.Close(); } catch (Exception ex) { EventLogHelper.WriteToEventLog(Config.ShellName, 2, "Exception in send/recieve script block: " + Environment.NewLine + ex.Message); Environment.Exit(1); } }
private static void StopClient() { try { Process[] processes = Process.GetProcessesByName("MP2-Client"); if (processes.Length == 0) { return; } // If process is running, send an IPC command to force closing. using (var client = new IpcClient("Client")) { client.Connect(); client.ShutdownApplication(2000, true); } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("MP2-Client.exe couldn't be started.", ex); } }
private void ConnectOnClick(object?sender, EventArgs e) { _client.Connect(); }