Example #1
0
 static void Main(string[] args)
 {
     using (var s = new ConsoleTest2Shell())
     {
         ConsoleShell.Start <MainController>(s);
     }
 }
Example #2
0
        /// <inheritdoc />
        public override void ExecuteCommand(ICommonSession?session, string command)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                return;
            }

            // echo the command locally
            WriteLine(null, "> " + command);

            //Commands are processed locally and then sent to the server to be processed there again.
            var args = new List <string>();

            CommandParsing.ParseArguments(command, args);

            var commandName = args[0];

            if (AvailableCommands.ContainsKey(commandName))
            {
                var command1 = AvailableCommands[commandName];
                args.RemoveAt(0);
                var shell   = new ConsoleShell(this, null);
                var cmdArgs = args.ToArray();

                AnyCommandExecuted?.Invoke(shell, commandName, command, cmdArgs);
                command1.Execute(shell, command, cmdArgs);
            }
            else
            {
                WriteError(null, "Unknown command: " + commandName);
            }
        }
Example #3
0
        public void Setup()
        {
            projectBuilder    = MockRepository.GenerateStub <IProjectBuilder>();
            ftpSessionFactory = MockRepository.GenerateMock <IFtpSessionFactory>();

            consoleEnv = new ConsoleShell("x");

            cmd = new DeployCommand(projectBuilder, ftpSessionFactory);
        }
Example #4
0
        public void Setup()
        {
            fileSystem       = MockRepository.GenerateMock <IFileSystem>();
            projectBuilder   = MockRepository.GenerateMock <IProjectBuilder>();
            textParser       = MockRepository.GenerateMock <IFreudeTextParser>();
            templatingEngine = MockRepository.GenerateMock <IFreudeTemplatingEngine>();
            consoleEnv       = new ConsoleShell("x");

            cmd = new BuildCommand(fileSystem, projectBuilder, textParser, templatingEngine);
        }
Example #5
0
        public static void Main(string[] args)
        {
            var unicodeEncoding = new UnicodeEncoding(!BitConverter.IsLittleEndian, false);

            Console.InputEncoding  = unicodeEncoding;
            Console.OutputEncoding = unicodeEncoding;
            // preventing a deadlock http://blogs.microsoft.co.il/blogs/dorony/archive/2012/09/12/console-readkey-net-4-5-changes-may-deadlock-your-system.aspx
            Console.Out.Flush();
            Console.Error.Flush();

            Options options;

            if (args.Length > 0)
            {
                if (args[0].Length < 2)
                {
                    throw new ArgumentException("Argument 0 (" + args[0] + ") is not long enough (>= 2)!", "args");
                }

                switch (args[0][0])
                {
                case '-':
                case '/':
                    options = Options.ParseFirstOption(args[0].Substring(1));
                    break;

                default:
                    throw new ArgumentException("Argument 0 (" + args[0] + ") is not a command option!", "args");
                }
            }
            else
            {
                options = Options.Default;
            }

            switch (options.StartupCommand)
            {
            case Options.Command.Install:
                using (var installer = new Installer())
                {
                    Task.WaitAll(installer.Execute());
                }
                break;
            }

            if (options.StartCLI)
            {
                var shell = new ConsoleShell();
                Task.WaitAll(shell.ReadConsole());
            }
        }
Example #6
0
        public static int Main(string[] args)
        {
            Stopwatch commandStopwatch = new Stopwatch();

            commandStopwatch.Start();

            XmlConfigurator.Configure();

            IRazorCompiler razorCompiler = new InMemoryRazorCompiler();

            IFileSystem fileSystem = new WindowsFileSystem();
            //IFtpChannelFactory ftpChannelFactory = new FtpChannelFactoryUsingSockets ();
            //IFtpCommunicator ftpCommunicator = new FtpCommunicator ();
            //IFtpSessionFactory ftpSessionFactory = new FtpSessionFactory(ftpChannelFactory, ftpCommunicator, fileSystem);
            IFreudeTemplatingEngine freudeTemplatingEngine = new FreudeTemplatingEngine(razorCompiler);
            IWikiTextTokenizer      wikiTextTokenizer      = new WikiTextTokenizer();
            IFreudeTextParser       freudeTextParser       = new FreudeTextParser(wikiTextTokenizer);
            IProjectBuilder         projectBuilder         = new ProjectBuilder(fileSystem);

            ConsoleShell consoleShell = new ConsoleShell("Freude.Engine.exe");

            consoleShell.RegisterCommand(new BuildCommand(fileSystem, projectBuilder, freudeTextParser, freudeTemplatingEngine));
            //consoleShell.RegisterCommand (new DeployCommand(projectBuilder, ftpSessionFactory));

            try
            {
                ConsoleShellResult consoleShellResult = consoleShell.ParseCommandLine(args);

                if (consoleShellResult.ExitCode.HasValue)
                {
                    return(consoleShellResult.ExitCode.Value);
                }

                foreach (IConsoleCommand consoleCommand in consoleShellResult.CommandsToExecute)
                {
                    consoleCommand.Execute(consoleShell);
                }

                TimeSpan elapsed = commandStopwatch.Elapsed;
                log.InfoFormat("Command done in {0}", elapsed);

                return(0);
            }
            catch (Exception ex)
            {
                log.Fatal("Program failed", ex);
                return(1);
            }
        }
Example #7
0
        public int Run(AgentRequest request)
        {
            var arguments = BuildPowerShellArguments(request);

            RunspaceConfiguration configuation;

            if (String.IsNullOrEmpty(request.PSConsoleFile))
            {
                configuation = RunspaceConfiguration.Create();
            }
            else
            {
                configuation = RunspaceConfiguration.Create(request.PSConsoleFile);
            }

            return(ConsoleShell.Start(configuation, null, null, arguments));
        }
