Beispiel #1
0
        public static void ConfigureCommandsAndHandlers(IWindsorContainer container)
        {
            var commandType = typeof(ICommand);
            var allCommands = AppDomain.CurrentDomain.GetAssemblies()
                              .SelectMany(s => s.GetTypes())
                              .Where(p => commandType.IsAssignableFrom(p) &&
                                     p.IsClass &&
                                     !p.IsAbstract &&
                                     !p.IsInterface);

            CommandLocator commandLocator = null;

            foreach (var command in allCommands)
            {
                if (commandLocator == null)
                {
                    commandLocator = new CommandLocator
                                         (command.Assembly, command.Namespace);
                }
                else
                {
                    commandLocator.AddCommandSource
                        (command.Assembly, command.Namespace);
                }
            }

            container.Register(
                Component.For <ICommandLocator>()
                .UsingFactoryMethod(() => commandLocator)
                );

            container.Register(Component.For <CommandPublicationRegistry>()
                               .ImplementedBy <CommandPublicationRegistry>());

            ModelBinders.Binders.Add(typeof(ICommand), new CommandModelBinder());

            var handlerType = typeof(ICommandHandler);
            var allHandlers = AppDomain.CurrentDomain.GetAssemblies()
                              .SelectMany(s => s.GetTypes())
                              .Where(p => handlerType.IsAssignableFrom(p) && p.IsClass);

            var handler = allHandlers.FirstOrDefault();

            if (handler != null)
            {
                var handlers = PipelineInstaller.InstallHandlers(container, handler.Assembly);

                container.Register(Component.For <IList <ICommandHandler> >()
                                   .Instance(handlers)
                                   .LifestyleSingleton());

                container.Register(Component.For <ICommandPipeline>()
                                   .ImplementedBy <SimpleCommandPipeline>()
                                   .LifestylePerWebRequest());
            }
            else
            {
                // TODO: log this?
            }
        }
Beispiel #2
0
        public void CanUseLocator()
        {
            var locator = new CommandLocator();
            var command = locator.FindCommand <AddRequest, int>();

            Assert.NotNull(command);
        }
Beispiel #3
0
 public AdminTool(CommandLocator commandLocator, BlockerLocator blockerLocator, OutsideWorld outsideWorld, bool debug)
 {
     this._commandLocator = CommandLocator.withAdditionalCommand(Help(), commandLocator);
     this._blockerLocator = blockerLocator;
     this._outsideWorld   = outsideWorld;
     this._debug          = debug;
     this._usage          = new Usage(SCRIPT_NAME, this._commandLocator);
 }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            File graphDir = new File(GraphDatabaseSettings.DEFAULT_DATABASE_NAME);

            _confDir = new File(graphDir, "conf");
            _homeDir = new File(graphDir, "home");
            @out     = mock(typeof(OutsideWorld));
            ResetOutsideWorldMock();
            _tool = new AdminTool(CommandLocator.fromServiceLocator(), BlockerLocator.fromServiceLocator(), @out, true);
        }
