factor out common HandleShow code for "show uptime"
parent
d68ba391fc
commit
08234d0097
|
@ -702,7 +702,7 @@ namespace OpenSim.Framework.Console
|
|||
/// </summary>
|
||||
public void Prompt()
|
||||
{
|
||||
string line = ReadLine(m_defaultPrompt + "# ", true, true);
|
||||
string line = ReadLine(DefaultPrompt + "# ", true, true);
|
||||
|
||||
if (line != String.Empty)
|
||||
Output("Invalid command");
|
||||
|
|
|
@ -43,15 +43,7 @@ namespace OpenSim.Framework.Console
|
|||
|
||||
public object ConsoleScene { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The default prompt text.
|
||||
/// </summary>
|
||||
public string DefaultPrompt
|
||||
{
|
||||
set { m_defaultPrompt = value; }
|
||||
get { return m_defaultPrompt; }
|
||||
}
|
||||
protected string m_defaultPrompt;
|
||||
public string DefaultPrompt { get; set; }
|
||||
|
||||
public ConsoleBase(string defaultPrompt)
|
||||
{
|
||||
|
|
|
@ -44,13 +44,18 @@ namespace OpenSim.Framework.Console
|
|||
|
||||
public ICommands Commands { get { return m_commands; } }
|
||||
|
||||
public string DefaultPrompt { get; set; }
|
||||
|
||||
public void Prompt() {}
|
||||
|
||||
public void RunCommand(string cmd) {}
|
||||
|
||||
public string ReadLine(string p, bool isCommand, bool e) { return ""; }
|
||||
|
||||
public object ConsoleScene { get { return null; } }
|
||||
public object ConsoleScene {
|
||||
get { return null; }
|
||||
set {}
|
||||
}
|
||||
|
||||
public void Output(string text, string level) {}
|
||||
public void Output(string text) {}
|
||||
|
@ -76,4 +81,4 @@ namespace OpenSim.Framework.Console
|
|||
public string[] Resolve(string[] cmd) { return null; }
|
||||
public XmlElement GetXml(XmlDocument doc) { return null; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,11 @@ namespace OpenSim.Framework
|
|||
{
|
||||
ICommands Commands { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The default prompt text.
|
||||
/// </summary>
|
||||
string DefaultPrompt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Display a command prompt on the console and wait for user input
|
||||
/// </summary>
|
||||
|
@ -87,4 +92,4 @@ namespace OpenSim.Framework
|
|||
|
||||
string ReadLine(string p, bool isCommand, bool e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace OpenSim.Framework
|
|||
{
|
||||
public interface IConsole
|
||||
{
|
||||
object ConsoleScene { get; }
|
||||
object ConsoleScene { get; set; }
|
||||
|
||||
void Output(string text, string level);
|
||||
void Output(string text);
|
||||
|
|
|
@ -62,7 +62,6 @@ namespace OpenSim.Framework.Servers
|
|||
/// </summary>
|
||||
private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
|
||||
|
||||
protected CommandConsole m_console;
|
||||
protected OpenSimAppender m_consoleAppender;
|
||||
protected IAppender m_logFileAppender = null;
|
||||
|
||||
|
@ -139,7 +138,8 @@ namespace OpenSim.Framework.Servers
|
|||
}
|
||||
else
|
||||
{
|
||||
m_consoleAppender.Console = m_console;
|
||||
// FIXME: This should be done through an interface rather than casting.
|
||||
m_consoleAppender.Console = (ConsoleBase)m_console;
|
||||
|
||||
// If there is no threshold set then the threshold is effectively everything.
|
||||
if (null == m_consoleAppender.Threshold)
|
||||
|
@ -367,8 +367,10 @@ namespace OpenSim.Framework.Servers
|
|||
}
|
||||
}
|
||||
|
||||
public virtual void HandleShow(string module, string[] cmd)
|
||||
public override void HandleShow(string module, string[] cmd)
|
||||
{
|
||||
base.HandleShow(module, cmd);
|
||||
|
||||
List<string> args = new List<string>(cmd);
|
||||
|
||||
args.RemoveAt(0);
|
||||
|
@ -385,10 +387,6 @@ namespace OpenSim.Framework.Servers
|
|||
Notice(GetThreadsReport());
|
||||
break;
|
||||
|
||||
case "uptime":
|
||||
Notice(GetUptimeReport());
|
||||
break;
|
||||
|
||||
case "version":
|
||||
Notice(GetVersionText());
|
||||
break;
|
||||
|
@ -429,33 +427,6 @@ namespace OpenSim.Framework.Servers
|
|||
return String.Format("Version: {0} (interface version {1})", m_version, VersionInfo.MajorInterfaceVersion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Console output is only possible if a console has been established.
|
||||
/// That is something that cannot be determined within this class. So
|
||||
/// all attempts to use the console MUST be verified.
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
protected void Notice(string msg)
|
||||
{
|
||||
if (m_console != null)
|
||||
{
|
||||
m_console.Output(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Console output is only possible if a console has been established.
|
||||
/// That is something that cannot be determined within this class. So
|
||||
/// all attempts to use the console MUST be verified.
|
||||
/// </summary>
|
||||
/// <param name="format"></param>
|
||||
/// <param name="components"></param>
|
||||
protected void Notice(string format, params string[] components)
|
||||
{
|
||||
if (m_console != null)
|
||||
m_console.OutputFormat(format, components);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enhance the version string with extra information if it's available.
|
||||
/// </summary>
|
||||
|
|
|
@ -26,12 +26,19 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OpenSim.Framework.Console;
|
||||
|
||||
namespace OpenSim.Framework.Servers
|
||||
{
|
||||
public class ServerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Console to be used for any command line output. Can be null, in which case there should be no output.
|
||||
/// </summary>
|
||||
protected ICommandConsole m_console;
|
||||
|
||||
/// <summary>
|
||||
/// Time at which this server was started
|
||||
/// </summary>
|
||||
|
@ -42,6 +49,22 @@ namespace OpenSim.Framework.Servers
|
|||
m_startuptime = DateTime.Now;
|
||||
}
|
||||
|
||||
public virtual void HandleShow(string module, string[] cmd)
|
||||
{
|
||||
List<string> args = new List<string>(cmd);
|
||||
|
||||
args.RemoveAt(0);
|
||||
|
||||
string[] showParams = args.ToArray();
|
||||
|
||||
switch (showParams[0])
|
||||
{
|
||||
case "uptime":
|
||||
Notice(GetUptimeReport());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a report about the uptime of this server
|
||||
/// </summary>
|
||||
|
@ -54,5 +77,32 @@ namespace OpenSim.Framework.Servers
|
|||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Console output is only possible if a console has been established.
|
||||
/// That is something that cannot be determined within this class. So
|
||||
/// all attempts to use the console MUST be verified.
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
protected void Notice(string msg)
|
||||
{
|
||||
if (m_console != null)
|
||||
{
|
||||
m_console.Output(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Console output is only possible if a console has been established.
|
||||
/// That is something that cannot be determined within this class. So
|
||||
/// all attempts to use the console MUST be verified.
|
||||
/// </summary>
|
||||
/// <param name="format"></param>
|
||||
/// <param name="components"></param>
|
||||
protected void Notice(string format, params string[] components)
|
||||
{
|
||||
if (m_console != null)
|
||||
m_console.OutputFormat(format, components);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -253,7 +253,7 @@ namespace OpenSim
|
|||
}
|
||||
}
|
||||
|
||||
protected virtual void AddPluginCommands(CommandConsole console)
|
||||
protected virtual void AddPluginCommands(ICommandConsole console)
|
||||
{
|
||||
List<string> topics = GetHelpTopics();
|
||||
|
||||
|
|
|
@ -174,6 +174,8 @@ namespace OpenSim.Server.Base
|
|||
MainConsole.Instance = new LocalConsole(prompt);
|
||||
}
|
||||
|
||||
m_console = MainConsole.Instance;
|
||||
|
||||
// Configure the appenders for log4net
|
||||
//
|
||||
OpenSimAppender consoleAppender = null;
|
||||
|
@ -351,21 +353,5 @@ namespace OpenSim.Server.Base
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void HandleShow(string module, string[] cmd)
|
||||
{
|
||||
List<string> args = new List<string>(cmd);
|
||||
|
||||
args.RemoveAt(0);
|
||||
|
||||
string[] showParams = args.ToArray();
|
||||
|
||||
switch (showParams[0])
|
||||
{
|
||||
case "uptime":
|
||||
MainConsole.Instance.Output(GetUptimeReport());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue