コード例 #1
0
        private string EvaluateCode(string withRecordValues)
        {
            var builder = new StringBuilder(withRecordValues);

            foreach (var codeBlock in _syntaxParser.GetCodeBlocksIn(withRecordValues))
            {
                var codeResult = _evaluator.Run(codeBlock.Code.RawText);
                var result     = codeResult.ResultSet ? codeResult.Result : string.Empty;
                builder.Replace(codeBlock.RawText, result.ToString());
            }
            return(builder.ToString());
        }
コード例 #2
0
        private IDbCommandResult GetResultOf(string command)
        {
            if (command.Equals("reset"))
            {
                _cSharpEvaluator.Init();
                return(new MessageResult(string.Format("C# Evaluator is reset")));
            }

            command = CommandModifier.Modify(command);
            var builder = new StringBuilder();

            builder.AppendFormat("Running: {0}", command).AppendLine();

            var result = _cSharpEvaluator.Run(command);

            if (result.ResultSet)
            {
                if (result.Result == null)
                {
                    return(new MessageResult("null"));
                }
                if (result.Result.IsCollection())
                {
                    return(_collectionConverter.Convert((IEnumerable)result.Result));
                }
                if (result.Result.IsComplexType())
                {
                    return(_collectionConverter.Convert(new[] { result.Result }));
                }
                builder.AppendLine(result.Result == null ? "null" : result.Result.ToString());
            }
            if (result.HasMessage)
            {
                builder.AppendLine(result.Message);
            }
            if (result.HasReport)
            {
                builder.AppendLine(result.Report);
            }
            return(new MessageResult(builder.ToString()));
        }