Beispiel #1
0
		static int Main(string[] args)
		{
			Log.Config.Output = LogOutputs.LogFile;
			Log.Config.Level = LogLevels.Info;

			if (!Environment.UserInteractive)
			{
				Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
				System.ServiceProcess.ServiceBase.Run(new SslService());
				return 0;
			}

			string ignore;
			bool nologo = ArgumentList.Remove(ref args, "nologo", out ignore);

			using (Log.AppStart(Environment.CommandLine))
			{
				if (nologo == false)
				{
					Console.WriteLine("SslTunnel.Server.exe");
					Console.WriteLine("Copyright 2009 by Roger Knapp, Licensed under the Apache License, Version 2.0");
					Console.WriteLine("");
				}

				CommandInterpreter ci = new CommandInterpreter(DefaultCommands.Help, typeof(Commands));
				ci.Run(args);
			}

			return Environment.ExitCode;
		}
Beispiel #2
0
        public static int Process(string[] args, ICommands commands)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            if (commands == null)
            {
                throw new ArgumentNullException(nameof(commands));
            }

            var commandInterpreter =
                new CSharpTest.Net.Commands.CommandInterpreter(DefaultCommands.Help, commands)
            {
                /* Sometimes ErrorLevel still has a value other than zero when testing.
                 * Maybe because this is a static class and a static member?
                 * Force it here.
                 */
                ErrorLevel = 0
            };

            commandInterpreter.Run(args);

            return(commandInterpreter.ErrorLevel);
        }
Beispiel #3
0
 static void Main(string[] args)
 {
     try
     {
         CommandInterpreter ci = new CommandInterpreter(DefaultCommands.Help, new Program());
         ci.Run(args);
     }
     catch(ApplicationException ae)
     {
         Console.Error.WriteLine();
         Console.Error.WriteLine(ae.Message);
     }
     catch (Exception e)
     {
         Console.Error.WriteLine();
         Console.Error.WriteLine(e.ToString());
     }
     finally
     {
         if(System.Diagnostics.Debugger.IsAttached)
         {
             Console.WriteLine();
             Console.WriteLine("Press [Enter] to quit...");
             Console.ReadLine();
         }
     }
 }
Beispiel #4
0
        static int Main(string[] arguments)
        {
            LogConfig.Configure();
            try
            {
                using (CommandLine commands = new CommandLine())
                {
                    CommandInterpreter ci = new CommandInterpreter(DefaultCommands.None, commands);
                    if (arguments.Length > 0)
                    {
                        List<string> args = new List<string>(arguments);
                        int position = 0;
                        while (position < args.Count)
                        {
                            int next = args.IndexOf("&&", position);
                            if (next < 0) next = args.Count;

                            ci.Run(arguments.Skip(position).Take(next - position).ToArray());
                            position = next + 1;

                            if (ci.ErrorLevel != 0)
                                break;
                        }
                    }
                    else
                        ci.Run(Console.In);

                    Environment.ExitCode = ci.ErrorLevel;
                }
            }
            catch (ApplicationException ae)
            {
                Console.Error.WriteLine();
                Console.Error.WriteLine(ae.Message);
                Environment.ExitCode = -1;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
                Environment.ExitCode = -1;
            }

            return Environment.ExitCode;
        }