Example #8
0
        /// <summary>
        /// Implements the application's entry point.
        /// </summary>
        /// <param name="args">The application's command line arguments.</param>
        /// <returns>The application's exit code.</returns>
        public static int Main(string[] args)
        {
            using (var snapIn = new OrchardPsSnapIn())
            {
                RunspaceConfiguration configuration;
                try
                {
                    configuration = RunspaceConfiguration.Create();

                    foreach (ProviderConfigurationEntry provider in snapIn.Providers)
                    {
                        configuration.Providers.Append(provider);
                    }

                    foreach (CmdletConfigurationEntry cmdlet in snapIn.Cmdlets)
                    {
                        configuration.Cmdlets.Append(cmdlet);
                    }

                    foreach (FormatConfigurationEntry format in snapIn.Formats)
                    {
                        configuration.Formats.Append(format);
                    }

                    configuration.InitializationScripts.Append(
                        new ScriptConfigurationEntry(
                            "NavigateToOrchardDrive",
                            "if (Test-Path Orchard:) { Set-Location Orchard: }"));

                    foreach (KeyValuePair <string, string> alias in snapIn.Aliases)
                    {
                        configuration.InitializationScripts.Append(
                            new ScriptConfigurationEntry(
                                "Alias-" + alias.Key,
                                "New-Alias '" + alias.Key + "' " + alias.Value));
                    }
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Failed to create runspace configuration. " + ex.Message);
                    return(-1);
                }

                return(ConsoleShell.Start(configuration, GetBanner(), string.Empty, args));
            }
        }
Example #9
0
        /// <summary>
        /// Runs the wizard in a console
        /// </summary>
        public async Task RunInConsole(ConsoleShell shell, bool reportErrorsToConsole = false)
        {
            foreach (var item in Steps)
            {
                CurrentStep = item; // In case any event handlers are listening

                ConsoleWriteLine(CurrentStepDisplayName);
                var command = CurrentStep.GetConsoleCommand();
                if (command != null)
                {
                    await shell.RunCommand(command, Enumerable.Empty <string>(), reportErrorsToConsole);
                }
                else
                {
                    ConsoleWriteLine(Properties.Resources.Wizard_Console_NullCommand);
                }
                ConsoleWriteLine("");
            }
        }
Example #10
0
        /// <inheritdoc />
        public override void ExecuteCommand(ICommonSession?session, string command)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                return;
            }

            // echo the command locally
            WriteLine(null, "> " + command);

            //Commands are processed locally and then sent to the server to be processed there again.
            var args = new List <string>();

            CommandParsing.ParseArguments(command, args);

            var commandName = args[0];

            if (AvailableCommands.ContainsKey(commandName))
            {
                var playerManager = IoCManager.Resolve <IPlayerManager>();
#if !DEBUG
                if (!_conGroup.CanCommand(commandName) && playerManager.LocalPlayer?.Session.Status > SessionStatus.Connecting)
                {
                    WriteError(null, $"Insufficient perms for command: {commandName}");
                    return;
                }
#endif
                var command1 = AvailableCommands[commandName];
                args.RemoveAt(0);
                var shell   = new ConsoleShell(this, null);
                var cmdArgs = args.ToArray();

                AnyCommandExecuted?.Invoke(shell, commandName, command, cmdArgs);
                command1.Execute(shell, command, cmdArgs);
            }
            else
            {
                WriteError(null, "Unknown command: " + commandName);
            }
        }
Example #11
0
        public void Setup()
        {
            outStream = new MemoryStream();
            errStream = new MemoryStream();

            shell           = new ConsoleShell("unittest.exe");
            shell.OutWriter = new StreamWriter(outStream, new UTF8Encoding(false));
            shell.ErrWriter = new StreamWriter(errStream, new UTF8Encoding(false));
            shell.Banner    = "Unit test console";

            IConsoleCommand mockCommand = MockRepository.GenerateStub <IConsoleCommand>();

            mockCommand.Stub(x => x.CommandId).Return("cmd1");
            mockCommand.Stub(x => x.Description).Return("performs action 1");
            mockCommand.Stub(x => x.ConstructUsageHelpText(null)).IgnoreArguments()
            .Return(@"   something to be used
   bla bla");

            shell.RegisterCommand(mockCommand);

            TestStandardConsoleCommand cmd2 = new TestStandardConsoleCommand();

            shell.RegisterCommand(cmd2);
        }
Example #12
0
 public AgateEmergencyVocabulary(ConsoleShell agateConsoleCore)
 {
     this.agateConsoleCore = agateConsoleCore;
 }
Example #13
0
 static void Main(string[] args)
 {
     ConsoleShell.Start <MainController>(new ConsoleTest1Shell());
 }
Example #14
0
        public static void TestConsoleShellScenario()
        {
            int ret = ConsoleShell.Start("Hello", string.Empty, new string[] { "-noprofile", "-c", "exit 42" });

            Assert.Equal(42, ret);
        }
Example #15
0
        public async Task TestConsoleCommand2Test()
        {
            using (var manager = new PluginManager())
            {
                using (var appViewModel = new ApplicationViewModel(manager))
                {
                    await manager.LoadCore(new BasicTestCoreMod());

                    var command = manager.CreateInstance <TestConsoleCommand2>();

                    Assert.AreEqual("True%narguments%ntest%nstandard%nin%n".Replace("%n", Environment.NewLine), ConsoleShell.TestConsoleCommand(command, appViewModel, new string[] { "test", "arguments" }, "standard\nin").Result);
                }
            }
        }