private void InitRunStyles() { // populate run styles RunStyles.Add(new RunStyle("Run Query", RunStyleIcons.RunOnly, false, false, false, "Executes the query and sends the results to the selected output")); RunStyles.Add(new RunStyle("Clear Cache then Run", RunStyleIcons.ClearThenRun, true,false,false, "Clears the database cache, then executes the query and sends the results to the selected output")); #if DEBUG // RunStyles.Add(new RunStyle("Benchmark", RunStyleIcons.RunBenchmark, false, false, false, "Executes the query multiple times and captures the timings")); //RunStyles.Add(new RunStyle("Run Table Function", RunStyleIcons.RunFunction, true, true,false, "Attempts to executes the selected function by inserting 'EVALUATE' in front of it and sends the results to the selected output")); //RunStyles.Add(new RunStyle("Run Measure", RunStyleIcons.RunScalar, true, true, true, "Attempts to executes the selected measure or scalar function by wrapping the selection with 'EVALUATE ROW(...)' and sends the results to the selected output")); #endif // set default run style var defaultRunStyle = RunStyleIcons.RunOnly; if (Options.SetClearCacheAsDefaultRunStyle) defaultRunStyle = RunStyleIcons.ClearThenRun; SelectedRunStyle = RunStyles.FirstOrDefault(rs => rs.Icon == defaultRunStyle); }
static void Main(string[] args) { _commandArgs = args; new TAppSettingsManager(false); // Read the default working parameters using TAppSettings. If a config file exists, the settings in the file will be used. CommandLineArgs commandLineArgs = new CommandLineArgs(); // Read the actual command line for any further over-rides commandLineArgs.ParseCommandLine(args); CreateLog(commandLineArgs); _RunStyle = RunStyles.None; if (commandLineArgs.UseFullUI) { TLogging.Log("Using the full UI"); // Find out if there is an existing instance Process curProcess = Process.GetCurrentProcess(); Process[] RunningProcesses = System.Diagnostics.Process.GetProcessesByName(curProcess.ProcessName); if (RunningProcesses.Length == 1) { // This is the only running process of our name FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Application.ExecutablePath); _Version = fvi.FileVersion; _ApplicationTitleAndVersion += ("(" + _Version + ")"); _ConfigFilePath += @"\OM_International\OpenPetraWebServer.cfg.xml"; _RunStyle = RunStyles.FullUI; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); myForm = new MainForm(); Application.Run(myForm); } else { // There must be another window in the tray IntPtr hWnd = FindWindow(null, APPLICATION_TITLE); if (hWnd != null) { // We need to activate the other app SendMessage(hWnd, UM_ACTIVATE_APP, IntPtr.Zero, IntPtr.Zero); } TLogging.Log("There is already another process with application title " + APPLICATION_TITLE); } } else { if (commandLineArgs.IsValid) { // Command line is valid so we will use the Small UI // Check if the port is available if (PortIsInUse(commandLineArgs.Port, true)) { string msg = "The port you have specified is in use. Check the System Tray to see if an instance of the web server is already running."; // Show a message box unless -quiet:true if (!commandLineArgs.SuppressStartupMessages) { System.Windows.Forms.MessageBox.Show( msg, APPLICATION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } // Now we just quit without starting anything TLogging.Log(msg); } else { if (commandLineArgs.MaxRuntimeInMinutes > 0) { // start a thread that will stop this server after the given time ThreadStart stopThread = delegate { StopApplication(commandLineArgs.MaxRuntimeInMinutes); }; Thread thread = new Thread(stopThread); // The next line is vital!! It ensures that when the application stops 'normally' the stopThread will terminate. // Otherwise the program will be left in memory thread.IsBackground = true; thread.Start(); } _RunStyle = RunStyles.SmallUI; TLogging.Log("Ict.Tools.OpenPetraWebServer is now running on port " + commandLineArgs.Port.ToString() + "..."); TLogging.Log(" Command line was: " + Environment.CommandLine); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); myForm = new SmallUIForm(commandLineArgs.PhysicalPath, commandLineArgs.VirtualPath, commandLineArgs.Port, commandLineArgs.DefaultPage, commandLineArgs.AcceptRemoteConnection, commandLineArgs.LogPageRequests); Application.Run(myForm); } } else { // Command line is invalid so we will use the Command Line Help form TLogging.Log("The command line arguments don't make sense! " + Environment.CommandLine, TLoggingType.ToConsole); _RunStyle = RunStyles.HelpUI; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new CommandLineHelp()); } } TLogging.Log("Ict.Tools.OpenPetraWebServer has finished"); }