Esempio n. 1
0
		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("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();
			}
		}
Esempio n. 2
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 "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;

                            GestureDefinition gu = new GestureDefinition(new Gesture(newGesture.Item1, newGesture.Item2.Select(list => new PointPattern(list)).ToArray()), false);
                            gu.Show();
                            gu.Activate();
                        }
                    }, DispatcherPriority.Input);
                }
                return true;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        private void ReadThreadStart(NamedPipeServerStream decodePipe, Process encoder)
        {
            const int bufSize = 5 * 1024 * 1024;
            byte[] buffer = new byte[bufSize];

            if (!decodePipe.IsConnected)
                decodePipe.WaitForConnection();

            try
            {
                decodePipe.CopyTo(encoder.StandardInput.BaseStream);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }

            encoder.StandardInput.BaseStream.Close();
        }
Esempio n. 5
0
        public async Task<Stream> RunAsync(Stream output, string query, params string[] sqlArguments)
        {
            NamedPipeServerStream pipeServerStream = new NamedPipeServerStream("SqlBcpWrapper" + GetHashCode(), PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous);

            pipeServerStream.BeginWaitForConnection(e =>
            {
                pipeServerStream.EndWaitForConnection(e);

                while (pipeServerStream.IsConnected && !pipeServerStream.IsMessageComplete)
                {
                }

                pipeServerStream.CopyTo(output);
                output.Seek(0, SeekOrigin.Begin);
                pipeServerStream.Disconnect();
                pipeServerStream.Close();
            }, this);
            
            RunInternal("\\\\.\\pipe\\SqlBcpWrapper" + GetHashCode(), query, sqlArguments, null, null);

            await Task.Run(() =>
            {
                while (pipeServerStream.IsConnected && !pipeServerStream.IsMessageComplete)
                {
                }
            });

            return output;
        }