Beispiel #5
0
		private static int Main(string[] args)
		{
			int result = -1;
		
			string ignore;
			bool wait = ArgumentList.Remove(ref args, "wait", out ignore);

			Log.ConsoleLevel = TraceLevel.Info;
			if (ArgumentList.Remove(ref args, "quiet", out ignore))
				Quiet();
			if (ArgumentList.Remove(ref args, "verbose", out ignore))
				Verbose();

			using(Log.Start(Environment.CommandLine))
			try
			{
				CommandInterpreter ci = new CommandInterpreter(DefaultCommands.Help, typeof(Program));
				ci.Run(args);
				result = ci.ErrorLevel;
			}
			catch (OperationCanceledException)
			{ result = 3; }
			catch (ApplicationException ex)
			{
				Log.Error(ex);
				Console.Error.WriteLine(ex);
				result = 1;
			}
			catch (Exception ex)
			{
				Log.Error(ex);
				Console.Error.WriteLine(ex.ToString());
				result = 2;
			}
			finally
			{
				if (wait)
				{
					Console.WriteLine("Exited with result = {0}, Press Enter to quit.", result);
					Console.ReadLine();
				}
			}
			return Environment.ExitCode = result;
		}
 public void Add(CommandInterpreter ci, DefaultCommands cmds)
 {
     foreach (DefaultCommands key in Enum.GetValues(typeof(DefaultCommands)))
     {
         IDisplayInfo item;
         if (key == (key & cmds) && _contents.TryGetValue(key, out item))
         {
             if (item is ICommandFilter)
             {
                 ci.AddFilter(item as ICommandFilter);
             }
             else if (item is ICommand)
             {
                 ci.AddCommand(item as ICommand);
             }
             else if (item is IOption)
             {
                 ci.AddOption(item as IOption);
             }
         }
     }
 }
        public int Run(string[] args)
        {
			Log.Config.Output = LogOutputs.LogFile;
			Log.Config.Level = LogLevels.Info;

			string ignore;
			bool nologo = ArgumentList.Remove(ref args, "nologo", out ignore);

			using (Log.AppStart(Environment.CommandLine))
			{
				if (nologo == false)
				{
					Console.WriteLine("SslTunnel.Server.exe");
					Console.WriteLine("Copyright 2009 by Roger Knapp, Licensed under the Apache License, Version 2.0");
					Console.WriteLine("");
				}

				CommandInterpreter ci = new CommandInterpreter(DefaultCommands.Help, typeof(Commands));
				ci.Run(args);
			}

			return Environment.ExitCode;
		}
Beispiel #8
0
        static int Main(string[] arguments)
        {
            try
            {
                CommandInterpreter ci = new CommandInterpreter(DefaultCommands.Help | DefaultCommands.IORedirect, typeof(Commands));
                ci.Run(arguments);
                
                Environment.ExitCode = ci.ErrorLevel;
            }
            catch (ApplicationException ae)
            {
                Console.Error.WriteLine();
                Console.Error.WriteLine(ae.Message);
                Environment.ExitCode = -1;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine();
                Console.Error.WriteLine(e.ToString());
                Environment.ExitCode = -1;
            }

            return Environment.ExitCode;
        }
		public LastFilter(CommandInterpreter ci)
		{ _ci = ci; }
Beispiel #10
0
 public LastFilter(CommandInterpreter ci)
 {
     _ci = ci;
 }
        static int Main(string[] args)
        {
            int result = -1;

            string temp;
            var wait = ArgumentList.Remove(ref args, "wait", out temp);
       
            try
            {
                // Construct the CommandInterpreter and initialize
                ICommandInterpreter ci = new CommandInterpreter(
                    DefaultCommands.Help |
                    DefaultCommands.IORedirect |
                    0,
                    // Add the types to use static members
                    typeof(Filters), 
                    // Add classes to use instance members
                    typeof(Commands)
                    );

                // If you want to hide some options/commands at runtime you can:
                foreach (var name in new[] {"prompt", "errorlevel"})
                {
                    IOption opt;
                    if (ci.TryGetOption(name, out opt))
                        opt.Visible = false;
                }
                foreach (var name in new[] {"echo", "set", "get"})
                {
                    ICommand opt;
                    if (ci.TryGetCommand(name, out opt))
                        opt.Visible = false;
                }

                // Apply all DefaultValue values to properties
                ci.SetDefaults();

                // If we have arguments, just run with those arguments...
                if (args.Length > 0)
                    ci.Run(args);
                else
                {
                    //When run without arguments you can either display help:
                    //ci.Help(null);
                    //... or run the interpreter:
                    ci.Run(Console.In);
                }

                result = ci.ErrorLevel;
            }
            catch (OperationCanceledException)
            { result = 3; }
            catch (ApplicationException ex)
            {
                Trace.TraceError("{0}", ex);
                Console.Error.WriteLine(ex.Message);
                result = 1;
            }
            catch (Exception ex)
            {
                Trace.TraceError("{0}", ex);
                Console.Error.WriteLine(ex.ToString());
                result = 2;
            }
            finally
            {
                if (wait)
                {
                    Console.WriteLine("Exited with result = {0}, Press Enter to quit.", result);
                    Console.ReadLine();
                }
            }

            return Environment.ExitCode = result;
        }