From 7939974d921064d4316b5143e3eb45d3e99abf33 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 22 Oct 2019 11:55:27 +0100 Subject: [PATCH] try to fix console AGAIN --- OpenSim/Framework/Console/ConsoleBase.cs | 59 ++++++++++++++++++-- OpenSim/Framework/Console/LocalConsole.cs | 27 ++++++++- OpenSim/Framework/Console/MockConsole.cs | 2 +- OpenSim/Framework/Console/OpenSimAppender.cs | 4 +- OpenSim/Framework/Console/RemoteConsole.cs | 30 ++++++++-- OpenSim/Framework/IConsole.cs | 6 +- 6 files changed, 114 insertions(+), 14 deletions(-) diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs index 343958b1bc..f9dfb63a43 100755 --- a/OpenSim/Framework/Console/ConsoleBase.cs +++ b/OpenSim/Framework/Console/ConsoleBase.cs @@ -35,6 +35,32 @@ using log4net; namespace OpenSim.Framework.Console { + public class ConsoleLevel + { + public string m_string; + + ConsoleLevel(string v) + { + m_string = v; + } + + static public implicit operator ConsoleLevel(string s) + { + return new ConsoleLevel(s); + } + + public static string ToString(ConsoleLevel s) + { + return s.m_string; + } + + public override string ToString() + { + return m_string; + } + } + + public class ConsoleBase : IConsole { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -58,14 +84,39 @@ namespace OpenSim.Framework.Console { } - public void Output(string format, params object[] components) + public void Output(string format) { - Output(format, null, components); + System.Console.WriteLine(format); } - public virtual void Output(string format, string level, params object[] components) + public virtual void Output(string format, params object[] components) { - System.Console.WriteLine(format, components); + string level = null; + if (components != null && components.Length > 0) + { + if (components[0] == null || components[0] is ConsoleLevel) + { + if (components[0] is ConsoleLevel) + level = ((ConsoleLevel)components[0]).ToString(); + + if (components.Length > 1) + { + object[] tmp = new object[components.Length - 1]; + Array.Copy(components, 1, tmp, 0, components.Length - 1); + components = tmp; + } + else + components = null; + } + + } + string text; + if (components == null || components.Length == 0) + text = format; + else + text = String.Format(format, components); + + System.Console.WriteLine(text); } public string Prompt(string p) diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs index d19e244051..e1492b8830 100755 --- a/OpenSim/Framework/Console/LocalConsole.cs +++ b/OpenSim/Framework/Console/LocalConsole.cs @@ -389,9 +389,32 @@ namespace OpenSim.Framework.Console System.Console.WriteLine(); } - public override void Output(string format, string level, params object[] components) + public override void Output(string format, params object[] components) { - string text = String.Format(format, components); + string level = null; + if(components != null && components.Length > 0) + { + if(components[0] == null || components[0] is ConsoleLevel) + { + if(components[0] is ConsoleLevel) + level = ((ConsoleLevel)components[0]).ToString(); + + if (components.Length > 1) + { + object[] tmp = new object[components.Length - 1]; + Array.Copy(components, 1, tmp, 0, components.Length - 1); + components = tmp; + } + else + components = null; + } + + } + string text; + if (components == null || components.Length == 0) + text = format; + else + text = String.Format(format, components); FireOnOutput(text); diff --git a/OpenSim/Framework/Console/MockConsole.cs b/OpenSim/Framework/Console/MockConsole.cs index 291b7e9fd4..d314047a7d 100755 --- a/OpenSim/Framework/Console/MockConsole.cs +++ b/OpenSim/Framework/Console/MockConsole.cs @@ -62,8 +62,8 @@ namespace OpenSim.Framework.Console set {} } + public void Output(string format) { } public void Output(string format, params object[] components) { } - public void Output(string format, string level, params object[] components) { } public string Prompt(string p) { return ""; } public string Prompt(string p, string def) { return ""; } diff --git a/OpenSim/Framework/Console/OpenSimAppender.cs b/OpenSim/Framework/Console/OpenSimAppender.cs index 72a251e9b1..39a550b59f 100644 --- a/OpenSim/Framework/Console/OpenSimAppender.cs +++ b/OpenSim/Framework/Console/OpenSimAppender.cs @@ -55,12 +55,14 @@ namespace OpenSim.Framework.Console { if (m_console != null) { - string level = "normal"; + ConsoleLevel level; if (le.Level == Level.Error) level = "error"; else if (le.Level == Level.Warn) level = "warn"; + else + level = "normal"; m_console.Output(loggingMessage, level); } diff --git a/OpenSim/Framework/Console/RemoteConsole.cs b/OpenSim/Framework/Console/RemoteConsole.cs index 8dc7333b26..889df36fe9 100755 --- a/OpenSim/Framework/Console/RemoteConsole.cs +++ b/OpenSim/Framework/Console/RemoteConsole.cs @@ -190,12 +190,34 @@ namespace OpenSim.Framework.Console m_Server.AddHTTPHandler("/SessionCommand/", HandleHttpSessionCommand); } - public override void Output(string format, string level = null, params object[] components) + public override void Output(string format, params object[] components) { - if (components.Length == 0) - Output(format, level, false, false, false); + string level = null; + if (components != null && components.Length > 0) + { + if (components[0] == null || components[0] is ConsoleLevel) + { + if (components[0] is ConsoleLevel) + level = ((ConsoleLevel)components[0]).ToString(); + + if (components.Length > 1) + { + object[] tmp = new object[components.Length - 1]; + Array.Copy(components, 1, tmp, 0, components.Length - 1); + components = tmp; + } + else + components = null; + } + } + + string text; + if (components == null || components.Length == 0) + text = format; else - Output(String.Format(format, components), level, false, false, false); + text = String.Format(format, components); + + Output(text, level, false, false, false); } protected void Output(string text, string level, bool isPrompt, bool isCommand, bool isInput) diff --git a/OpenSim/Framework/IConsole.cs b/OpenSim/Framework/IConsole.cs index 36660f4b51..ef23cdcd8c 100755 --- a/OpenSim/Framework/IConsole.cs +++ b/OpenSim/Framework/IConsole.cs @@ -32,11 +32,13 @@ namespace OpenSim.Framework { public interface IConsole { + + IScene ConsoleScene { get; set; } + void Output(string format); void Output(string format, params object[] components); - void Output(string format, string level, params object[] components); - + string Prompt(string p); string Prompt(string p, string def); string Prompt(string p, List excludedCharacters);