public PipeClient(PipeConfiguration configuration) { address = new EndpointAddress(string.Format(CultureInfo.InvariantCulture, "{0}/{1}", configuration.Uri, configuration.Name)); proxy = ChannelFactory<IPipeService>.CreateChannel(new NetNamedPipeBinding(), address); }
protected override void OnStartup(StartupEventArgs e) { // unhandleed exceptions AppDomain.CurrentDomain.UnhandledException += ExceptionOccured; // named pipe configuration var pipeConf = new PipeConfiguration { Uri = "net.pipe://localhost/Pipe", Name = "Farawla" }; // passed argument var arg = e.Args.Length > 0 ? e.Args[0] : string.Empty; // check if other instance exists if (mutex.WaitOne(TimeSpan.Zero, true)) { mutex.ReleaseMutex(); try { var server = new PipeServer(pipeConf); // listen for other instances server.Start((action, data) => { if (action == "open") { // open document Controller.Current.CreateNewTab(data); // activate window if (Settings.Instance.IsWindowMaximized) Controller.Current.MainWindow.WindowState = WindowState.Maximized; else Controller.Current.MainWindow.WindowState = WindowState.Normal; Controller.Current.MainWindow.Activate(); } }); } catch { } } else { // if arg found, send to original instance if (!arg.IsBlank()) { try { var client = new PipeClient(pipeConf); client.Send("open", arg); } catch { } } Current.Shutdown(); return; // just in case Shutdown is not forcing } base.OnStartup(e); // pass arguments if found if (!arg.IsBlank()) { Current.Properties["Argument0"] = arg; } }
public PipeServer(PipeConfiguration configuration) { this.configuration = configuration; }