示例#1
0
        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);
            }
        }
示例#2
0
        public bool ProcessMessages(IpcCommands command, object data)
        {
            try
            {
                Application.Current?.Dispatcher.InvokeAsync(() =>
                {
                    switch (command)
                    {
                    case IpcCommands.Exit:
                        {
                            Application.Current.Shutdown();
                            break;
                        }

                    case IpcCommands.GotGesture:
                        {
                            var newGesture = data as Point[][][];
                            if (newGesture == null)
                            {
                                return;
                            }

                            GotNewPattern?.Invoke(this, newGesture.Select(list => new PointPattern(list)).ToArray());
                            break;
                        }
                    }
                }, DispatcherPriority.Input);

                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(false);
            }
        }