예제 #1
0
        static private void ThreadMain()
        {
            while (true)
            {
                m_startEvent.WaitOne();
                CommandThread cmd = null;

                try
                {
                    m_queueLock.WaitOne();
                    cmd = m_commandQueue.Dequeue();
                }
                finally
                {
                    m_queueLock.ReleaseMutex();
                }

                try
                {
                    System.Threading.Thread thread = new System.Threading.Thread(new ThreadStart(cmd.Run));
                    thread.Start();
                }
                catch
                {
                }
            }
        }
        public static bool Schedule(OutputWindowPane output, string executable, string commandline, string workingdir, OnDone callback, object callbackArg, int timeout)
		{
			CommandThread cmd = new CommandThread();
			cmd.output = output;
			cmd.executable = executable;
			cmd.commandline = commandline;
			cmd.workingdir = workingdir;
            cmd.callback = callback;
            cmd.callbackArg = callbackArg;
            cmd.timeout = timeout;

			try
			{
				m_queueLock.WaitOne();
				m_commandQueue.Enqueue(cmd);
			}
			finally
			{
				m_queueLock.ReleaseMutex();
			}

			m_startEvent.Release();
			Log.Debug("Scheduled {0} {1}\n", cmd.executable, cmd.commandline);
			return true;
		}
        // --------------------------------- RunCommand ------------------------------
        public virtual string[] RunCommand(
            CommandThread InCmdThread,
            ReadBuffer InReadBuffer,
            delWriteEventLog InWriteEventLog,
            string InCmdText)
        {
            StringBuilder accumRead = new StringBuilder();

            string[] lines = null;

            // send command to the telnet server.
            if (InCmdThread.ShutdownFlag.State == false)
            {
                if (InWriteEventLog != null)
                {
                    InWriteEventLog(null, "exit", "Logout");
                }
                InCmdThread.Conn.WriteLine(InCmdText);
            }

            // read back whatever is in the read buffer.
            if (InCmdThread.ShutdownFlag.State == false)
            {
                lines = InReadBuffer.ReadUntilEndsWith(CommandPromptPatterns);
                ThreadCommon.WriteToEventLog(InWriteEventLog, lines, "Run");
            }

            // return all the response line received from the server.
            return(lines);
        }
예제 #4
0
        public static bool Schedule(OutputWindowPane output, string executable, string commandline, string workingdir, OnDone callback, object callbackArg, int timeout)
        {
            CommandThread cmd = new CommandThread();

            cmd.output      = output;
            cmd.executable  = executable;
            cmd.commandline = commandline;
            cmd.workingdir  = workingdir;
            cmd.callback    = callback;
            cmd.callbackArg = callbackArg;
            cmd.timeout     = timeout;

            try
            {
                m_queueLock.WaitOne();
                m_commandQueue.Enqueue(cmd);
            }
            finally
            {
                m_queueLock.ReleaseMutex();
            }

            m_startEvent.Release();
            Log.Info("Scheduled {0} {1}\n", cmd.executable, cmd.commandline);
            return(true);
        }
        // --------------------------------- Logout ------------------------------
        public virtual string[] Logout(
            CommandThread InCmdThread,
            ReadBuffer InReadBuffer,
            delWriteEventLog InWriteEventLog,
            string InNullText)
        {
            StringBuilder accumRead = new StringBuilder();

            string[] lines = null;

            if (InCmdThread.Conn.IsConnected == false)
            {
                InCmdThread.ShutdownFlag.Set();
            }

            // send "exit" command to the telnet server.
            if (InCmdThread.ShutdownFlag.State == false)
            {
                if (InWriteEventLog != null)
                {
                    InWriteEventLog(null, "exit", "Logout");
                }
                try
                {
                    InCmdThread.Conn.WriteLine("exit");
                }
                catch (NotConnectedException)
                {
                    InCmdThread.ShutdownFlag.Set();
                }
            }

            // read back whatever is in the read buffer.
            if (InCmdThread.ShutdownFlag.State == false)
            {
                lines = InReadBuffer.Read();
                ThreadCommon.WriteToEventLog(InWriteEventLog, lines, "Logout");
            }

            // wait for the "socket is disconnected" signal.
            int waitDur = 5000;

            while (true)
            {
                bool rc = InCmdThread.Conn.IsDisconnectedSignal.WaitOne(waitDur);
                if (rc == true)
                {
                    break;
                }
                if (waitDur < 3600000)
                {
                    waitDur *= 2;
                }
                InWriteEventLog(null,
                                "waiting for telnet server to disconnect after exit", "Logout");
            }

            // return all the response line received from the server.
            return(lines);
        }
