public bool ProcessMessages(NamedPipeServerStream server) { BinaryFormatter binForm = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream()) { server.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); object data = binForm.Deserialize(memoryStream); string message = data as string; if (message != null) { _synchronizationContext.Post(state => { switch (message) { case "StartTeaching": PointCapture.Instance.Mode = CaptureMode.Training; break; case "StopTraining": if (PointCapture.Instance.Mode != CaptureMode.UserDisabled) { PointCapture.Instance.Mode = CaptureMode.Normal; } break; case "EnableCapture": PointCapture.Instance.EnablePointCapture(); break; case "DisableCapture": PointCapture.Instance.DisablePointCapture(); break; case "LoadApplications": ApplicationManager.Instance.LoadApplications().Wait(); break; case "LoadGestures": GestureManager.Instance.LoadGestures().Wait(); break; case "LoadConfiguration": AppConfig.Reload(); break; case "ShowTrayIcon": TrayManager.Instance.TrayIconVisible = true; break; case "HideTrayIcon": TrayManager.Instance.TrayIconVisible = false; break; } }, null); } } return(true); }
public void Get(Stream s) { if (thr != null) { throw new InvalidOperationException("Can only serve one thing at a time!"); } if (e != null) { throw new InvalidOperationException("Previous attempt failed!", e); } if (!s.CanWrite) { throw new ArgumentException($"{nameof(Stream)} must be readable!"); } using var evt = new ManualResetEventSlim(); thr = new Thread(delegate() { try { using var srv = new NamedPipeServerStream(PipeName, PipeDirection.In); evt.Set(); srv.WaitForConnection(); srv.CopyTo(s); //srv.Flush(); } catch (Exception ee) { e = ee; } }); thr.Start(); evt.Wait(); }
public bool ProcessMessages(NamedPipeServerStream server) { try { BinaryFormatter binForm = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream()) { server.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); object data = binForm.Deserialize(memoryStream); Application.Current?.Dispatcher.InvokeAsync(() => { string message = data as string; if (message != null) { switch (message) { case "MainWindow": { foreach (Window win in Application.Current.Windows) { if (win.GetType() == typeof(MainWindow)) { win.Activate(); return; } } MainWindow mw = new MainWindow(); mw.Show(); mw.Activate(); break; } case "Exit": { Application.Current.Shutdown(); break; } } } else { var newGesture = data as Tuple <string, List <List <List <Point> > > >; if (newGesture == null) { return; } GotNewGesture?.Invoke(this, new Gesture(newGesture.Item1, newGesture.Item2.Select(list => new PointPattern(list)).ToArray())); } }, DispatcherPriority.Input); } return(true); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } }
public bool ProcessMessages(NamedPipeServerStream server) { try { BinaryFormatter binForm = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream()) { server.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); object data = binForm.Deserialize(memoryStream); Application.Current?.Dispatcher.InvokeAsync(() => { string message = data as string; if (message != null) { switch (message) { case "Exit": { Application.Current.Shutdown(); break; } } } else { var newGesture = data as List <List <List <Point> > >; if (newGesture == null) { return; } GotNewPattern?.Invoke(this, newGesture.Select(list => new PointPattern(list)).ToArray()); } }, DispatcherPriority.Input); } return(true); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } }
private void ReadThreadStart(NamedPipeServerStream decodePipe, Process encoder) { if (!decodePipe.IsConnected) { decodePipe.WaitForConnection(); } try { decodePipe.CopyTo(encoder.StandardInput.BaseStream); } catch (Exception ex) { Log.Error(ex); } encoder.StandardInput.BaseStream.Close(); }
public bool ProcessMessages(NamedPipeServerStream server) { BinaryFormatter binForm = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream()) { server.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); object data = binForm.Deserialize(memoryStream); string message = data as string; if (message != null) { switch (message) { case "LoadConfiguration": AppConfig.Reload(); break; } } } return(true); }
public bool ProcessMessages(NamedPipeServerStream server) { BinaryFormatter binForm = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream()) { server.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); object data = binForm.Deserialize(memoryStream); string message = data as string; if (message != null) { _synchronizationContext.Post(state => { switch (message) { //case "Guide": // GestureSignDaemon.Input.TouchCapture.Instance.MessageWindow.PointsIntercepted += InitializationRatio.MessageWindow_PointsIntercepted; // break; case "StartTeaching": { TouchCapture.Instance.Mode = CaptureMode.Training; break; } case "EnableTouchCapture": TouchCapture.Instance.EnableTouchCapture(); break; case "DisableTouchCapture": TouchCapture.Instance.DisableTouchCapture(); break; case "LoadApplications": ApplicationManager.Instance.LoadApplications().Wait(); break; case "LoadGestures": GestureManager.Instance.LoadGestures().Wait(); break; case "LoadConfiguration": AppConfig.Reload(); break; case "ShowTrayIcon": TrayManager.Instance.TrayIconVisible = true; break; case "HideTrayIcon": TrayManager.Instance.TrayIconVisible = false; break; case "OverlayGesture": TouchCapture.Instance.OverlayGesture = true; break; } }, null); } } return(true); }