private void OpenInNewTab() { var openDialog = CreateOpenLSLDialog(); var showDialog = openDialog.ShowDialog(); if (showDialog == null || !showDialog.Value) { return; } var alreadyOpen = EditorTabs.FirstOrDefault(x => x.FilePath == openDialog.FileName); if (alreadyOpen != null) { TabControl.SelectedIndex = EditorTabs.IndexOf(alreadyOpen); return; } var tab = CreateEditorTab(); if (!tab.OpenFileInteractive(openDialog.FileName)) { return; } EditorTabs.Add(tab); TabControl.SelectedIndex = EditorTabs.Count - 1; }
private NamedPipeServerStream CreateOpenTabPipeServer(string pipeName) { var ps = new PipeSecurity(); ps.AddAccessRule(new PipeAccessRule("Users", PipeAccessRights.ReadWrite | PipeAccessRights.CreateNewInstance, AccessControlType.Allow)); ps.AddAccessRule(new PipeAccessRule("SYSTEM", PipeAccessRights.FullControl, AccessControlType.Allow)); var pipeClientConnection = new NamedPipeServerStream(pipeName, PipeDirection.In, 5, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024, ps); pipeClientConnection.BeginWaitForConnection(asyncResult => { using (var conn = (NamedPipeServerStream)asyncResult.AsyncState) { conn.EndWaitForConnection(asyncResult); var newServer = CreateOpenTabPipeServer(pipeName); var streamReader = new StreamReader(conn); while (true) { string file = streamReader.ReadLine(); if (file == ":KILL:") { if (pipeClientConnection.IsConnected) { pipeClientConnection.Disconnect(); } pipeClientConnection.Close(); pipeClientConnection.Dispose(); if (newServer.IsConnected) { newServer.Disconnect(); } newServer.Close(); newServer.Dispose(); Dispatcher.Invoke(Close); } if (file == ":EOF:") { break; } Dispatcher.Invoke(() => { var alreadyOpen = EditorTabs.FirstOrDefault(x => x.FilePath == file); if (alreadyOpen != null) { TabControl.SelectedIndex = EditorTabs.IndexOf(alreadyOpen); return; } var tab = CreateEditorTab(); if (!tab.OpenFileInteractive(file)) { return; } EditorTabs.Add(tab); TabControl.SelectedIndex = EditorTabs.Count - 1; }); } } }, pipeClientConnection); return(pipeClientConnection); }