Beispiel #1
0
        /// <summary>
        /// Send a drag and drop message to the named pipe.
        /// Write a drag and drop message out to the pipe.
        /// Todo: add abstraction, handle more operators.
        /// </summary>
        public string sendMessage(IMessage message)
        {
            string reply = "";
            lock (_sync)
            {
                if (!_isLocked)
                {
                    try
                    {
                        sw.WriteLine(message.Construct());
                        sw.Flush();
                        _server.WaitForPipeDrain();

                        reply = sr.ReadLine();
                        _server.WaitForPipeDrain();

                    }
                    catch (IOException ex)
                    {
                        //Catch broken pipe exception
                        System.Diagnostics.Debug.WriteLine("Broken Pipe" + ex.ToString());
                        //Lock the server, a new pipe must be used.
                        _isLocked = true;
                    }
                    catch (Exception ex)
                    {
                        //Catch other (unexpected) exceptions
                        System.Diagnostics.Debug.WriteLine("Unknown pipe error" + ex.ToString());
                        //Lock the server, a new pipe (probably) must be used.
                        _isLocked = true;
                    }
                }
                return reply;
            }
        }