Beispiel #1
0
        async Task <bool> OnEvaluateOnCallFrame(MessageId msg_id, int scope_id, string expression, CancellationToken token)
        {
            try
            {
                var context = GetContext(msg_id);
                if (context.CallStack == null)
                {
                    return(false);
                }

                var resolver = new MemberReferenceResolver(this, context, msg_id, scope_id, logger);

                JObject retValue = await resolver.Resolve(expression, token);

                if (retValue == null)
                {
                    retValue = await EvaluateExpression.CompileAndRunTheExpression(expression, resolver, token);
                }

                if (retValue != null)
                {
                    SendResponse(msg_id, Result.OkFromObject(new
                    {
                        result = retValue
                    }), token);
                }
                else
                {
                    SendResponse(msg_id, Result.Err($"Unable to evaluate '{expression}'"), token);
                }
            }
            catch (ReturnAsErrorException ree)
            {
                SendResponse(msg_id, ree.Error, token);
            }
            catch (Exception e)
            {
                logger.LogDebug($"Error in EvaluateOnCallFrame for expression '{expression}' with '{e}.");
                SendResponse(msg_id, Result.Exception(e), token);
            }

            return(true);
        }
Beispiel #2
0
        async Task <bool> OnEvaluateOnCallFrame(MessageId msg_id, int scope_id, string expression, CancellationToken token)
        {
            try
            {
                var context = GetContext(msg_id);
                if (context.CallStack == null)
                {
                    return(false);
                }

                var varValue = await TryGetVariableValue(msg_id, scope_id, expression, false, token);

                if (varValue != null)
                {
                    SendResponse(msg_id, Result.OkFromObject(new
                    {
                        result = varValue["value"]
                    }), token);
                    return(true);
                }

                string retValue = await EvaluateExpression.CompileAndRunTheExpression(this, msg_id, scope_id, expression, token);

                SendResponse(msg_id, Result.OkFromObject(new
                {
                    result = new
                    {
                        value = retValue
                    }
                }), token);
                return(true);
            }
            catch (Exception e)
            {
                logger.LogDebug(e, $"Error in EvaluateOnCallFrame for expression '{expression}.");
            }
            return(false);
        }