예제 #1
0
        private static void RunInteractive(bool npsIsStandardOut)
        {
            OutputWriter.WriteLine("Reading data. Type '/' followed by a command to send. Press q key to exit.");
            CommandInterpreter interpreter = new CommandInterpreter(_dataReceiver);

            while (true)
            {
                bool exit = false;
                using var ms          = new MemoryStream();
                using var safeStream  = Stream.Synchronized(ms);
                using StreamWriter sw = new StreamWriter(safeStream);
                Stream oldNps = null;
                try
                {
                    var key = Console.ReadKey();
                    OutputWriter = sw;
                    //While we're doing this,
                    ErrorWriter = sw;
                    if (npsIsStandardOut && _dataReceiver is KissCommunication kisser)
                    {
                        oldNps = kisser.NonPacketStream;
                        kisser.NonPacketStream = safeStream;
                    }
                    interpreter.ProgrammerOutput = sw;
                    var line2 = Console.ReadLine();
                    var line  = key.KeyChar + line2;
                    if (!interpreter.HandleLine(line))
                    {
                        exit = true;
                        Console.WriteLine("Shutting Down...");
                        _dataReceiver.Disconnect();
                        _exitingSource.Cancel();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    if (exit)
                    {
                        throw;
                    }
                    else
                    {
                        Console.Error.WriteLine(ex.Message);
                    }
                }
                finally
                {
                    OutputWriter = Console.Out;
                    ErrorWriter  = Console.Error;
                    if (_dataReceiver is KissCommunication kisser)
                    {
                        kisser.NonPacketStream = oldNps;
                    }
                    interpreter.ProgrammerOutput = Console.Out;
                    sw.Flush();
                    Console.Write(sw.Encoding.GetString(ms.ToArray()));
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Stop Communicator to close communication medium
        /// </summary>
        public void StopCommunicator()
        {
            // Check for Null Reference
            if (_communicator != null)
            {
                // Check if the Communicator is currently active
                if (_communicator.IsConnected())
                {
                    // Stop Communication Server
                    _communicator.Disconnect();

                    return;
                }

                if (Logger.IsInfoEnabled)
                {
                    Logger.Info("Already disconnected", _type.FullName, "StopCommunicator");
                }
                return;
            }

            if (Logger.IsInfoEnabled)
            {
                Logger.Info("Communicator object not initialized", _type.FullName, "StopCommunicator");
            }
        }
 /// <summary>
 /// Stop Communicator to close communication medium
 /// </summary>
 public void StopCommunicator()
 {
     // Check for Null Reference
     if (_communicator != null)
     {
         // Check if the Communicator is currently active
         if (_communicator.IsConnected())
         {
             // Stop Communication Server
             _communicator.Disconnect();
         }
     }
 }
예제 #4
0
 public void Disconnect()
 {
     try
     {
         lock (Object)
         {
             if (_comm != null)
             {
                 _comm.Disconnect();
                 _comm = null;
             }
         }
     }
     catch
     {
         // もう終わるし、、、何もしない(◞‸◟)
     }
 }