Пример #1
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            AppDomain.CurrentDomain.AssemblyResolve    += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            string runningMode = null;

            if (args.Length > 0)
            {
                string fileName = args[0];
                string arg      = fileName.ToLower();
                if (arg == "-mode" || arg == "/mode")
                {
                    if (args.Length > 1)
                    {
                        runningMode = args[1].ToLower();
                    }
                }
                else
                {
                    FileInfo fi = new FileInfo(fileName);
                    if (fi.Exists && fi.Extension.ToLower() == ".ctfx")
                    {
                        LoginHelper.NeedOpen = fi;
                    }
                }
            }

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

            if (String.IsNullOrEmpty(runningMode))
            {
                runningMode = ConfigurationManager.AppSettings["mode"].ToLower();
            }
            if (runningMode == "edithor")
            {
                Application.Run(new EditMainForm());
            }
            else if (runningMode == "client")
            {
                Application.Run(new TestingMainForm());
            }
            else if (runningMode == "service")
            {
                NativeMethods.AllocConsole();
                bool isService = false;
                bool.TryParse(ConfigurationManager.AppSettings["isService"], out isService);
                if (!isService)
                {
                    ServerHostProvider.StartServer(Program.Port, Program.DnsIdentity, Program.IsHttp);
                    Console.WriteLine(String.Format("[{0}]: Starting server.", DateTime.Now));
                    Console.WriteLine(String.Format("DnsIdentity: {0}; Port: {1}; IsHttp: {2};",
                                                    Program.DnsIdentity, Program.Port, Program.IsHttp));
                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey();
                }
                else
                {
                    ServiceBase[] ServicesToRun;
                    ServicesToRun = new ServiceBase[] { new TestingService() };
                    ServiceBase.Run(ServicesToRun);
                }
            }
            else
            {
                SystemMessage.ShowErrorMessage("Режим запуска не определён");
            }
        }
Пример #2
0
 protected override void OnStart(string[] args)
 {
     ServerHostProvider.StartServer(Program.Port, Program.DnsIdentity, Program.IsHttp);
 }