Exemplo n.º 1
0
        protected override void Executed(Params args, IConsoleOutput target)
        {
            Command[] enabledCommands = AllCommandsInternal.Where(i => i.IsEnabled).ToArray();

            if (args.Count == 0)
            {
                Executed(new Params(new string[] { 1.ToString() }), target);
                return;
            }

            if (args.IsInteger(0))
            {
                target.WriteLine("Listing commands at page " + args.ToInt(0) + " of " + GetPageCount());

                for (int i = (args.ToInt(0) - 1) * 5; i < (args.ToInt(0) - 1) * 5 + 5 && i < enabledCommands.Length; i++)
                {
                    target.WriteLine("* " + enabledCommands[i].Name + ": " + enabledCommands[i].HelpDescription);
                }
            }
            else
            {
                Command cmd = GetByName(args.JoinEnd(0));

                target.WriteLine(cmd.Name);
                target.WriteLine("* " + cmd.HelpDescription);

                string sstring = cmd.GetSyntax(new Params(new string[0])).CreateSyntaxString();
                target.WriteWarning("* Syntax: ");

                foreach (string i in sstring.Split('\n'))
                {
                    target.WriteWarning("*   " + i);
                }
            }
        }
Exemplo n.º 2
0
        protected override void Executed(Params args, IConsoleOutput target)
        {
            switch (args[1])
            {
            case "+":
                target.WriteLine(args.ToDouble(0) + args.ToDouble(2));
                break;

            case "-":
                target.WriteLine(args.ToDouble(0) - args.ToDouble(2));
                break;

            case "*":
                target.WriteLine(args.ToDouble(0) * args.ToDouble(2));
                break;

            case "/":
                if (args.ToInt(2) == 0)
                {
                    ThrowGenericError("Attempted division by zero", ErrorCode.NUMBER_IS_ZERO);
                }

                target.WriteLine(args.ToDouble(0) / args.ToDouble(2));
                break;

            case "%":
                target.WriteLine(args.ToDouble(0) % args.ToDouble(2));
                break;

            default:
                ThrowArgumentError(args[1], new string[] { "+", "-", "*", "/" }, ErrorCode.ARGUMENT_UNLISTED);
                break;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Executes a console command as C# script.
        /// </summary>
        /// <param name="output">Console output buffer to append any output messages.</param>
        /// <param name="command">Command to execute.</param>
        public void Execute(IConsoleOutput output, string command)
        {
            if (EchoEnabled)
            {
                output.Append(command);
            }


            if (!_warmupTask.IsCompleted)
            {
                _warmupTask.Wait();
            }

            Task.Run(async() =>
            {
                try
                {
                    _executionSignal.WaitOne(); // TODO: timeout

                    _scriptState = await _scriptState.ContinueWithAsync(command, ScriptOptions);
                    if (_scriptState.ReturnValue != null)
                    {
                        output.Append(_scriptState.ReturnValue.ToString());
                    }
                }
                catch (CompilationErrorException e)
                {
                    output.Append(string.Join(Environment.NewLine, e.Diagnostics));
                }
                finally
                {
                    _executionSignal.Set();
                }
            });
        }
        public void OnExecuteAsync_Should_NotThrow(
            IConsoleOutput console,
            IAutoRestOptions options,
            IProcessLauncher processLauncher,
            IProgressReporter progressReporter,
            IAutoRestCodeGeneratorFactory factory,
            ICodeGenerator generator,
            IOpenApiDocumentFactory documentFactory,
            string outputFile,
            string code)
        {
            var sut = new AutoRestCommand(
                console,
                options,
                processLauncher,
                progressReporter,
                factory,
                documentFactory)
            {
                OutputFile = outputFile
            };

            Mock.Get(generator).Setup(c => c.GenerateCode(progressReporter)).Returns(code);
            new Func <Task>(sut.OnExecuteAsync).Should().NotThrow();
        }
 public async Task OnExecuteAsync_Should_Create_Generator(
     IConsoleOutput console,
     IAutoRestOptions options,
     IProcessLauncher processLauncher,
     IProgressReporter progressReporter,
     IAutoRestCodeGeneratorFactory factory,
     IOpenApiDocumentFactory documentFactory,
     string swaggerFile)
 => await new AutoRestCommand(
     console,
     options,
     processLauncher,
     progressReporter,
     factory,
     documentFactory)
 {
     SwaggerFile = swaggerFile
 }
 .OnExecuteAsync()
 .ContinueWith(
     t => Mock.Get(factory)
     .Verify(
         c => c.Create(
             swaggerFile,
             "GeneratedCode",
             options,
             processLauncher,
             documentFactory)));
Exemplo n.º 6
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <param name="arguments">Arguments to pass to the command</param>
        /// <param name="target">Writable console target</param>
        public int Execute(IEnumerable <string> arguments, IConsoleOutput target)
        {
            try
            {
                //If the user attempt to use commands like  if, while and for outside a script context
                if (IsCodeBlockCommand() && !(target is ScriptTargetWrapper))
                {
                    ThrowGenericError("This command can only be used in script files", ErrorCode.INVALID_CONTEXT);
                }

                Params p = new Params(arguments);
                GetSyntax(p).IsCorrectSyntax(this, p, true);

                Executed(p, target);
                return(0);
            }
            catch (CommandException x)
            {
                foreach (string i in x.Message.Split('\n'))
                {
                    target.WriteError(i);
                }

                return(x.ErrorCode);
            }
        }
Exemplo n.º 7
0
        public override Task <bool> TryExecuteAsync(string text, IConsoleOutput output)
        {
            var parser = new CommandTextParser();

            text = Preprocess(text);

            string name;
            var    options   = new Collection <Tuple <string, string> >();
            var    arguments = new Collection <string>();

            if (!parser.Parse(text, out name, options, arguments))
            {
                throw new Exception();
            }

            foreach (var command in Commands)
            {
                if (!comparer.Equals(command.CommandName, name))
                {
                    continue;
                }

                if (ValidateCommand(command, options, arguments))
                {
                    return(command.ExecuteAsync(output, options, arguments));
                }
            }

            return(Task.FromResult(false));
        }
Exemplo n.º 8
0
 public ExecuteConsoleCommandEventArgs(IConsoleOutput console, ICollection <Task> promises, ICollection <Tuple <string, string> > options, ICollection <string> arguments)
 {
     this.promises = promises;
     Console       = console;
     Options       = options;
     Arguments     = arguments;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Basic constructor.
 /// </summary>
 /// <param name="consoleOutput">Interface for interacting with the output
 /// console.</param>
 /// <param name="buffer">Console input buffer to use.</param>
 /// <param name="history">Console history object to use.</param>
 /// <param name="completionHandler">Optionally provides completion
 /// handler.</param>
 public ConsoleLineInput(IConsoleOutput consoleOutput, IConsoleInputBuffer buffer, IConsoleHistory history, ConsoleCompletionHandler completionHandler)
 {
     ConsoleOutput     = consoleOutput;
     Buffer            = buffer;
     History           = history;
     CompletionHandler = completionHandler;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Basic constructor.
 /// </summary>
 /// <param name="consoleOutput">Interface for interacting with the output
 /// console.</param>
 /// <param name="buffer">Console input buffer to use.</param>
 /// <param name="history">Console history object to use.</param>
 /// <param name="completionHandler">Optionally provides completion
 /// handler.</param>
 public ConsoleLineInput(IConsoleOutput consoleOutput, IConsoleInputBuffer buffer, IConsoleHistory history, ConsoleCompletionHandler completionHandler)
 {
     ConsoleOutput = consoleOutput;
     Buffer = buffer;
     History = history;
     CompletionHandler = completionHandler;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConsoleOutputFileDiscoveryStatusObserver"/> class.
 /// </summary>
 /// <param name="consoleOutput">The console output.</param>
 /// <param name="fileDiscoveryStatusInterpretationStrategyFactory">
 /// The file discovery status interpretation strategy factory.
 /// </param>
 public ConsoleOutputFileDiscoveryStatusObserver(
     IConsoleOutput consoleOutput,
     IFileDiscoveryStatusInterpretationStrategyFactory fileDiscoveryStatusInterpretationStrategyFactory)
 {
     this.consoleOutput = consoleOutput;
     this.fileDiscoveryStatusInterpretationStrategyFactory = fileDiscoveryStatusInterpretationStrategyFactory;
 }
Exemplo n.º 12
0
 public BufferedConsoleOutput(int width, int height, IConsoleOutput consoleOutput)
 {
     _height = height;
     _consoleOutput = consoleOutput;
     _backBuffer = new ConsoleBuffer(width, height, _consoleOutput.DefaultForegroundColor, _consoleOutput.DefaultBackgroundColor);
     _frontBuffer = new ConsoleBuffer(width, height, _consoleOutput.DefaultForegroundColor, _consoleOutput.DefaultBackgroundColor);
 }
Exemplo n.º 13
0
 public DeleteOperationBase(IConsoleOutput output, IFileSystem fs, IRecycleBin recycleBin, ILogger logger)
     : base(output)
 {
     FileSystem  = fs;
     _recycleBin = recycleBin;
     _logger     = logger;
 }
        public void Setup()
        {
            //Set up S's
            fakeConsoleOutput = Substitute.For <IConsoleOutput>();
            fakeFileOutput    = Substitute.For <IFileOutput>();

            //Set up X's
            airspace   = new Airspace(10000, 90000, 10000, 90000, 500, 20000);
            trackData1 = new TrackData("ABC123", 30000, 30000, 3000, "20181224200050123", 100, 45, fakeConsoleOutput);
            trackData2 = new TrackData("DEF123", 30001, 30001, 3001, "20181224200050123", 100, 45, fakeConsoleOutput);

            trackData3 = new TrackData("ABC123", 30000, 30000, 3000, "20181224200050123", 100, 45, fakeConsoleOutput);
            trackData4 = new TrackData("DEF123", 50000, 50000, 5000, "20181224200050123", 100, 45, fakeConsoleOutput);

            //Fake transponderReceiver
            fakeTransponderReceiver = Substitute.For <ITransponderReceiver>();

            //Create new ATM.TransponderReceiver for simulating inputs from the TransponderReceiver from the dll.
            transponderReceiver = new TransponderReceiver(fakeTransponderReceiver, fakeConsoleOutput);

            //Set up T's
            ATM = new ATMclass(fakeConsoleOutput, fakeFileOutput, airspace, fakeTransponderReceiver);

            //Attach ATM, so that updates to the transponderReceiver updates data in the ATM
            transponderReceiver.Attach(ATM);
        }
Exemplo n.º 15
0
        public void OnExecuteAsync_Should_NotThrow(
            IConsoleOutput console,
            IProgressReporter progressReporter,
            IOpenApiDocumentFactory openApiDocumentFactory,
            INSwagOptions options,
            INSwagCodeGeneratorFactory codeGeneratorFactory,
            ICodeGenerator generator,
            string outputFile,
            string code)
        {
            var sut = new NSwagCommand(
                console,
                progressReporter,
                openApiDocumentFactory,
                options,
                codeGeneratorFactory);

            sut.OutputFile = outputFile;

            Mock.Get(generator)
            .Setup(c => c.GenerateCode(progressReporter))
            .Returns(code);

            new Func <Task>(sut.OnExecuteAsync).Should().NotThrow();
        }
Exemplo n.º 16
0
 public void Render(GameTime time, IConsoleOutput console)
 {
     foreach (var item in Components)
     {
         item.Render(time, console);
     }
 }
Exemplo n.º 17
0
        public async void Execute(IConsoleOutput output, string command)
        {
            try
            {
                var reply     = string.Empty;
                var arguments = command.Split(new char[] { ' ' });

                if (arguments[0].Equals("Loaded", StringComparison.OrdinalIgnoreCase))
                {
                    reply = getLoadedScripts();
                }
                else if (arguments[0].Equals("Running", StringComparison.OrdinalIgnoreCase))
                {
                    reply = getRunningScripts();
                }
                else if (arguments[0].Equals("Exec", StringComparison.OrdinalIgnoreCase))
                {
                    var scriptFile = arguments[1];
                    ExecuteScript(scriptFile);
                }
                else if (arguments[0].Equals("Cancel", StringComparison.OrdinalIgnoreCase))
                {
                    CancelScript();
                }
                else
                {
                    reply = await ExecuteExpression(command);
                }
                output.Append(reply);
            }
            catch (Exception ex)
            {
                output.Append(ex.Message);
            }
        }
Exemplo n.º 18
0
        public Display(IBus bus, IConsoleOutput consoleOutput) : base(8 * 1024)
        {
            _bus           = bus;
            _consoleOutput = consoleOutput;

            _consoleOutput.SetPalette(new uint[]
            {
                0x0fbc9b,
                0x0fac8b,
                0x306230,
                0x0f380f,
                0xffffff,
                0xb0b0b0,
                0x808080,
                0x404040,
                0x000000,
                0xff0000,
                0x00ff00,
                0x0000ff,
                0xffff00,
                0xff00ff,
                0x00ffff,
                0xff0088,
            });

            DisplayControl = new DisplayControl();
        }
Exemplo n.º 19
0
        static int Parseline(IEnumerator <char> e, IConsoleOutput target)
        {
            VariableCollection vars;

            if (target is ScriptTargetWrapper v && v.Session.Scope.Any())
            {
                vars = v.Session.Scope.Peek().Locals;
            }
Exemplo n.º 20
0
 public OutputManager(IConsoleOutput consoleOutput,
                      ISystemSettingsWrapper systemSettingsWrapper,
                      ILogWrapper logWrapper)
 {
     this.consoleOutput         = consoleOutput;
     this.systemSettingsWrapper = systemSettingsWrapper;
     this.logWrapper            = logWrapper;
 }
Exemplo n.º 21
0
        public IConsoleInput CreateConsole(IConsoleOutput consoleOutput)
        {
            var console = _classFactory.Create <SmartHalConsole>();

            console.SetOutput(consoleOutput);

            return(console);
        }
Exemplo n.º 22
0
 public CompileCommandHandler(
     IFileSystem fileSystem,
     IHttpClientFactory httpClientFactory,
     IConfigurationStore configurationStore,
     IConsoleOutput output)
     : base(fileSystem, httpClientFactory, configurationStore, output)
 {
 }
Exemplo n.º 23
0
 public FieldView(Field <IAnimal> field, IConsoleOutput consoleOutput, IConsoleWindow consoleWindow, ISymbolProvider animalSymbolProvider, IStringDrawer stringDrawer, StringBuilder fieldAsStringBuilder) : this(field)
 {
     _consoleOutput        = consoleOutput;
     _consoleWindow        = consoleWindow;
     _animalSymbolProvider = animalSymbolProvider;
     _fieldAsStringBuilder = fieldAsStringBuilder;
     _stringDrawer         = stringDrawer;
 }
Exemplo n.º 24
0
        private ConsoleLineInput CreateInputWithText(IConsoleOutput consoleOutput, string text, ConsoleCompletionHandler completionHandler = null)
        {
            var input = CreateInput(consoleOutput, completionHandler);

            input.Insert(text);
            input.MoveCursorToEnd();

            return(input);
        }
Exemplo n.º 25
0
 public UpdateCommandHandler(
     IFileSystem fileSystem,
     IHttpClientFactory httpClientFactory,
     IConsoleOutput output)
 {
     FileSystem        = fileSystem;
     HttpClientFactory = httpClientFactory;
     Output            = output;
 }
Exemplo n.º 26
0
        public void Render(GameTime time, IConsoleOutput console)
        {
            var updatables = this.Behaviours.Where(n => n.GetType().IsAssignableFrom(typeof(IRenderable))).Cast <IRenderable>();

            foreach (var renderer in updatables)
            {
                renderer.Render(time, console);
            }
        }
Exemplo n.º 27
0
        private ConsoleLineInput CreateInputWithText(IConsoleOutput consoleOutput, string text, ITokenCompleter tokenCompleter = null)
        {
            var input = CreateInput(consoleOutput, tokenCompleter);

            input.Insert(text);
            input.MoveCursorToEnd();

            return(input);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Creates a new context that writes output to the given IConsoleOutput object.
        /// </summary>
        /// <param name="clearMessage">A default message shown every time the screen is cleared.</param>
        public Context(IConsoleOutput console, IUserInput inputHandle, string clearMessage = "")
        {
            Commands             = new();
            PromptSymbol         = "-> ";
            IndentationLevel     = 0;
            OnScreenClearMessage = clearMessage ?? "";

            OutputHandle = console;
            InputHandle  = inputHandle;
        }
Exemplo n.º 29
0
 public void setup()
 {
     fakeFileOutput    = Substitute.For <IFileOutput>();
     fakeConsoleOutput = Substitute.For <IConsoleOutput>();
     timeStamp         = "235928121999";
     uut = new EventList();
     td1 = new TrackData("ABC123", 10000, 10000, 1000, timeStamp, 100, 45, fakeConsoleOutput);
     td2 = new TrackData("DEF123", 10000, 10000, 1000, timeStamp, 100, 45, fakeConsoleOutput);
     td3 = new TrackData("XYZ123", 10000, 10000, 1000, timeStamp, 100, 45, fakeConsoleOutput);
 }
Exemplo n.º 30
0
 public UpdateCommandHandler(
     IFileSystem fileSystem,
     IHttpClientFactory httpClientFactory,
     IConfigurationStore configurationStore,
     IConsoleOutput output)
 {
     FileSystem         = fileSystem;
     HttpClientFactory  = httpClientFactory;
     ConfigurationStore = configurationStore;
     Output             = output;
 }
Exemplo n.º 31
0
 protected override void Executed(Params args, IConsoleOutput target)
 {
     if (target is ScriptTargetWrapper i)
     {
         i.Session.Abort();
     }
     else
     {
         ThrowGenericError("This command is only valid in script files", ErrorCode.INVALID_CONTEXT);
     }
 }
 public SwaggerCodegenCommand(
     IConsoleOutput console,
     IProgressReporter progressReporter,
     IGeneralOptions options,
     IProcessLauncher processLauncher,
     ISwaggerCodegenFactory factory) : base(console, progressReporter)
 {
     this.options         = options ?? throw new ArgumentNullException(nameof(options));
     this.processLauncher = processLauncher ?? throw new ArgumentNullException(nameof(processLauncher));
     this.factory         = factory ?? throw new ArgumentNullException(nameof(factory));
 }
Exemplo n.º 33
0
        /// <summary>
        /// Primary constructor.
        /// </summary>
        /// <param name="lineInput">Line input engine.</param>
        /// <param name="consoleInput">Interface for interacting with the input
        /// console; a default implementation is used if this parameter is null.
        /// </param>
        /// <param name="consoleOutput">Interface for interacting with the output
        /// console; a default implementation is used if this parameter is null.
        /// </param>
        /// <param name="keyBindingSet">The key bindings to use in the reader.
        /// Default bindings are used if this parameter is null.</param>
        public ConsoleReader(IConsoleLineInput lineInput, IConsoleInput consoleInput = null, IConsoleOutput consoleOutput = null, IReadOnlyConsoleKeyBindingSet keyBindingSet = null)
        {
            if (lineInput == null)
            {
                throw new ArgumentNullException(nameof(lineInput));
            }

            LineInput = lineInput;
            ConsoleInput = consoleInput ?? BasicConsoleInputAndOutput.Default;
            ConsoleOutput = consoleOutput ?? BasicConsoleInputAndOutput.Default;
            KeyBindingSet = keyBindingSet ?? ConsoleKeyBindingSet.Default;

            _defaultCursorSize = ConsoleOutput.CursorSize;
        }
		public void Intialize()
		{
			_fileSystemHelper = Substitute.For<IFileSystemHelper>();
			_directory = Substitute.For<IDirectory>();
			_fileOutput = Substitute.For<IFileOutput>();
			_consoleOutput = Substitute.For<IConsoleOutput>();
			_utils = Substitute.For<IUtils>();
			_tagsOperation = Substitute.For<ITagsOperation>();
			_tagHelper = Substitute.For<ITagHelper>();
			_file = Substitute.For<IFile>();

			_target = new SearchOperation(
				_fileSystemHelper , 
				_directory, 
				_fileOutput, 
				_consoleOutput, 
				_file, 
				_utils, 
				_tagsOperation,
				_tagHelper);
		}
Exemplo n.º 35
0
		/// <summary>
		/// Initializes a new instance of the <see cref="SelfMediaDatabase.Core.Operations.Search.SearchOperation"/> class.
		/// </summary>
		/// <param name="fileSystemHelper">File system helper.</param>
		/// <param name="directory">Directory.</param>
		/// <param name="fileOutput">File output.</param>
		/// <param name="consoleOutput">Console output.</param>
		/// <param name="file">Injectable wrapper of <see cref="System.IO.File"/>.</param>
		/// <param name="utils">Some utils methods provider.</param>
		/// <param name="tagsOperation">Tags operation library.</param>
		/// <param name="tagHelper">Helper to access to tags of media files.</param>
		public SearchOperation(
			IFileSystemHelper fileSystemHelper, 
			IDirectory directory, 
			IFileOutput fileOutput, 
			IConsoleOutput consoleOutput, 
			IFile file, 
			IUtils utils,
			ITagsOperation tagsOperation,
			ITagHelper tagHelper)
		{
			if (fileSystemHelper == null)
				throw new ArgumentNullException("fileSystemHelper");
			if (directory == null)
				throw new ArgumentNullException("directory");
			if (fileOutput == null)
				throw new ArgumentNullException("fileOutput");
			if (consoleOutput == null)
				throw new ArgumentNullException("consoleOutput");
			if (file == null)
				throw new ArgumentNullException("file");
			if (utils == null)
				throw new ArgumentNullException("utils");
			if (tagsOperation == null)
				throw new ArgumentNullException("tagsOperation");
			if (tagHelper == null)
				throw new ArgumentNullException("exifHelper");

			_fileSystemHelper = fileSystemHelper;
			_directory = directory;
			_fileOutput = fileOutput;
			_consoleOutput = consoleOutput;
			_file = file;
			_utils = utils;
			_tagsOperation = tagsOperation;
			_tagHelper = tagHelper;
		}
Exemplo n.º 36
0
 public SaleController(IBarcodeReader barcodeReader, IConsoleOutput consoleOutput,
                       IDictionary<string, string> pricesByProduct)
     : this(barcodeReader, new SaleView(consoleOutput), new Catalog(pricesByProduct))
 {
 }
Exemplo n.º 37
0
 public SelectionMenu(IConsoleOutput consoleOutput, IInput input)
 {
     _consoleOutput = consoleOutput;
     _input = input;
 }
Exemplo n.º 38
0
 public OutputService(IConsoleOutput consoleOutput)
 {
     _consoleOutput = consoleOutput;
 }
Exemplo n.º 39
0
 public SaleView(IConsoleOutput consoleOutput)
 {
     _consoleOutput = consoleOutput;
 }