public Func <int> RunConsoleModeCommand(string[] lines, bool inputIsFromUser, ConsoleCommand command, TextWriter outputWriter = null) { var injectedInputStream = new MemoryStream(); var fakeConsoleWriter = outputWriter ?? new StringWriter(); var fakeConsoleReader = new StreamReader(injectedInputStream); var consoleModeCommand = new ConsoleModeCommand( () => new ConsoleCommand[] { command }, fakeConsoleWriter, fakeConsoleReader); arrange(delegate { var injectedInput = new StreamWriter(injectedInputStream); foreach (var line in lines) { injectedInput.WriteLine(line); } injectedInput.Flush(); injectedInputStream.Seek(0, SeekOrigin.Begin); }); IConsoleRedirectionDetection redirectionDetection = A.Fake <IConsoleRedirectionDetection>(); arrange(() => consoleModeCommand.SetConsoleRedirectionDetection(redirectionDetection)); arrange(() => A.CallTo(() => redirectionDetection.IsInputRedirected()).Returns(!inputIsFromUser)); return(() => ConsoleCommandDispatcher.DispatchCommand(new ConsoleCommand[] { consoleModeCommand }, new string[0], fakeConsoleWriter)); }
static void Main(string[] args) { var processed = false; Console.Write("Initializing ChronoSpark Time Manager..."); SparkLogic.Initialize(); Console.WriteLine("DONE!"); while (!processed)//!exit { Console.Write("ChronoSpark => "); processed = false; var cmd = "run-console"; ReminderControl defaultController = new ReminderControl(); NoActiveTaskListener noActiveTaskListener = new NoActiveTaskListener(); IntervalPassedListener intervalPassedListener = new IntervalPassedListener(); TimeToReportListener timeToReportListener = new TimeToReportListener(); noActiveTaskListener.Suscribe(defaultController); intervalPassedListener.Suscribe(defaultController); timeToReportListener.Suscribe(defaultController); ThreadPool.QueueUserWorkItem(delegate { defaultController.ActivateReminders(); }); String[] cdmArgs = cmd.Split(' '); var commands = GetCommands(); ConsoleModeCommand consoleRunner = new ConsoleModeCommand(GetCommands); commands = commands.Concat(new[] { consoleRunner }); ConsoleCommandDispatcher.DispatchCommand(commands, cdmArgs, Console.Out); processed = true; } }
public Func<int> RunConsoleModeCommand(string[] lines, bool inputIsFromUser, TextWriter outputWriter = null) { var injectedInputStream = new MemoryStream(); var fakeConsoleWriter = outputWriter ?? new StringWriter(); var fakeConsoleReader = new StreamReader(injectedInputStream); var consoleModeCommand = new ConsoleModeCommand( () => new ConsoleCommand[] {new Should_fail_strictly_on_error_when_running_noninteractive.StatusEchoCommand()}, fakeConsoleWriter, fakeConsoleReader); arrange(delegate { var injectedInput = new StreamWriter(injectedInputStream); foreach (var line in lines) injectedInput.WriteLine(line); injectedInput.Flush(); injectedInputStream.Seek(0, SeekOrigin.Begin); }); IConsoleRedirectionDetection redirectionDetection = A.Fake<IConsoleRedirectionDetection>(); arrange(() => consoleModeCommand.SetConsoleRedirectionDetection(redirectionDetection)); arrange(() => A.CallTo(() => redirectionDetection.IsInputRedirected()).Returns(!inputIsFromUser)); return () => ConsoleCommandDispatcher.DispatchCommand(new ConsoleCommand[] {consoleModeCommand}, new string[0], fakeConsoleWriter); }
private static int Main(string[] args) { Console.WriteLine("JSONList version {0} by [email protected]", GetVersion()); var commands = GetCommands(); var consoleRunner = new ConsoleModeCommand(GetCommands); commands = commands.Concat(new[] { consoleRunner }); return(ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out)); }
static int Main(string[] args) { // Locate commands avaiable var commands = GetCommands(); // Allows to execute commands from an internal console ConsoleModeCommand consoleRunner = new ConsoleModeCommand(GetCommands); commands = commands.Concat(new[] { consoleRunner }); // Run the command for the console input return(ConsoleCommandDispatcher.DispatchCommand(commands, args, System.Console.Out)); }
static int Main(string[] args) { // locate any commands in the assembly (or use an IoC container, or whatever source) var commands = GetCommands(); // optionally, include ConsoleModeCommand if you want to allow the user to run // commands from the console. ConsoleModeCommand consoleRunner = new ConsoleModeCommand(GetCommands); commands = commands.Concat(new[] { consoleRunner }); // run the command for the console input return(ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out)); }