Beispiel #1
0
        public static Configuration create(string[] parameters)
        {
            Configuration conf = new Configuration();

            // use default configuration if no parameters exist

            if (parameters.Length == 0)
                return conf;

            // cycle throught command line using enumerator on parameters array

            IEnumerator enumerator = parameters.GetEnumerator();
            enumerator.MoveNext();

            string parameter = (string)enumerator.Current;

            // parse if first parameter is a valid integer and use it as a port number for listener

            int port;
            bool hasPortParameter = int.TryParse(parameter, out port);

            if (hasPortParameter)
            {
                conf.Port = port;

                // continue parsing parameters (if they exist)
                if (!enumerator.MoveNext())
                    return conf;
                parameter = (string)enumerator.Current;
            }

            do
            {
                if (parameter.Equals("-m"))
                {
                    conf.AllowMultiple = true;
                }
                else if (parameter.Equals("-b"))
                {
                    conf.Banner = false;
                }
                else if (parameter.Equals("-h"))
                {
                    conf.Help = true;
                }
                else if (parameter.Equals("-ip"))
                {
                    enumerator.MoveNext();
                    conf.IpAddress = (string)enumerator.Current;
                }
                else
                {
                    throw new ArgumentException(string.Format("Error: {0} is an invalid command line parameter.", parameter));
                }

                parameter = (string)enumerator.Current;
            } while (enumerator.MoveNext());

            return conf;
        }
Beispiel #2
0
        /// <summary>
        /// Run server
        /// </summary>
        /// <param name="conf">server configuration</param>
        private static void RunServer(Configuration conf)
        {
            using (Server server = new Server().Start(conf.IpAddress, conf.Port))
            {
                if (!server.IsRunning())
                {
                    Console.WriteLine("Could not start server... Exiting.");
                    return;
                }

                Console.WriteLine("Server running press [c] to stop");
                while (server.IsRunning() && Console.ReadKey(true).Key != ConsoleKey.C)
                    ;
                server.Stop();
            }
        }