/// <summary>
 /// Creates a new instance of the core. Ideally this should be created by Ninject to ensure all dependencies are handled appropriately.
 /// Note: A TerminalBindings class lives in the Terminal.Core.Ninject.BindingModules namespace. Use this when building your Ninject kernel to ensure proper dependency injection.
 /// 
 /// Sampel: IKernel kernel = new StandardKernel(new TerminalBindings());
 /// </summary>
 /// <param name="commands">A list of all commands available to the application.</param>
 /// <param name="userRepository">The user repository used to retrieve the current user from the database.</param>
 public TerminalApi(List<ICommand> commands, IDataBucket dataBucket)
 {
     _commands = commands;
     _dataBucket = dataBucket;
     _commandContext = new CommandContext();
     TerminalEvents = new TerminalEvents();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Examine command result and perform relevant actions.
        /// </summary>
        /// <param name="commandResult">The command result returned by the terminal core.</param>
        private static void InterpretResult(CommandResult commandResult)
        {
            // Set the terminal core command context to the one returned in the result so that it can be passed
            // in again on the next API request. This maintains certain state information.
            _commandContext = commandResult.CommandContext;

            // If the result calls for the screen to be cleared, clear it.
            if (commandResult.ClearScreen)
                Console.Clear();

            // Set the terminal core current user to the one returned in the result and display the username in the console title bar.
            _username = commandResult.CurrentUser != null ? commandResult.CurrentUser.Username : null;
            Console.Title = commandResult.TerminalTitle;

            // Add a blank line to the console before displaying results.
            if (commandResult.DisplayItems.Count > 0)
                Console.WriteLine();

            // Iterate over the display collection and perform relevant display actions based on the type of the object.
            foreach (var displayInstruction in commandResult.DisplayItems)
                Display(displayInstruction);

            if (!commandResult.EditText.IsNullOrEmpty())
                SendKeys.SendWait(commandResult.EditText.Replace("\n", "--"));

            // If the terminal is prompting for a password then set the global PasswordField bool to true.
            _passwordField = commandResult.PasswordField;

            // If the terminal is asking to be closed then kill the runtime loop for the console.
            _appRunning = !commandResult.Exit;
        }