Exemple #1
0
        private void ReadStarConfigs()
        {
            var serverConfig = new JsonFileConfiguration <ServerConfiguration>(ServerConfigFile, _jsonSettings);

            serverConfig.Load();

            ServerConfig = serverConfig.Config;

            Configurations.Add(serverConfig);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;

            XmlConfigurator.Configure();

            _configFile = new JsonFileConfiguration <SharpConfig>("sharpconfig.json", new JsonSerializerSettings());
            _configFile.Load();

            try
            {
                Run();
            }
            catch (Exception ex)
            {
                ex.LogError();

                return;
            }

            if (StarMain.Instance.ServerConfig.RunAsService)
            {
                if (MonoHelper.IsRunningOnMono)
                {
                    StarLog.DefaultLogger.Info("You are currently running Mono version {0}", MonoHelper.GetMonoVersion());

                    WaitForUnixExit();
                }

                ServiceBase.Run(new StarService());

                return;
            }

            Console.CancelKeyPress += Console_CancelKeyPress;
            Console.SetError(TextWriter.Null);

            if (MonoHelper.IsRunningOnMono)
            {
                StarLog.DefaultLogger.Info("You are currently running Mono version {0}", MonoHelper.GetMonoVersion());

                WaitForUnixExit();
            }
            else
            {
                NativeMethods.SetConsoleCtrlHandler(ConsoleCtrlCheck, true);
            }

            while (!_shutdown)
            {
                try
                {
                    string input = Console.ReadLine();

                    if (input != null)
                    {
                        string[] ex = input.Split(' ');

                        if (ex[0].Equals("exit", StringComparison.OrdinalIgnoreCase))
                        {
                            TimeSpan?ts = null;
                            if (ex.Length == 2)
                            {
                                double time;

                                if (double.TryParse(ex[1], out time))
                                {
                                    ts = TimeSpan.FromMinutes(time);
                                }
                            }

                            Shutdown(false, ts);

                            if (!ts.HasValue)
                            {
                                break;
                            }
                        }

                        StarMain.Instance.ConsoleCommandManager.TryPassConsoleCommand(input);
                    }
                }
                catch
                {
                }
            }
        }