Beispiel #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException
        public static void Main(string[] args)
        {
            Path homeDir   = Paths.get(Neo4jHome);
            Path configDir = Paths.get(Neo4jConf);
            bool debug     = !string.ReferenceEquals(Neo4jDebug, null);

            using (RealOutsideWorld outsideWorld = new RealOutsideWorld())
            {
                (new AdminTool(CommandLocator.fromServiceLocator(), BlockerLocator.fromServiceLocator(), outsideWorld, debug)).Execute(homeDir, configDir, args);
            }
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void printsUnknownCommandWhenUnknownCommandIsProvided()
        internal virtual void PrintsUnknownCommandWhenUnknownCommandIsProvided()
        {
            CommandLocator commandLocator = mock(typeof(CommandLocator));

            when(commandLocator.AllProviders).thenReturn(Collections.emptyList());
            when(commandLocator.FindProvider("foobar")).thenThrow(new NoSuchElementException("foobar"));

            HelpCommand helpCommand = new HelpCommand(mock(typeof(Usage)), @out, commandLocator);

            IncorrectUsage incorrectUsage = assertThrows(typeof(IncorrectUsage), () => helpCommand.execute("foobar"));

            assertThat(incorrectUsage.Message, containsString("Unknown command: foobar"));
        }
        static int Main(string[] args)
        {
            string[] commandArguments;
            var      commandName = ExtractCommand(args, out commandArguments);
            var      locator     = new CommandLocator();
            var      command     = locator.Find(commandName);

            if (command == null)
            {
                locator.Create(locator.Find("help")).Execute(commandArguments);
                return(4);
            }

            try
            {
                var exitCode = locator.Create(command).Execute(commandArguments);
                return(exitCode);
            }
            catch (OptionException ex)
            {
                WriteError(ex);
                locator.Create(locator.Find("help")).Execute(new[] { commandName });
                return(4);
            }
            catch (ArgumentException ex)
            {
                WriteError(ex);
                return(4);
            }
            catch (FileNotFoundException ex)
            {
                WriteError(ex);
                return(4);
            }
            catch (InvalidDataException ex)
            {
                WriteError(ex);
                return(2);
            }
            catch (IOException ex)
            {
                WriteError(ex, details: true);
                return(1);
            }
            catch (Exception ex)
            {
                WriteError(ex, details: true);
                return(3);
            }
        }
Beispiel #8
0
        private static MemoryStream ConstructOctodiffCmd(string cmdName, string[] args, MemoryStream ms = null)
        {
            // Setup Octodiff command
            var          sb        = new StringBuilder();
            var          cl        = new CommandLocator();
            var          command   = cl.Find(cmdName);
            MemoryStream sigStream = null;

            // Parse commands
            foreach (string arg in args)
            {
                sb.Append(arg != "" ? arg + " " : "");
            }

            try
            {
                // Execute octodiff command
                Log.Info("Octodiff --" + cmdName + " " + sb.ToString());
                sigStream = cl.Create(command).Execute(args, ms);

                return(sigStream);
            }
            catch (OptionException ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }
            catch (UsageException ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }
            catch (FileNotFoundException ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }
            catch (CorruptFileFormatException ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }
            catch (IOException ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }
            catch (Exception ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }

            return(null);
        }
Beispiel #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void printsAvailableCommandsWhenUnknownCommandIsProvided()
        internal virtual void PrintsAvailableCommandsWhenUnknownCommandIsProvided()
        {
            CommandLocator commandLocator = mock(typeof(CommandLocator));
            IList <AdminCommand_Provider> mockCommands = new IList <AdminCommand_Provider> {
                MockCommand("foo"), MockCommand("bar"), MockCommand("baz")
            };

            when(commandLocator.AllProviders).thenReturn(mockCommands);
            when(commandLocator.FindProvider("foobar")).thenThrow(new NoSuchElementException("foobar"));

            HelpCommand helpCommand = new HelpCommand(mock(typeof(Usage)), @out, commandLocator);

            IncorrectUsage incorrectUsage = assertThrows(typeof(IncorrectUsage), () => helpCommand.execute("foobar"));

            assertThat(incorrectUsage.Message, containsString("Available commands are: foo bar baz"));
        }
Beispiel #10
0
        //usage
        // j command args
        // j -add:command -repath:false -arg:% <COMMAND TO RUN>
        // j -remove:command
        // j -list
        static void Main(string[] args)
        {
            //make sure the previous version is gone
            if (File.Exists(JumperSettings.BATFile))
                File.Delete(JumperSettings.BATFile);

            //verify the shortu
            JumperSettings.VerifyJumpBatFile();

            //execute the app as required
            var settings = JumperSettings.Load();
            var reader = new ArgumentReader(args);
            var locator = new CommandLocator(settings, reader);
            var command = locator.CreateCommand();
            command.Run();
        }
Beispiel #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testAdminUsage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void TestAdminUsage()
        {
            CommandLocator commandLocator = mock(typeof(CommandLocator));
            IList <AdminCommand_Provider> mockCommands = new IList <AdminCommand_Provider> {
                MockCommand("foo"), MockCommand("bar"), MockCommand("baz")
            };

            when(commandLocator.AllProviders).thenReturn(mockCommands);

            using (MemoryStream baos = new MemoryStream())
            {
                PrintStream ps = new PrintStream(baos);

                Usage usage = new Usage("neo4j-admin", commandLocator);

                HelpCommand helpCommand = new HelpCommand(usage, ps.println, commandLocator);

                helpCommand.Execute();

                assertEquals(string.Format("usage: neo4j-admin <command>%n" + "%n" + "Manage your Neo4j instance.%n" + "%n" + "environment variables:%n" + "    NEO4J_CONF    Path to directory which contains neo4j.conf.%n" + "    NEO4J_DEBUG   Set to anything to enable debug output.%n" + "    NEO4J_HOME    Neo4j home directory.%n" + "    HEAP_SIZE     Set JVM maximum heap size during command execution.%n" + "                  Takes a number and a unit, for example 512m.%n" + "%n" + "available commands:%n" + "%n" + "General%n" + "    bar%n" + "        null%n" + "    baz%n" + "        null%n" + "    foo%n" + "        null%n" + "%n" + "Use neo4j-admin help <command> for more details.%n"), baos.ToString());
            }
        }
Beispiel #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void showsArgumentsAndDescriptionForSpecifiedCommand() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShowsArgumentsAndDescriptionForSpecifiedCommand()
        {
            CommandLocator        commandLocator  = mock(typeof(CommandLocator));
            AdminCommand_Provider commandProvider = mock(typeof(AdminCommand_Provider));

            when(commandProvider.Name()).thenReturn("foobar");
            Arguments arguments = (new Arguments()).withDatabase();

            when(commandProvider.AllArguments()).thenReturn(arguments);
            when(commandProvider.PossibleArguments()).thenReturn(Collections.singletonList(arguments));
            when(commandProvider.Description()).thenReturn("This is a description of the foobar command.");
            when(commandLocator.FindProvider("foobar")).thenReturn(commandProvider);

            using (MemoryStream baos = new MemoryStream())
            {
                PrintStream ps = new PrintStream(baos);

                HelpCommand helpCommand = new HelpCommand(new Usage("neo4j-admin", commandLocator), ps.println, commandLocator);
                helpCommand.Execute("foobar");

                assertEquals(string.Format("usage: neo4j-admin foobar [--database=<name>]%n" + "%n" + "environment variables:%n" + "    NEO4J_CONF    Path to directory which contains neo4j.conf.%n" + "    NEO4J_DEBUG   Set to anything to enable debug output.%n" + "    NEO4J_HOME    Neo4j home directory.%n" + "    HEAP_SIZE     Set JVM maximum heap size during command execution.%n" + "                  Takes a number and a unit, for example 512m.%n" + "%n" + "This is a description of the foobar command.%n" + "%n" + "options:%n" + "  --database=<name>   Name of database. [default:" + GraphDatabaseSettings.DEFAULT_DATABASE_NAME + "]%n"), baos.ToString());
            }
        }
Beispiel #13
0
 public void GivenACommandLocator()
 {
     CommandLocator = new CommandLocator(ModuleManager, new ClientInformation {
         CurrentConnection = ClientConnection
     });
 }
Beispiel #14
0
 public Usage(string scriptName, CommandLocator commands)
 {
     this._scriptName = scriptName;
     this._commands   = commands;
 }
Beispiel #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            _usageCmd = new Usage(AdminTool.SCRIPT_NAME, CommandLocator.fromServiceLocator());
        }
Beispiel #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Override @Nonnull public AdminCommand create(java.nio.file.Path homeDir, java.nio.file.Path configDir, OutsideWorld outsideWorld)
        public override AdminCommand Create(Path homeDir, Path configDir, OutsideWorld outsideWorld)
        {
            return(new HelpCommand(_usage, outsideWorld.stdOutLine, CommandLocator.fromServiceLocator()));
        }
Beispiel #17
0
 internal HelpCommand(Usage usage, System.Action <string> output, CommandLocator locator)
 {
     this._usage   = usage;
     this._output  = output;
     this._locator = locator;
 }