예제 #1
0
        private static void Main()
        {
            // Setup uncaught exception catching, only if we're not running from Visual Studio thou...
            if (!AppDomain.CurrentDomain.FriendlyName.EndsWith("vshost.exe"))
            {
                Application.ThreadException += ApplicationOnThreadException;
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
            }

            RootDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            if (RootDirectory == null)
            {
                throw new Exception("Unable to find Assembly root path. The f**k happened here?");
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Global.ApplicationInfo = new ApplicationInfo();
            Global.ApplicationInfo.ApplicationName    = "PokeEditorV3";
            Global.ApplicationInfo.ApplicationVersion = "0.1";
            Global.ApplicationInfo.BasePath           = Application.StartupPath;

            // Set the configuration provider
            var provider = new XmlConfigurationProvider();

            provider.ManualConfigFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PokeEditor.config");
            Global.ConfigurationProvider  = provider;
            Global.ConfigurationInfo.Add(new EditorConfigInfo());

            // Initialize validators
            var verifiers = new VerifierCollection();

            verifiers.Add(new WritePermissionVerifier(Path.Combine(RootDirectory, "Exceptions")));
            verifiers.Add(new WritePermissionVerifier(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)));
            if (!verifiers.Verify())
            {
                throw new VerificationException(verifiers.ErrorMessage);
            }

            // Load all managers
            GlobalManager.Initialize();

            var mainForm = new FrmMain();

            Context = SynchronizationContext.Current;

            Application.Run(mainForm);

            // Show Login form

            /*using (var loginForm = new FrmLogin())
             * {
             *  DialogResult result = loginForm.ShowDialog();
             *  if (result == DialogResult.OK)
             *  {
             *      Application.Run(mainForm);
             *  }
             * }*/
        }
예제 #2
0
        static void Main()
        {
            RootDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            if (RootDirectory == null)
            {
                throw new Exception("Unable to find Assembly root path. The f**k happened here?");
            }

            var consoleMode = Environment.CommandLine.Contains("-console");

            Global.ApplicationInfo = new ApplicationInfo();
            Global.ApplicationInfo.ApplicationName    = "Server";
            Global.ApplicationInfo.ApplicationVersion = "0.1";
            Global.ApplicationInfo.BasePath           = RootDirectory;

            // Initialize validators
            var verifiers = new VerifierCollection();

            verifiers.Add(new WritePermissionVerifier(Path.Combine(RootDirectory, "cfg")));
            verifiers.Add(new WritePermissionVerifier(Path.Combine(RootDirectory, "logs")));
            if (!verifiers.Verify())
            {
                throw new VerificationException(verifiers.ErrorMessage);
            }

            // Set the configuration provider
            var provider = new XmlConfigurationProvider();

            provider.ManualConfigFilePath = Path.Combine(RootDirectory, "cfg", "Server.config");
            Global.ConfigurationProvider  = provider;
            Global.ConfigurationInfo.Add(new ServerConfigInfo());

            // Setup logging
            if (consoleMode)
            {
                Global.LoggingProvider = new ConsoleLoggingProvider();
            }
            else
            {
                Global.LoggingProvider = new AsyncLoggingProvider(Path.Combine(RootDirectory, "logs"), "server", 7);
            }

            if (consoleMode)
            {
                var application = new Startup();
                application.StartServer();

                Console.WriteLine(@"The server started successfully, press key 'q' to stop it!");

                while (Console.ReadKey().KeyChar != 'q')
                {
                    //Console.WriteLine("");
                }

                /*Console.WriteLine(@"-----------------------------------------");
                 * Console.WriteLine(@"End of the line. Press enter to exit.");
                 * Console.ReadLine();*/
            }
            else
            {
                ServiceBase.Run(new Startup());
            }
        }