30 using System.Collections;
31 using System.Collections.Generic;
32 using System.ComponentModel;
34 using System.Diagnostics;
37 using System.Text.RegularExpressions;
38 using System.Windows.Forms;
41 namespace LaunchSLClient
43 public partial class Form1 : Form
46 string sandboxUrl =
"";
53 private List<Grid> m_grids =
new List<Grid>();
57 InitializeComponent();
59 m_machineConfig = getMachineConfig();
60 m_machineConfig.GetClient(ref exePath, ref runLine, ref exeFlags);
64 ArrayList menuItems =
new ArrayList();
65 menuItems.Add(string.Empty);
67 addLocalSims(ref menuItems);
69 foreach (
Grid grid
in m_grids)
71 menuItems.Add(grid.Name +
" - " + grid.URL);
74 comboBox1.DataSource = menuItems;
79 if (Environment.OSVersion.Platform == PlatformID.Unix)
81 if (File.Exists(
"/System/Library/Frameworks/Cocoa.framework/Cocoa"))
87 return new UnixConfig();
92 return new WindowsConfig();
96 private void initializeGrids()
98 string iniFile =
"LaunchSLClient.ini";
100 if (!
File.Exists(iniFile))
103 IniConfigSource configSource =
new IniConfigSource(iniFile);
105 foreach (IConfig config
in configSource.Configs)
107 Grid grid =
new Grid();
109 grid.Name = config.Name;
110 grid.LoginURI = config.GetString(
"loginURI",
"");
111 grid.URL = config.GetString(
"URL",
"");
117 private void addLocalSandbox(ref ArrayList menuItems)
121 if (
File.Exists(
"Regions/default.xml"))
123 string sandboxHostName =
"";
124 string sandboxPort =
"";
127 Regex myRegex =
new Regex(
".*internal_ip_port=\\\"(?<port>.*?)\\\".*external_host_name=\\\"(?<name>.*?)\\\".*");
129 FileInfo defaultFile =
new FileInfo(
"Regions/default.xml");
130 StreamReader stream = defaultFile.OpenText();
133 text = stream.ReadLine();
138 MatchCollection theMatches = myRegex.Matches(text);
139 foreach (Match theMatch
in theMatches)
141 if (theMatch.Length != 0)
143 sandboxHostName = theMatch.Groups[
"name"].ToString();
144 sandboxPort = theMatch.Groups[
"port"].ToString();
147 }
while (text != null);
150 sandboxUrl =
"http:\\" + sandboxHostName +
":" + sandboxPort;
151 menuItems.Add(
"Local Sandbox");
155 private void addLocalGrid(ref ArrayList menuItems)
158 if (
File.Exists(
"network_servers_information.xml"))
161 FileInfo defaultFile =
new FileInfo(
"network_servers_information.xml");
162 Regex myRegex =
new Regex(
".*UserServerURL=\\\"(?<url>.*?)\\\".*");
163 StreamReader stream = defaultFile.OpenText();
167 text = stream.ReadLine();
172 foreach (Match theMatch
in myRegex.Matches(text))
174 if (theMatch.Length != 0)
176 gridUrl = theMatch.Groups[
"url"].ToString();
179 }
while (text != null);
183 menuItems.Add(
"Local Grid Server");
188 private void addLocalSims(ref ArrayList menuItems)
190 string configDir = m_machineConfig.GetConfigDir();
192 if (!
string.IsNullOrEmpty(configDir))
194 Directory.SetCurrentDirectory(configDir);
196 addLocalSandbox(ref menuItems);
197 addLocalGrid(ref menuItems);
201 private void comboBox1_SelectedIndexChanged(
object sender, EventArgs e)
203 if (comboBox1.Text ==
string.Empty)
207 else if (comboBox1.Text ==
"Local Sandbox")
209 runUrl=
" -loginuri " + sandboxUrl;
211 else if (comboBox1.Text ==
"Local Grid Server")
213 runUrl =
" -loginuri " + gridUrl;
217 foreach (Grid grid
in m_grids)
219 if (comboBox1.Text == grid.Name +
" - " + grid.URL)
221 if (grid.LoginURI !=
string.Empty)
222 runUrl =
" -loginuri " + grid.LoginURI;
231 comboBox1.DroppedDown =
false;
234 System.Diagnostics.Process proc =
new System.Diagnostics.Process();
235 proc.StartInfo.FileName = runLine;
236 proc.StartInfo.Arguments = exeFlags +
" " + runUrl;
237 proc.StartInfo.UseShellExecute =
false;
238 proc.StartInfo.RedirectStandardOutput =
false;
239 proc.StartInfo.WorkingDirectory = exePath;