Exemplo n.º 1
0
        static private void CreateLog(CommandLineArgs args)
        {
            if (args.LogfilePath == String.Empty)
            {
                // Create a console-only log
                new TLogging();
            }
            else
            {
                // Create a log file and a console log
                string pathToLogFile;

                if (args.UseFullUI)
                {
                    pathToLogFile = Path.Combine(args.LogfilePath, "Ict.Tools.OpenPetraWebServer.log");
                }
                else
                {
                    pathToLogFile = Path.Combine(args.LogfilePath, "Ict.Tools.OpenPetraWebServer." + args.Port.ToString() + ".log");
                }

                new TLogging(pathToLogFile);
            }

            // Direct the console logging to our server log form
            TLogging.SendConsoleOutputToString(OnNewLoggingMessage);
        }
Exemplo n.º 2
0
        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");
        }
Exemplo n.º 3
0
        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");
        }