예제 #6
0
        public static bool Schedule(string executable, string commandline, string workingdir, OnDone callback, object callbackArg, int timeout)
        {
            var cmd = new CommandThread
            {
                executable  = executable,
                commandline = commandline,
                workingdir  = workingdir,
                callback    = callback,
                callbackArg = callbackArg,
                timeout     = timeout
            };

            try
            {
                m_queueLock.WaitOne();
                m_commandQueue.Enqueue(cmd);
            }
            finally
            {
                m_queueLock.ReleaseMutex();
            }

            m_startEvent.Release();
            Log.Info("Scheduled {0} {1}\n", cmd.executable, cmd.commandline);
            return(true);
        }
예제 #7
0
 public MainForm()
 {
     InitializeComponent();
     random        = new Random();
     commandThread = CommandThread.getInstance();
     timer100      = new System.Threading.Timer(TimerTick100, this, 1000, 100);
 }
예제 #8
0
 /// <summary>
 /// The constructor for a message router.
 /// </summary>
 /// <param name="engine">The engine.</param>
 public MessageRouter(Rete.Rete engine)
 {
     InitBlock();
     this.engine = engine;
     interpreter = new CLIPSInterpreter(engine);
     commandThread = new CommandThread(this);
     commandThread.Start();
 }
예제 #9
0
 public static CommandThread getInstance()
 {
     if (self == null)
     {
         self = new CommandThread();
     }
     return(self);
 }
예제 #10
0
 /// <summary>
 /// The constructor for a message router.
 /// </summary>
 /// <param name="engine">The engine.</param>
 public MessageRouter(Rete.Rete engine)
 {
     InitBlock();
     this.engine   = engine;
     interpreter   = new CLIPSInterpreter(engine);
     commandThread = new CommandThread(this);
     commandThread.Start();
 }
        // --------------------------------- Login ------------------------------
        public virtual string[] Login(
            CommandThread InCmdThread,
            ReadBuffer InReadBuffer,
            delWriteEventLog InWriteEventLog,
            string InNullText)
        {
            StringBuilder accumRead = new StringBuilder();

            string[] lines        = null;
            string[] loginPrompts = new string[] { ":" };

            // telnet server sends a login prompt. read until it arrives.
            if (InCmdThread.ShutdownFlag.State == false)
            {
                if (InWriteEventLog != null)
                {
                    InWriteEventLog(null, "Read login prompt ...", "Login");
                }
                lines = InReadBuffer.ReadUntilEndsWith(loginPrompts);
                ThreadCommon.WriteToEventLog(InWriteEventLog, lines, "Login");
            }

            // send username to the telnet server.
            if (InCmdThread.ShutdownFlag.State == false)
            {
                if (InWriteEventLog != null)
                {
                    InWriteEventLog(null, "Username " + mLoginProperties.LoginUser, "Login");
                }
                InCmdThread.Conn.WriteLine(mLoginProperties.LoginUser);
            }

            // read back the prompt for password.
            if (InCmdThread.ShutdownFlag.State == false)
            {
                if (InWriteEventLog != null)
                {
                    InWriteEventLog(null, "Read password prompt ...", "Login");
                }
                lines = InReadBuffer.ReadUntilEndsWith(loginPrompts);
                ThreadCommon.WriteToEventLog(InWriteEventLog, lines, "Login");
            }

            // send password to telnet server.
            if (InCmdThread.ShutdownFlag.State == false)
            {
                if (InWriteEventLog != null)
                {
                    InWriteEventLog(null, "Password ********", "Login");
                }
                InCmdThread.Conn.WriteLine(mLoginProperties.LoginPass);
            }

            // read back until the logged in command prompt.
            if (InCmdThread.ShutdownFlag.State == false)
            {
                if (InWriteEventLog != null)
                {
                    InWriteEventLog(null, "Read command prompt ...", "Login");
                }


                while (true)
                {
                    string[] xx = null;
                    xx = InReadBuffer.Read();
                    ThreadCommon.WriteToEventLog(InWriteEventLog, xx, "Login");
                    string lastLine = Arrayer.LastItem(xx);
                    if (lastLine != null)
                    {
                        string trimLastLine = lastLine.TrimEnd(new char[] { ' ', '\t', '\r', '\n' });
                        string lsChar       = StringExt.Tail(trimLastLine, 1);
                        if (lsChar == ">")
                        {
                            break;
                        }
                    }
                }
            }

            // return all the response line received from the server.
            return(lines);
        }