Example #1
0
        public Task<CommandParserOutputDto> ParseCommand(string input, CancellationToken cancellationToken)
        {
            var output = new CommandParserOutputDto();

             if (!string.IsNullOrEmpty(input)) {
            var matches = Regex.Matches(input, REGEX_EXPR, RegexOptions.IgnoreCase);
            foreach (Match m in matches) {
               var command = m.Groups[REGEX_EXPRX_COMD]?.Value;
               var x = m.Groups[REGEX_EXPRX_X]?.Value;
               var y = m.Groups[REGEX_EXPRX_Y]?.Value;
               var c = m.Groups[REGEX_EXPRX_COLOR]?.Value;

               if (!string.IsNullOrEmpty(command)
                  && !string.IsNullOrEmpty(x)
                  && !string.IsNullOrEmpty(y)
                  && !string.IsNullOrEmpty(c)
                  && NOT_ALLOWED_CHARS.All(chr => !c.Contains(chr))) {

                  output.WasHandled = true;
                  output.Output = new FillCommandDto() {
                     X = int.Parse(x),
                     Y = int.Parse(y),
                     Color = char.Parse(c)
                  };

                  break;
               }
            }
             }

             return Task.FromResult(output);
        }
Example #2
0
        public Task <CommandParserOutputDto> ParseCommand(string input, CancellationToken cancellationToken)
        {
            var output = new CommandParserOutputDto();

            if (!string.IsNullOrEmpty(input))
            {
                var matches = Regex.Matches(input, REGEX_EXPR, RegexOptions.IgnoreCase);
                foreach (Match m in matches)
                {
                    var command = m.Groups[REGEX_EXPRX_COMD]?.Value;
                    var height  = m.Groups[REGEX_EXPRX_HEIGHT]?.Value;
                    var width   = m.Groups[REGEX_EXPRX_WIDTH]?.Value;

                    if (!string.IsNullOrEmpty(command) &&
                        !string.IsNullOrEmpty(height) &&
                        !string.IsNullOrEmpty(width))
                    {
                        output.WasHandled = true;
                        output.Output     = new CanvasCommandDto()
                        {
                            Height = int.Parse(height),
                            Width  = int.Parse(width)
                        };

                        break;
                    }
                }
            }

            return(Task.FromResult(output));
        }
Example #3
0
        public async Task Update(CommandParserOutputDto input, CancellationToken cancellationToken)
        {
            // exit (if asked)
            cancellationToken.ThrowIfCancellationRequested();

            // todo : add validation here

            if (_renders != null)
            {
                foreach (var r in _renders)
                {
                    await r.Render(input.Output, _buffer, _screenSize, cancellationToken).ConfigureAwait(false);
                }
            }
        }
Example #4
0
        public Task <CommandParserOutputDto> ParseCommand(string input, CancellationToken cancellationToken)
        {
            var output = new CommandParserOutputDto();

            if (!string.IsNullOrEmpty(input))
            {
                var matches = Regex.Matches(input, REGEX_EXPR, RegexOptions.IgnoreCase);
                foreach (Match m in matches)
                {
                    if (!string.IsNullOrEmpty(m.Groups[REGEX_EXPRX_COMD]?.Value))
                    {
                        output.WasHandled = true;
                        output.Output     = new QuitCommandDto();
                        break;
                    }
                }
            }

            return(Task.FromResult(output));
        }
Example #5
0
        public Task <CommandParserOutputDto> ParseCommand(string input, CancellationToken cancellationToken)
        {
            var output = new CommandParserOutputDto();

            if (!string.IsNullOrEmpty(input))
            {
                var matches = Regex.Matches(input, REGEX_EXPR, RegexOptions.IgnoreCase);
                foreach (Match m in matches)
                {
                    var command = m.Groups[REGEX_EXPRX_COMD]?.Value;
                    var x1      = m.Groups[REGEX_EXPRX_X1]?.Value;
                    var y1      = m.Groups[REGEX_EXPRX_Y1]?.Value;
                    var x2      = m.Groups[REGEX_EXPRX_X2]?.Value;
                    var y2      = m.Groups[REGEX_EXPRX_Y2]?.Value;

                    if (!string.IsNullOrEmpty(command) &&
                        !string.IsNullOrEmpty(x1) &&
                        !string.IsNullOrEmpty(y1) &&
                        !string.IsNullOrEmpty(x2) &&
                        !string.IsNullOrEmpty(y2))
                    {
                        output.WasHandled = true;
                        output.Output     = new RectCommandDto()
                        {
                            X1 = int.Parse(x1),
                            Y1 = int.Parse(y1),
                            X2 = int.Parse(x2),
                            Y2 = int.Parse(y2)
                        };

                        break;
                    }
                }
            }

            return(Task.FromResult(output));
        }