Пример #1
0
        /// <summary>
        /// This method drives/orchestrates the desired
        /// functionality based on the action specified
        /// from the command line.
        /// </summary>
        /// <param name="parameters"></param>
        static private void runAsConsoleApplication(CommandLineParams parameters)
        {
            try
            {
                Console.WriteLine("Press any key to terminate...");

                ServiceHost blackjackHost =
                    new ServiceHost(typeof(BlackjackGameProcessor));
                blackjackHost.Open();

                // This will prevent the program
                // from terminating, while still
                // allowing this primary thread to
                // be responsive and display console
                // i/o generated from the trace
                bool done = false;
                do
                {
                    done = Console.KeyAvailable;
                    Thread.Sleep(100);
                } while (done == false);

                blackjackHost.Close();

                Console.WriteLine("Finished.");
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            Console.Read();
        }
Пример #2
0
        /// <summary>
        /// This is the application entry point
        /// </summary>
        /// <param name="args">The command line arguments</param>
        static int Main(string[] args)
        {
            // We won't have any arguments
            // if we are called by the SCM.
            // Since we have arguments, we
            // must be running interactively
            // with the user.
            if (args.Length > 0)
            {
                // Show some UI info
                showBanner();
            }

            LogHelper.Instance("BlackjackService");

            CommandLineParams parameters = null;

            try
            {
                // Parsing the command line can throw an
                // exception.  So we are going to use two
                // separate try..catch blocks.  One will handle
                // command line parsing problems, and the
                // other will handle processing-specific exceptions
                parameters = new CommandLineParams(args);
            }
            catch (Exception exception)
            {
                LogHelper.Instance().Write(exception.Message, LogEntrySeverityEnum.Error, exception);

                Console.WriteLine("There is a problem with the command line arguments - see event log for details.");

                return(FAILED);
            }

            try
            {
                if (true == parameters.ShowHelp)
                {
                    showUsage();

                    return(SUCCESS);
                }
                else if (true == parameters.InstallService)
                {
                    installService();

                    return(SUCCESS);
                }
                else if (true == parameters.UninstallService)
                {
                    uninstallService();

                    return(SUCCESS);
                }
                else if (args.Length > 0)
                {
                    runAsConsoleApplication(parameters);
                }
                else
                {
                    runAsService();
                }
            }
            catch (Exception exception)
            {
                LogHelper.Instance().Write(exception.Message, LogEntrySeverityEnum.Error, exception);

                Console.WriteLine("An unrecoverable problem was encountered - see event log for details.");

                return(FAILED);
            }

            return(SUCCESS);
        }