aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/OpenSim.GridLaunch/GUI/Console/Console.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tools/OpenSim.GridLaunch/GUI/Console/Console.cs')
-rw-r--r--OpenSim/Tools/OpenSim.GridLaunch/GUI/Console/Console.cs122
1 files changed, 122 insertions, 0 deletions
diff --git a/OpenSim/Tools/OpenSim.GridLaunch/GUI/Console/Console.cs b/OpenSim/Tools/OpenSim.GridLaunch/GUI/Console/Console.cs
new file mode 100644
index 0000000..a04c9cf
--- /dev/null
+++ b/OpenSim/Tools/OpenSim.GridLaunch/GUI/Console/Console.cs
@@ -0,0 +1,122 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.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 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30
31namespace OpenSim.GridLaunch.GUI.Console
32{
33 internal class Console: IGUI
34 {
35 private List<string> Apps = new List<string>();
36 public Console ()
37 {
38 Program.AppCreated += Program_AppCreated;
39 Program.AppRemoved += Program_AppRemoved;
40 Program.AppConsoleOutput += Program_AppConsoleOutput;
41 Program.Command.CommandLine += Command_CommandLine;
42 }
43
44 private string currentApp = "";
45 private bool quitTyped = false;
46 void Command_CommandLine(string application, string command, string arguments)
47 {
48
49 // If command is a number then someone might be trying to change console: /1, /2, etc.
50 int currentAppNum = 0;
51 if (int.TryParse(command, out currentAppNum))
52 if (currentAppNum <= Apps.Count)
53 {
54 currentApp = Apps[currentAppNum - 1];
55 System.Console.WriteLine("Changed console to app: " + currentApp);
56 } else
57 System.Console.WriteLine("Unable to change to app number: " + currentAppNum);
58
59 // Has user typed quit?
60 if (command.ToLower() == "quit")
61 quitTyped = true;
62
63 // Has user typed /list?
64 if (command.ToLower() == "list")
65 {
66 System.Console.WriteLine("/0 Log console");
67 for (int i = 1; i <= Apps.Count; i++)
68 {
69 System.Console.WriteLine(string.Format("/{0} {1}", i, Apps[i - 1]));
70 }
71 }
72 }
73 #region Module Start / Stop
74 public void StartGUI()
75 {
76 // Console start
77 System.Console.WriteLine("Console GUI");
78 System.Console.WriteLine("Use commands /0, /1, /2, etc to switch between applications.");
79 System.Console.WriteLine("Type /list for list of applications.");
80 System.Console.WriteLine("Anything that doesn't start with a / will be sent to selected application");
81 System.Console.WriteLine("type /quit to exit");
82
83
84 while (quitTyped == false)
85 {
86 string line = System.Console.ReadLine().TrimEnd("\r\n".ToCharArray());
87 Program.Write(currentApp, line);
88 }
89 // We are done
90 System.Console.WriteLine("Console exit.");
91 }
92
93 public void StopGUI()
94 {
95 // Console stop
96 }
97 #endregion
98
99 #region GridLaunch Events
100 void Program_AppCreated(string App)
101 {
102 System.Console.WriteLine("Started: " + App);
103 if (!Apps.Contains(App))
104 Apps.Add(App);
105 }
106
107 void Program_AppRemoved(string App)
108 {
109 System.Console.WriteLine("Stopped: " + App);
110 if (Apps.Contains(App))
111 Apps.Remove(App);
112 }
113
114 void Program_AppConsoleOutput(string App, string Text)
115 {
116 System.Console.Write(App + ": " + Text);
117 }
118 #endregion
119
120
121 }
122}