Esempio n. 1
0
        static void Main()
        {
            //Perform a simple greet
            IGreeter greeter = new EnglishGreeter();
            greeter.Greet(Environment.UserName);

            //Run the command line program - this demonstrates usage of protected fields
            var service = new CommandLineService();

            //To demonstrate field access (pointless field access mind you) set the field "Name"
            service.Name = "MyService";

            //Register commands and start
            service.RegisterCommand<QuitCommand>();
            service.RegisterCommand<SayHelloCommand>();
            service.RegisterCommand<TestCommand>();
            service.Start();

            //Display the "IsRunning" property - for no reason other than to prove property access is the same
            Console.Write("The CommandLineService {0} ", service.Name);
            if (service.IsRunning)
                Console.WriteLine("is still running");
            else
                Console.WriteLine("has stopped running");
        }
Esempio n. 2
0
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="args">The args.</param>
 /// <returns></returns>
 protected override int ExecuteCommand(string[] args)
 {
     IGreeter greeter = new EnglishGreeter();
     if (args == null || args.Length == 0)
         Console.WriteLine(greeter.Greet(Environment.UserName));
     else if (args.Length == 1)
         Console.WriteLine(greeter.Greet(args[0]));
     else
     {
         Console.WriteLine("Invalid arguments");
         return 1;
     }
     return 0;
 }
Esempio n. 3
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        protected override int ExecuteCommand(string[] args)
        {
            IGreeter greeter = new EnglishGreeter();

            if (args == null || args.Length == 0)
            {
                Console.WriteLine(greeter.Greet(Environment.UserName));
            }
            else if (args.Length == 1)
            {
                Console.WriteLine(greeter.Greet(args[0]));
            }
            else
            {
                Console.WriteLine("Invalid arguments");
                return(1);
            }
            return(0);
        }