Inheritance: CommandLine.CommandLineOptionsBase
        static int RunMain(string[] arguments)
        {
            var result = 0;
           
            try
            {
                CommandLineParameters options = new CommandLineParameters();
                CommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));
                if(!parser.ParseArguments(arguments, options))
                {
                    return 80;
                }

                bool commandLineParameterProcessed = false;
                if(options.Install)
                {
                    Dev2Logger.Log.Info("Starting Install");
                    commandLineParameterProcessed = true;

                    if(!EnsureRunningAsAdministrator(arguments))
                    {
                        Dev2Logger.Log.Info("Cannot install because the server is not running as an admin user");
                        return result;
                    }

                    if(!WindowsServiceManager.Install())
                    {
                        result = 81;
                        Dev2Logger.Log.Info("Install Success Result is 81");
                    }
                }

                if(options.StartService)
                {
                    Dev2Logger.Log.Info("Starting Service");
                    commandLineParameterProcessed = true;

                    if(!EnsureRunningAsAdministrator(arguments))
                    {
                        Dev2Logger.Log.Info("Cannot start because the server is not running as an admin user");
                        return result;
                    }

                    if(!WindowsServiceManager.StartService(null))
                    {
                        Dev2Logger.Log.Info("Starting Service success. result 83");
                        result = 83;
                    }
                }

                if(options.StopService)
                {
                    Dev2Logger.Log.Info("Stopping Service");
                    commandLineParameterProcessed = true;

                    if(!EnsureRunningAsAdministrator(arguments))
                    {
                        Dev2Logger.Log.Info("Cannot stop because the server is not running as an admin user");
                        return result;
                    }

                    if(!WindowsServiceManager.StopService(null))
                    {
                        Dev2Logger.Log.Info("Stopping Service success. result 84");
                        result = 84;
                    }
                }

                if(options.Uninstall)
                {
                    Dev2Logger.Log.Info("Uninstall Service");
                    commandLineParameterProcessed = true;

                    if(!EnsureRunningAsAdministrator(arguments))
                    {
                        Dev2Logger.Log.Info("Cannot uninstall because the server is not running as an admin user");
                        return result;
                    }

                    if(!WindowsServiceManager.Uninstall())
                    {
                        Dev2Logger.Log.Info("Uninstall Service success. result 92");
                        result = 82;
                    }
                }

                if(commandLineParameterProcessed)
                {
                    Dev2Logger.Log.Info("Command line processed. Returning");
                    return result;
                }
                AppDomain.CurrentDomain.UnhandledException += (sender, args) => { Dev2Logger.Log.Fatal("Server has crashed!!!", args.ExceptionObject as Exception); };
                if(Environment.UserInteractive || options.IntegrationTestMode)
                {
                    Dev2Logger.Log.Info("** Starting In Interactive Mode ( " + options.IntegrationTestMode + " ) **");
                    using(_singleton = new ServerLifecycleManager(arguments))
                    {
                        result = _singleton.Run(true);
                    }

                    _singleton = null;
                }
                else
                {
                    Dev2Logger.Log.Info("** Starting In Service Mode **");
                    // running as service
                    using(var service = new ServerLifecycleManagerService())
                    {
                        ServiceBase.Run(service);
                    }
                }
            }
            catch(Exception err)
            {
                Dev2Logger.Log.Error("Error Starting Server", err);
                // ReSharper disable InvokeAsExtensionMethod
                Dev2Logger.Log.Error("Error Starting Server. Stack trace", err);
                // ReSharper restore InvokeAsExtensionMethod
                throw;
            }
            return result;
        }