コード例 #1
0
ファイル: Program.cs プロジェクト: szx8023/openPDC
        static void Main(string[] args)
        {
            ConsoleHost shellHost = new ConsoleHost(new ServiceHost());

            shellHost.Run();
            Environment.Exit(0);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: lulzzz/openMIC
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            if (!s_singleInstanceMutex.WaitOne(0, true))
            {
                Environment.Exit(1);
            }

            bool runAsService;
            bool runAsApplication;

            Arguments args = new Arguments(Environment.CommandLine, true);

            if (args.Count > 1)
            {
                MessageBox.Show("Too many arguments. If specified, argument must be one of: -RunAsService, -RunAsApplication or -RunAsConsole.");
                Environment.Exit(1);
            }

            if (args.Count == 0)
            {
#if DEBUG
                runAsService     = false;
                runAsApplication = true;
#else
                runAsService     = true;
                runAsApplication = false;
#endif
            }
            else
            {
                runAsService     = args.Exists("RunAsService");
                runAsApplication = args.Exists("RunAsApplication");

                if (!runAsService && !runAsApplication && !args.Exists("RunAsConsole"))
                {
                    MessageBox.Show("Invalid argument. If specified, argument must be one of: -RunAsService, -RunAsApplication or -RunAsConsole.");
                    Environment.Exit(1);
                }
            }

            if (runAsService)
            {
                // Run as Windows Service.
                ServiceBase.Run(new ServiceBase[] { Host });
            }
            else if (runAsApplication)
            {
                // Run as Windows Application.
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new DebugHost(Host));
            }
            else
            {
                ConsoleHost consoleHost = new ConsoleHost(Host);
                consoleHost.Run();
                Environment.Exit(0);
            }
        }
コード例 #3
0
        /// <summary>
        /// The entry point
        /// </summary>
        /// <param name="args">The run arguments</param>
        static void Main(string[] args)
        {
            // create host
            var host = new ConsoleHost();

            // run
            host.Run();
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            // init structure map
            IoC.Initialize();
            ConsoleHost applicationEntry = new ConsoleHost(System.Console.In, System.Console.Out);

            applicationEntry.Run();
        }
コード例 #5
0
 static void Main(string[] args)
 {
     try
     {
         ConsoleHost host = new ConsoleHost(new ServiceHost());
         host.Run();
         Environment.Exit(0);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Hosted service exception: {0}", ex.Message);
         Environment.Exit(1);
     }
 }
コード例 #6
0
        public static async Task <int> Run <T>(string[] args, T commandLineBinding) where T : ICommandLineBinding
        {
            var initialisationInformation = new InitialisationInformation();

            initialisationInformation.AddMessage(MessageType.Information, $"Received command line {string.Join(" ", args.Select(x => $"[{x}]"))}");
            var consoleHost = new ConsoleHost();

            var parserType        = typeof(CommandLineParser <>).MakeGenericType(commandLineBinding.CommandLineType);
            var commandLineParser = (ICommandLineParser)Activator.CreateInstance(parserType);

            var parseResult = commandLineParser.Parse(args, initialisationInformation);

            switch (parseResult.ParseResult)
            {
            case ParseResult.Failed:
                consoleHost.ReportInitialisation(initialisationInformation);
                return(ReturnCodes.CommandLineParsingFailed);

            case ParseResult.SuccessfulAndExit:
                consoleHost.ReportInitialisation(initialisationInformation);
                return(ReturnCodes.Success);

            default:
                var          applicationBootstrapper = commandLineBinding.CreateBootstrapper(parseResult.CommandLine);
                IApplication application             = null;

                try
                {
                    application = applicationBootstrapper.Bootstrap();
                }
                catch (Exception ex)
                {
                    initialisationInformation.AddMessage(MessageType.Error, $"Failed to bootstrap{Environment.NewLine}{ex}");
                    consoleHost.ReportInitialisation(initialisationInformation);
                    return(ReturnCodes.BoostrapFailed);
                }

                var returnCode = await consoleHost.Run(application, initialisationInformation);

                return((int)returnCode);
            }
        }
コード例 #7
0
        /// <summary>
        /// The entry point of application
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            var host = new ConsoleHost();

            host.Run();
        }