aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common/OpenSim.Framework.Console/ConsoleBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Common/OpenSim.Framework.Console/ConsoleBase.cs')
-rw-r--r--Common/OpenSim.Framework.Console/ConsoleBase.cs220
1 files changed, 0 insertions, 220 deletions
diff --git a/Common/OpenSim.Framework.Console/ConsoleBase.cs b/Common/OpenSim.Framework.Console/ConsoleBase.cs
deleted file mode 100644
index 30854fe..0000000
--- a/Common/OpenSim.Framework.Console/ConsoleBase.cs
+++ /dev/null
@@ -1,220 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.IO;
30
31namespace OpenSim.Framework.Console
32{
33 public enum LogPriority : int
34 {
35 CRITICAL,
36 HIGH,
37 MEDIUM,
38 NORMAL,
39 LOW,
40 VERBOSE,
41 EXTRAVERBOSE
42 }
43
44 public class ConsoleBase
45 {
46 StreamWriter Log;
47 public conscmd_callback cmdparser;
48 public string componentname;
49 private bool m_silent;
50
51 public ConsoleBase(string LogFile, string componentname, conscmd_callback cmdparser, bool silent )
52 {
53 this.componentname = componentname;
54 this.cmdparser = cmdparser;
55 this.m_silent = silent;
56 System.Console.WriteLine("ServerConsole.cs - creating new local console");
57 System.Console.WriteLine("Logs will be saved to current directory in " + LogFile);
58 Log = File.AppendText(LogFile);
59 Log.WriteLine("========================================================================");
60 Log.WriteLine(componentname + " Started at " + DateTime.Now.ToString());
61 }
62
63 public void Close()
64 {
65 Log.WriteLine("Shutdown at " + DateTime.Now.ToString());
66 Log.Close();
67 }
68
69 public void Write(string format, params object[] args)
70 {
71 Notice(format,args);
72 return;
73 }
74
75 public void Warn(string format, params object[] args)
76 {
77 WriteNewLine(ConsoleColor.Yellow, format, args);
78 return;
79 }
80
81 public void Notice(string format, params object[] args)
82 {
83 WriteNewLine(ConsoleColor.White, format, args);
84 return;
85 }
86
87 public void Error(string format, params object[] args)
88 {
89 WriteNewLine(ConsoleColor.Red, format, args);
90 return;
91 }
92
93 public void Verbose(string format, params object[] args)
94 {
95 WriteNewLine(ConsoleColor.Gray, format, args);
96 return;
97 }
98
99 public void Status(string format, params object[] args)
100 {
101 WriteNewLine(ConsoleColor.Blue, format, args);
102 return;
103 }
104
105 private void WriteNewLine(System.ConsoleColor color, string format, params object[] args)
106 {
107 Log.WriteLine(format, args);
108 Log.Flush();
109 if (!m_silent)
110 {
111 try
112 {
113 System.Console.ForegroundColor = color;
114 System.Console.WriteLine(format, args);
115 System.Console.ResetColor();
116 } // Because mono and old debian sucks.
117 catch (System.ArgumentNullException)
118 {
119 System.Console.WriteLine(format, args);
120 }
121 }
122 return;
123 }
124
125 public string ReadLine()
126 {
127 string TempStr = System.Console.ReadLine();
128 Log.WriteLine(TempStr);
129 return TempStr;
130 }
131
132 public int Read()
133 {
134 int TempInt = System.Console.Read();
135 Log.Write((char)TempInt);
136 return TempInt;
137 }
138
139 // Displays a prompt and waits for the user to enter a string, then returns that string
140 // Done with no echo and suitable for passwords
141 public string PasswdPrompt(string prompt)
142 {
143 // FIXME: Needs to be better abstracted
144 Log.WriteLine(prompt);
145 this.Write(prompt);
146 ConsoleColor oldfg = System.Console.ForegroundColor;
147 System.Console.ForegroundColor = System.Console.BackgroundColor;
148 string temp = System.Console.ReadLine();
149 System.Console.ForegroundColor = oldfg;
150 return temp;
151 }
152
153 // Displays a command prompt and waits for the user to enter a string, then returns that string
154 public string CmdPrompt(string prompt)
155 {
156 this.Write(String.Format("{0}: ", prompt));
157 return this.ReadLine();
158 }
159
160 // Displays a command prompt and returns a default value if the user simply presses enter
161 public string CmdPrompt(string prompt, string defaultresponse)
162 {
163 string temp = CmdPrompt(String.Format( "{0} [{1}]", prompt, defaultresponse ));
164 if (temp == "")
165 {
166 return defaultresponse;
167 }
168 else
169 {
170 return temp;
171 }
172 }
173
174 // Displays a command prompt and returns a default value, user may only enter 1 of 2 options
175 public string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB)
176 {
177 bool itisdone = false;
178 string temp = CmdPrompt(prompt, defaultresponse);
179 while (itisdone == false)
180 {
181 if ((temp == OptionA) || (temp == OptionB))
182 {
183 itisdone = true;
184 }
185 else
186 {
187 Notice("Valid options are " + OptionA + " or " + OptionB);
188 temp = CmdPrompt(prompt, defaultresponse);
189 }
190 }
191 return temp;
192 }
193
194 // Runs a command with a number of parameters
195 public Object RunCmd(string Cmd, string[] cmdparams)
196 {
197 cmdparser.RunCmd(Cmd, cmdparams);
198 return null;
199 }
200
201 // Shows data about something
202 public void ShowCommands(string ShowWhat)
203 {
204 cmdparser.Show(ShowWhat);
205 }
206
207 public void MainConsolePrompt()
208 {
209 string[] tempstrarray;
210 string tempstr = this.CmdPrompt(this.componentname + "# ");
211 tempstrarray = tempstr.Split(' ');
212 string cmd = tempstrarray[0];
213 Array.Reverse(tempstrarray);
214 Array.Resize<string>(ref tempstrarray, tempstrarray.Length - 1);
215 Array.Reverse(tempstrarray);
216 string[] cmdparams = (string[])tempstrarray;
217 RunCmd(cmd, cmdparams);
218 }
219 }
220}