protected void Output(string text, string level, bool isPrompt, bool isCommand, bool isInput) { if (level == null) { level = String.Empty; } // Increment the line number. It was 0 and they start at 1 // so we need to pre-increment. m_lineNumber++; // Create and populate the new entry. ScrollbackEntry newEntry = new ScrollbackEntry(); newEntry.lineNumber = m_lineNumber; newEntry.text = text; newEntry.level = level; newEntry.isPrompt = isPrompt; newEntry.isCommand = isCommand; newEntry.isInput = isInput; // Add a line to the scrollback. In some cases, that may not // actually be a line of text. lock (m_Scrollback) { // Prune the scrollback to the length se send as connect // burst to give the user some context. while (m_Scrollback.Count >= 1000) { m_Scrollback.RemoveAt(0); } m_Scrollback.Add(newEntry); } // Let the rest of the system know we have output something. FireOnOutput(text.Trim()); // Also display it for debugging. System.Console.WriteLine(text.Trim()); }
// Send all pending output to the client. protected Hashtable GetEvents(UUID RequestID, UUID sessionID) { // Find the connection that goes with this client. ConsoleConnection c = null; lock (m_Connections) { if (!m_Connections.ContainsKey(sessionID)) { return(NoEvents(RequestID, UUID.Zero)); } c = m_Connections[sessionID]; } // If we have nothing to send, send the no events response. c.last = System.Environment.TickCount; if (c.lastLineSeen >= m_lineNumber) { return(NoEvents(RequestID, UUID.Zero)); } Hashtable result = new Hashtable(); // Create the response document. XmlDocument xmldoc = new XmlDocument(); XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", ""); xmldoc.AppendChild(xmlnode); XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession", ""); //if (c.newConnection) //{ // c.newConnection = false; // Output("+++" + DefaultPrompt); //} lock (m_Scrollback) { long startLine = m_lineNumber - m_Scrollback.Count; long sendStart = startLine; if (sendStart < c.lastLineSeen) { sendStart = c.lastLineSeen; } for (long i = sendStart; i < m_lineNumber; i++) { ScrollbackEntry e = m_Scrollback[(int)(i - startLine)]; XmlElement res = xmldoc.CreateElement("", "Line", ""); res.SetAttribute("Number", e.lineNumber.ToString()); res.SetAttribute("Level", e.level); // Don't include these for the scrollback, we'll send the // real state later. if (!c.newConnection) { res.SetAttribute("Prompt", e.isPrompt ? "true" : "false"); res.SetAttribute("Command", e.isCommand ? "true" : "false"); res.SetAttribute("Input", e.isInput ? "true" : "false"); } else if (i == m_lineNumber - 1) // Last line for a new connection { res.SetAttribute("Prompt", m_expectingInput ? "true" : "false"); res.SetAttribute("Command", m_expectingCommand ? "true" : "false"); res.SetAttribute("Input", (!m_expectingInput) ? "true" : "false"); } else { res.SetAttribute("Input", e.isInput ? "true" : "false"); } res.AppendChild(xmldoc.CreateTextNode(e.text)); rootElement.AppendChild(res); } } c.lastLineSeen = m_lineNumber; c.newConnection = false; xmldoc.AppendChild(rootElement); result["str_response_string"] = xmldoc.InnerXml; result["int_response_code"] = 200; result["content_type"] = "application/xml"; result["keepalive"] = false; result = CheckOrigin(result); return(result); }