void Execute(string userInput) { State = ExecutionState.Running; CommandInvocation _currentInvocation = new CommandInvocation(userInput); if (commands.ContainsKey(_currentInvocation.FingerPrint)) { try { commands[_currentInvocation.FingerPrint].Execute(_currentInvocation, this); } catch (Exception _exc) { MainOutput.Enqueue(_exc.Message.Decorat("language", "english"), OutputLevel.Error); if (!SuppressExceptions) { throw; } } } else { PropertyDecorator <string> _message = new PropertyDecorator <string>( "The command-fingerprint \"{0}\" is undefined in the current context.".LegacyForm(( object )userInput)); _message.Set("language", "english"); SystemOutput.Enqueue( new CommandOutput( OutputLevel.Error, _message, DateTime.Now)); } State = ExecutionState.Idle; }
Context( ) { SuppressExceptions = true; MainOutput.NewOutputReceived += collector_NewOutputReceived; SystemOutput.NewOutputReceived += collector_NewOutputReceived; MainInput.NewInputLineAdded += collector_NewInputReceived; MainInput.CurrentLineChanged += MainInput_CurrentLineChanged; MainInput.KeyPressed += MainInput_KeyPressed; Define( "do nothing", (_invocation, _context) => { #region PropertyDecorator <string> _message = new PropertyDecorator <string>("I didn't do anything."); _message.Set("language", "english"); _context.MainOutput.Enqueue( new CommandOutput( OutputLevel.Information, _message, DateTime.Now)); #endregion }); Define("help", (_invocation, _context) => { #region PropertyDecorator <string> _message = new PropertyDecorator <string>( "There is {0} command defined in this context.".LegacyForm(_context.commands.Count( ))); _message.Set("language", "english"); _context.MainOutput.Enqueue( new CommandOutput( OutputLevel.Information, _message, DateTime.Now)); _message = new PropertyDecorator <string>( "The first 10 command defined in this context."); _message.Set("language", "english"); _context.MainOutput.Enqueue( new CommandOutput( OutputLevel.Information, _message, DateTime.Now)); var _orderedCommand = _context.commands.OrderBy(_e => _e.Value.FingerPrint); foreach (KeyValuePair <string, Command> _commandDefinition in _orderedCommand.Take(10)) { _context.MainOutput.Enqueue(_commandDefinition.Value.FingerPrint.DecoratAsEnglish( )); } _message = new PropertyDecorator <string>( "Use command ,,list commands from::th to::th'' for more."); _message.Set("language", "english"); _context.MainOutput.Enqueue( new CommandOutput( OutputLevel.Information, _message, DateTime.Now)); _message = new PropertyDecorator <string>( "Use command ,,describe ::command'' for help about commands."); _message.Set("language", "english"); _context.MainOutput.Enqueue( new CommandOutput( OutputLevel.Information, _message, DateTime.Now)); #endregion }); Define("list commands from::th to::th", (_invocation, _context) => { #region int _from = int.Parse(_invocation["from:th"].Value); int _to = int.Parse(_invocation["to:th"].Value); PropertyDecorator <string> _message = new PropertyDecorator <string>( "Commands from {0} to {1} are the followings.".LegacyForm(_from, _to)); _message.Set("language", "english"); _context.MainOutput.Enqueue( new CommandOutput( OutputLevel.Information, _message, DateTime.Now)); var _orderedCommand = _context.commands.OrderBy(_e => _e.Value.FingerPrint); StringBuilder _listOfCommands = new StringBuilder( ); for (int _index = _from; _index < _to; _index++) { _context.MainOutput.Enqueue( _orderedCommand.ElementAt(_index).Value.FingerPrint.DecoratAsEnglish( )); } #endregion }); Define( "execute from::", (_invocation, _context) => { #region string _path = _invocation[@"^from$:"].Value; var _inputLines = loadFile(_path); MainOutput.Enqueue( "Totaly {0} input lines loaded. Start execution now.".LegacyForm(_inputLines.Count( )).DecoratAsEnglish( )); MainInput.AddRange(_inputLines); #endregion }); Define( "wait for::milliseconds", (_invocation, _context) => { #region int _timeout = int.Parse(_invocation[@"^for$:^milliseconds$"].Value); _context.MainOutput.Enqueue( "Waiting for {0} milliseconds.".LegacyForm(_timeout).DecoratAsEnglish( )); Thread.Sleep(_timeout); #endregion }); Define( "label as::", (_invocation, _context) => _context.MainOutput.Enqueue( _invocation[@"^as$:"].Value.DecoratAsEnglish( ), OutputLevel.Note)); }