예제 #1
0
        private static PMConfiguration ParseArgs(string[] args)
        {
            if (args.Length < 2 ||
                !int.TryParse(args[1], out int version))
            {
                OnInvalidNumberOfArguments();
                Environment.Exit(1);
                return(null);
            }
            PMConfiguration config = new PMConfiguration {
                Host    = args[0],
                Port    = PORT,
                Version = version
            };

            switch (args.Length)
            {
            // Read commands from Standard Input
            case 2:
                config.InputSource = GetStdinStreamInput();
                return(config);

            // Read commands from Configuration File
            case 3:
                config.InputSource = GetFileStreamInput(args[2]);
                return(config);

            default:
                OnInvalidNumberOfArguments();
                Environment.Exit(1);
                return(null);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            AppContext.SetSwitch(
                "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport",
                true);

            PMConfiguration config = ParseArgs(args);

            Console.WriteLine(
                "[{0}] Puppet Master started with version {1}",
                DateTime.Now.ToString("HH:mm:ss"),
                config.Version);

            NameServiceDB nameServiceDB = new NameServiceDB();
            PMController  controller    = new PMController(config, nameServiceDB);

            using TextReader textReader = config.InputSource;
            string   line;
            ICommand command;

            while ((line = textReader.ReadLine()) != null)
            {
                if (!TryParse(line, out command))
                {
                    Console.WriteLine("Invalid Command");
                    continue;
                }
                command.Accept(controller);
            }

            Console.WriteLine(
                "[{0}] Instructions Completed. Press any key to exit...",
                DateTime.Now.ToString("HH:mm:ss"));
            Console.ReadKey();
        }
예제 #3
0
 public PMController(PMConfiguration config, NameServiceDB nameServiceDB)
 {
     this.config        = config;
     this.nameServiceDB = nameServiceDB;
 }