示例#1
0
        CommandScanner CreateFactory()
        {
            var factory = new CommandScanner();

            factory.Registrate(typeof(TestAttributesCommand));
            return(factory);
        }
        public void Initialize()
        {
            var currentType = GetType();

            var scanner = new CommandScanner();
            var systemCommandTypes = scanner.Scan(currentType.Assembly, currentType.Namespace);

            Register(systemCommandTypes);
        }
示例#3
0
        public void Initialize()
        {
            var currentType = GetType();

            var scanner            = new CommandScanner();
            var systemCommandTypes = scanner.Scan(currentType.Assembly, currentType.Namespace);

            Register(systemCommandTypes);
        }
示例#4
0
        public void returns_expected_when_no_commands_are_found_in_assembly()
        {
            var emptyAssembly = new AssemblyBuilder().Build();
            var sut = new CommandScanner();

            var result = sut.Scan(emptyAssembly);

            Assert.Empty(result);
        }
示例#5
0
        public void returns_expected_when_no_commands_are_found_in_assembly()
        {
            var emptyAssembly = new AssemblyBuilder().Build();
            var sut           = new CommandScanner();

            var result = sut.Scan(emptyAssembly);

            Assert.Empty(result);
        }
        public IRegistryConfiguration RegisterFromAssembly(Assembly assembly)
        {
            _modifiers.Add(r =>
            {
                var commandTypes = new CommandScanner().Scan(assembly);
                r.Register(commandTypes);
            });

            return this;
        }
示例#7
0
        public IRegistryConfiguration RegisterFromAssembly(Assembly assembly)
        {
            _modifiers.Add(r =>
            {
                var commandTypes = new CommandScanner().Scan(assembly);
                r.Register(commandTypes);
            });

            return(this);
        }
示例#8
0
        static void Main(string[] args)
        {
            var scanner = new CommandScanner();

            //scan or append command types manualy here:
            //scanner.Registrate<myCommandType>();
            //or command singletone Instances
            //scanner.Registrate(new myCommand(myCommandSettings))

            //scan only executing assembly:
            scanner.ScanAssembly(Assembly.GetEntryAssembly());

            var gin = new Gin(
                library:  scanner,                       //Specify your own command library
                executor: new Executor(),                //(optional) specify your own command executor (do not forget to catch exceptions and attach the log to commands in it)
                log:      new DecoratorLog               //(optional) combine different logs
                (
                    new ConsoleLog(),
                    new FileLog(maxLogLength: 10000,
                                relativeFileName: "TheLog.txt",
                                writeFilter: FileLogFilter.All)
                ));

            gin.Log.WriteMessage("Gin lauched at " + DateTime.Now);

            //to switch log at runtime:
            //gin.Log = new ConsoleLog();
            if (!Environment.UserInteractive) //if it was launched as a service
            {
                gin.Log.WriteMessage("Executed as a service");
                //Do not forget to setup your service name at WindowsServiceInstaller.cs

                //and do whatever you want here as a service...

                //Will be executed at scheduler timer thread:
                gin.Execute("divide  a 10  b 5  at 02:00  every 24h");
                //You can use different argument styles and combine them
                //gin.Execute("divide a: 10  b: 5  at 02:00  every 24h");
                //gin.Execute("divide -a 10  -b 5  -at 02:00  every \"24h\"");

                //Will be executed at this thread:
                gin.Execute("writeHello");

                gin.WaitForFinsh();
            }
            else if (args.Length > 0)     // if it was launched with parameters:
            {
                gin.Execute(args);
                //close the application after operation will be done
            }
            else               // when it's executed as a console application:
            {
                gin.AddHelp(); // adds the \"help\" command
                gin.AddExit(); // adds the \"exit\" command

                gin.RunInputLoop();

                gin.Log.WriteMessage("Goodbye. Press any key to continue...");
                Console.ReadKey();
            }
        }
示例#9
0
 public void BeforeEachTest()
 {
     _configuration = new ParserConfiguration();
     _scanner = new CommandScanner(_configuration);
 }
示例#10
0
        private void Initialize()
        {
            // TODO - allow help options to be configured via settings
            _configuration.AddNamedParameter("Help", true).AddShortName("h").AddShortName("?");

            // Scan all the commands for their options...
            CommandScanner scanner = new CommandScanner(_configuration);

            foreach (var c in _commands)
            {
                // Add the command to the configuration based on attribute decorations...
                var parserCommand = scanner.Scan(c);

                // Add the command to the map so we can find it after parsing...
                _commandMap.Add(parserCommand.Text, c);

                // Set help as the default command
                if (c == _helpCommand)
                {
                    _configuration.DefaultCommand = parserCommand;
                }
            }
        }