private void Shutdown()
 {
     // Inform MOG we are shutting down
     MOG_Main.Shutdown();
     // Terminate our application
     Application.Exit();
 }
示例#2
0
        internal void Shutdown()
        {
            // Inform MOG we are shutting down
            MOG_Main.Shutdown();

            // Play nice and let the processing thread shutdown on it's own
            int waitTime  = 0;
            int sleepTime = 10;

            while (mMogProcess != null)
            {
                // Gracefully sleep while we wait for the process thread to shutdown
                Thread.Sleep(sleepTime);
                waitTime += sleepTime;
                // Check if we have waited long enough?
                if (waitTime >= 1000)
                {
                    // Forcible terminate the processing thread
                    mMogProcess.Abort();
                    mMogProcess = null;
                }
            }

            // Terminate our application
            Application.Exit();
        }
示例#3
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (components != null)
         {
             components.Dispose();
         }
     }
     MOG_Main.Shutdown(true);
     base.Dispose(disposing);
 }
示例#4
0
        static void Main(string[] args)
        {
            Control.CheckForIllegalCrossThreadCalls = false;

            SplashForm form = null;

            try
            {
                // Check for multiple instances
                Process mogProcess = RunningInstance();
                if (mogProcess != null)
                {
                    // we've got a duplicate process - ask the user if they want to continue anyway
                    DialogResult res = MessageBox.Show("An instance of the MOG Server Manager is already running on this machine.\nIt is possible that this instance is the result of a crash or other problem,\nin which case you should contact your MOG or network administrator.\n\nWould you like to start the Manager anyway?",
                                                       "Manager Already Running", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

                    // if not, shutdown
                    if (res == DialogResult.No)
                    {
                        return;
                    }

                    // user wants to spawn a new instance
                }

                form                  = new SplashForm(args);
                form.Closing         += new CancelEventHandler(form_Closing);
                form.Closed          += new EventHandler(form_Closed);
                form.HandleDestroyed += new EventHandler(form_HandleDestroyed);
                Application.Run(form);
            }
            catch (Exception e)
            {
                MOG_Report.ReportMessage("Main", e.Message, e.StackTrace, MOG_ALERT_LEVEL.CRITICAL);
                // Write our problem out to our Output window in VS.NET
                System.Diagnostics.Debug.WriteLine(e.ToString() + "\n" + e.StackTrace);
                // Shutdown our process
                if (form != null)
                {
                    form.Close();
                    if (form.mainForm.mMogProcess != null)
                    {
                        form.mainForm.mMogProcess.Abort();
                    }
                }
                // Exit our application so we can set a breakpoint here and try again
                MOG_Main.Shutdown();
                Application.Exit();
            }
        }
示例#5
0
        public void ParseArgs(string [] args, string defaultIniLocation)
        {
            configurationIni = defaultIniLocation;

            // Parse command line options
            if (args.Length > 0)
            {
                foreach (string arg in args)
                {
                    if (arg.IndexOf("mog=") != -1)
                    {
                        configurationIni = arg.Substring(arg.IndexOf("=") + 1);
                        FileInfo file = new FileInfo(configurationIni);
                        if (!file.Exists)
                        {
                            MessageBox.Show(String.Concat("MOG Configutation file (", configurationIni, ") does not exist! Exiting..."), "INI Error");
                            MOG_Main.Shutdown();
                            Application.Exit();
                        }
                    }
                }
            }
        }
示例#6
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     MOG_Main.Shutdown();
     RemoteServerSettings.SaveSettings();
 }
示例#7
0
        private bool InitSlave(string[] args)
        {
            String configFilename;
            bool   bInitialized = false;
            int    argc         = getNumArgs(args);

            // Default into SLAVE mode
            configFilename = "";

            // Parse command line options
            if (args.Length > 0)
            {
                foreach (String arg in args)
                {
                    if (arg.IndexOf("mog=") != -1)
                    {
                        configFilename = arg.Substring(arg.IndexOf("=") + 1);
                        FileInfo file = new FileInfo(configFilename);
                        if (!file.Exists)
                        {
                            MessageBox.Show(String.Concat("MOG Configutation file (", configFilename, ") does not exist! Exiting..."), "INI Error");
                            Shutdown();
                            return(false);
                        }
                    }
                }
            }

            // Check command-line argument #2
            if (argc >= 2)
            {
                MessageBox.Show("Command line arguments are not yet supported.");
            }
            else
            {
                // Use the specified config file
                if (argc >= 2)
                {
                    configFilename = args[1];
                }

                try
                {
                    // Attempt to initialize the Slave?
                    if (MOG_Main.Init_Slave(configFilename, "Slave"))
                    {
                        // Make sure we obtain a valid NetworkID before continuing
                        if (MOG_ControllerSystem.RequireNetworkIDInitialization())
                        {
                            bInitialized = true;
                            this.niconSystemTrayIcon.Text = RefreshConnectionToolText();
                        }
                        else
                        {
                            // This is a great place to kill the application because there is already another server running
                            MOG_Report.ReportMessage("Mog Initialization Error", "Slave was unable to obtain a NetworkID from the server.", "", MOG_ALERT_LEVEL.ALERT);
                            MOG_Main.Shutdown();
                            return(false);
                        }
                    }
                    else
                    {
                        // The server was shutdown
                        Bitmap DisconnectedIcon = new Bitmap(SlaveIconsImageList.Images[1]);
                        niconSystemTrayIcon.Icon = System.Drawing.Icon.FromHandle(DisconnectedIcon.GetHicon());
                        niconSystemTrayIcon.Text = "Server is disconnected!";

                        // This is a great place to kill the application because there is already another server running
                        MOG_Report.ReportMessage("Mog Initialization Error", "Slave was unable to initialize.", "", MOG_ALERT_LEVEL.ALERT);
                        MOG_Main.Shutdown();
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    MOG_Report.ReportMessage("Mog Initialization Error", e.Message, e.StackTrace, MOG_ALERT_LEVEL.CRITICAL);
                    MOG_Main.Shutdown();
                    return(false);
                }
            }

            return(bInitialized);
        }