public RCode Execute(int id, [FromBody] RCode code)
        {
            GraphicsDevice.ClearImages();

            if (string.IsNullOrEmpty(code.Block))
            {
                code.Result = RResult.Empty;
                return code;
            }

            var statements = code.Block.Split(new[] { ';', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); //TODO: Use tokenizer.
            try
            {
                CharacterDevice.ResetConsole();
                var evaluated = statements.Select(_engine.Evaluate).ToList();
                var plots = GraphicsDevice.GetImages().Select(RenderSvg).ToList();
                var console = CharacterDevice.GetOutput().ToList();
                var internalResults = evaluated.Select(Mapper.Map).ToList();

                var result = new RResult
                {
                        Plots = plots,
                        Console = console,
                        InternalResults = internalResults
                };

                code.Result = result;
                return code;
            }
            catch (Exception ex)
            {
                //TODO: Service reliability logging
                return CreateErrorResult(code, ex);
            }
        }
Пример #2
0
        public RCode Execute(int id, [FromBody] RCode code)
        {
            GraphicsDevice.ClearImages();

            if (string.IsNullOrEmpty(code.Block))
            {
                code.Result = RResult.Empty;
                return(code);
            }

            var statements = code.Block.Split(new[] { ';', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); //TODO: Use tokenizer.

            try
            {
                CharacterDevice.ResetConsole();
                var evaluated       = statements.Select(_engine.Evaluate).ToList();
                var plots           = GraphicsDevice.GetImages().Select(RenderSvg).ToList();
                var console         = CharacterDevice.GetOutput().ToList();
                var internalResults = evaluated.Select(Mapper.Map).ToList();

                var result = new RResult
                {
                    Plots           = plots,
                    Console         = console,
                    InternalResults = internalResults
                };


                code.Result = result;
                return(code);
            }
            catch (Exception ex)
            {
                //TODO: Service reliability logging
                return(CreateErrorResult(code, ex));
            }
        }