aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/OpenSim.GridLaunch/GUI/WinForm/ProcessPanel.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Tools/OpenSim.GridLaunch/GUI/WinForm/ProcessPanel.cs288
1 files changed, 288 insertions, 0 deletions
diff --git a/OpenSim/Tools/OpenSim.GridLaunch/GUI/WinForm/ProcessPanel.cs b/OpenSim/Tools/OpenSim.GridLaunch/GUI/WinForm/ProcessPanel.cs
new file mode 100644
index 0000000..dbf97d6
--- /dev/null
+++ b/OpenSim/Tools/OpenSim.GridLaunch/GUI/WinForm/ProcessPanel.cs
@@ -0,0 +1,288 @@
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.ComponentModel;
30using System.Data;
31using System.Diagnostics;
32using System.Drawing;
33using System.Text;
34using System.Windows.Forms;
35
36namespace OpenSim.GridLaunch.GUI.WinForm
37{
38 public partial class ProcessPanel : Form, IGUI
39 {
40 public ProcessPanel()
41 {
42 Application.EnableVisualStyles();
43 //Application.SetCompatibleTextRenderingDefault(false);
44
45 InitializeComponent();
46 Program.AppCreated += Program_AppCreated;
47 Program.AppRemoved += Program_AppRemoved;
48 Program.AppConsoleOutput += Program_AppConsoleOutput;
49 Program.AppConsoleError += Program_AppConsoleError;
50 log4netAppender.LogLine += log4netAppender_LogLine;
51 }
52
53 #region Module Start / Stop
54 public void StartGUI()
55 {
56 Application.Run(this);
57 }
58
59 public void StopGUI()
60 {
61 this.Close();
62 }
63 #endregion
64
65 #region Main log tab
66 void log4netAppender_LogLine(Color color, string LogText)
67 {
68 ucLogWindow1.Write(color, LogText);
69 }
70 #endregion
71
72 #region Form events
73 private void btnShutdown_Click(object sender, EventArgs e)
74 {
75 Program.Shutdown();
76 }
77 #endregion
78
79 #region GridLaunch Events
80 public delegate void Program_AppCreatedDelegate(string App);
81 public void Program_AppCreated(string App)
82 {
83 if (this.InvokeRequired) {
84 this.Invoke(new Program_AppCreatedDelegate(Program_AppCreated), App);
85 return;
86 }
87
88 Trace.WriteLine("Start: " + App);
89
90 // Do we already have app window for that app?
91 if (AppWindow_Get(App) != null)
92 return;
93
94 // New log window
95 ucAppWindow aw = new ucAppWindow();
96 // New tab page
97 TabPage tp = new TabPage(App);
98 // Add log window into tab page
99 tp.Controls.Add(aw);
100 // Add tab page into tab control
101 tabControl1.TabPages.Add(tp);
102 // Add it all to our internal list
103 AppWindow_Add(App, aw);
104 // Hook up events
105 aw.LineEntered += AppWindow_LineEntered;
106
107 // Fill log window fully inside tab page
108 aw.Dock = DockStyle.Fill;
109 }
110
111
112 public delegate void Program_AppRemovedDelegate(string App);
113 public void Program_AppRemoved(string App)
114 {
115 if (this.InvokeRequired) {
116 this.Invoke(new Program_AppRemovedDelegate(Program_AppRemoved), App);
117 return;
118 }
119
120 Trace.WriteLine("Stop: " + App);
121
122 // Get app window
123 ucAppWindow aw = AppWindow_Get(App);
124 if (aw == null)
125 return;
126
127 // Get its tab page
128 TabPage tp = aw.Parent as TabPage;
129
130 if (tp != null)
131 {
132 // Remove tab page from tab control
133 tabControl1.TabPages.Remove(tp);
134 // Remove app window from tab
135 tp.Controls.Remove(aw);
136 }
137
138 // Dispose of app window
139 aw.Dispose();
140
141 // Dispose of tab page
142 if (tp != null)
143 tp.Dispose();
144
145 // Remove from our internal list
146 AppWindow_Remove(App);
147 }
148
149
150 public delegate void Program_AppConsoleOutputDelegate(string App, string LogText);
151 void Program_AppConsoleOutput(string App, string LogText)
152 {
153 if (this.InvokeRequired)
154 {
155 this.Invoke(new Program_AppConsoleOutputDelegate(Program_AppConsoleOutput), App, LogText);
156 return;
157 }
158
159 // Get app window
160 ucAppWindow aw = AppWindow_Get(App);
161 // Write text to it
162 if (aw != null)
163 aw.Write(System.Drawing.Color.Black, LogText);
164 }
165
166 public delegate void Program_AppConsoleErrorDelegate(string App, string LogText);
167 void Program_AppConsoleError(string App, string LogText)
168 {
169 if (this.InvokeRequired) {
170 this.Invoke(new Program_AppConsoleErrorDelegate(Program_AppConsoleError), App, LogText);
171 return;
172 }
173
174 // Get app window
175 ucAppWindow aw = AppWindow_Get(App);
176 // Write text to it
177 if (aw != null)
178 aw.Write(System.Drawing.Color.Red, LogText);
179
180 }
181 #endregion
182
183 #region App Window events
184 private void AppWindow_LineEntered(ucAppWindow AppWindow, string LogText)
185 {
186 Program.WriteLine(AppWindow_Get(AppWindow), LogText);
187 }
188 #endregion
189
190 private void ProcessPanel_Load(object sender, EventArgs e)
191 {
192 string[] arr = new string[Program.Settings.Components.Keys.Count];
193 Program.Settings.Components.Keys.CopyTo(arr, 0);
194 cblStartupComponents.Items.AddRange(arr);
195
196 // Now correct all check states
197 for (int i = 0; i < cblStartupComponents.Items.Count; i++ )
198 {
199 string _name = cblStartupComponents.Items[i] as string;
200 bool _checked = Program.Settings.Components[_name];
201
202 cblStartupComponents.SetItemChecked(i, _checked);
203 }
204
205
206 }
207
208
209
210
211 #region Internal App Window list and functions
212 private Dictionary<string, ucAppWindow> _appWindows = new Dictionary<string, ucAppWindow>();
213 private Dictionary<ucAppWindow, string> _appWindows_rev = new Dictionary<ucAppWindow, string>();
214 private void AppWindow_Add(string AppWindowName, ucAppWindow AppWindow)
215 {
216 lock (_appWindows)
217 {
218 _appWindows.Add(AppWindowName, AppWindow);
219 _appWindows_rev.Add(AppWindow, AppWindowName);
220 // Hook events
221 AppWindow.LineEntered += AppWindow_LineEntered;
222 }
223 }
224 private void AppWindow_Remove(ucAppWindow AppWindow)
225 {
226 lock (_appWindows)
227 {
228 if (_appWindows_rev.ContainsKey(AppWindow))
229 {
230 // Unhook events
231 AppWindow.LineEntered -= AppWindow_LineEntered;
232 // Delete from list
233 string name = _appWindows_rev[AppWindow];
234 _appWindows.Remove(name);
235 _appWindows_rev.Remove(AppWindow);
236 }
237 }
238 }
239 private void AppWindow_Remove(string AppWindowName)
240 {
241 lock (_appWindows)
242 {
243 if (_appWindows.ContainsKey(AppWindowName))
244 {
245 ucAppWindow AppWindow = _appWindows[AppWindowName];
246 // Unhook events
247 AppWindow.LineEntered -= AppWindow_LineEntered;
248 // Delete from list
249 _appWindows.Remove(AppWindowName);
250 _appWindows_rev.Remove(AppWindow);
251 }
252 }
253 }
254 private string AppWindow_Get(ucAppWindow AppWindow)
255 {
256 lock (_appWindows)
257 {
258 if (_appWindows_rev.ContainsKey(AppWindow))
259 return _appWindows_rev[AppWindow];
260 }
261 return null;
262 }
263 private ucAppWindow AppWindow_Get(string AppWindowName)
264 {
265 lock (_appWindows)
266 {
267 if (_appWindows.ContainsKey(AppWindowName))
268 return _appWindows[AppWindowName];
269 }
270 return null;
271 }
272 #endregion
273
274 private void btnSave_Click(object sender, EventArgs e)
275 {
276 Program.Settings.Components.Clear();
277 for (int i = 0; i < cblStartupComponents.Items.Count; i++)
278 {
279 string _name = cblStartupComponents.Items[i] as string;
280 bool _checked = cblStartupComponents.GetItemChecked(i);
281
282 Program.Settings.Components.Add(_name, _checked);
283 Program.Settings.SaveConfig();
284 }
285 }
286
287 }
288}