Ejemplo n.º 1
0
        public CorValue NewArray(CorEvaluationContext ctx, CorType elemType, int size)
        {
            ManualResetEvent doneEvent = new ManualResetEvent(false);
            CorValue         result    = null;

            EvalEventHandler completeHandler = delegate(object o, CorEvalEventArgs eargs)
            {
                OnEndEvaluating();
                result = eargs.Eval.Result;
                doneEvent.Set();
                eargs.Continue = false;
            };

            EvalEventHandler exceptionHandler = delegate(object o, CorEvalEventArgs eargs)
            {
                OnEndEvaluating();
                result = eargs.Eval.Result;
                doneEvent.Set();
                eargs.Continue = false;
            };

            try {
                process.OnEvalComplete  += completeHandler;
                process.OnEvalException += exceptionHandler;

                ctx.Eval.NewParameterizedArray(elemType, 1, 1, 0);
                process.SetAllThreadsDebugState(CorDebugThreadState.THREAD_SUSPEND, ctx.Thread);
                OnStartEvaluating();
                ClearEvalStatus();
                process.Continue(false);

                if (doneEvent.WaitOne(ctx.Options.EvaluationTimeout, false))
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }
            finally {
                process.OnEvalComplete  -= completeHandler;
                process.OnEvalException -= exceptionHandler;
            }
        }
Ejemplo n.º 2
0
        public CorValue RuntimeInvoke(CorEvaluationContext ctx, CorFunction function, CorType[] typeArgs, CorValue thisObj, CorValue[] arguments)
        {
            if (!ctx.Thread.ActiveChain.IsManaged)
            {
                throw new EvaluatorException("Cannot evaluate expression because the thread is stopped in native code.");
            }

            CorValue[] args;
            if (thisObj == null)
            {
                args = arguments;
            }
            else
            {
                args    = new CorValue[arguments.Length + 1];
                args[0] = thisObj;
                arguments.CopyTo(args, 1);
            }

            CorMethodCall mc        = new CorMethodCall();
            CorValue      exception = null;
            CorEval       eval      = ctx.Eval;

            EvalEventHandler completeHandler = delegate(object o, CorEvalEventArgs eargs) {
                OnEndEvaluating();
                mc.DoneEvent.Set();
                eargs.Continue = false;
            };

            EvalEventHandler exceptionHandler = delegate(object o, CorEvalEventArgs eargs) {
                OnEndEvaluating();
                exception = eargs.Eval.Result;
                mc.DoneEvent.Set();
                eargs.Continue = false;
            };

            process.OnEvalComplete  += completeHandler;
            process.OnEvalException += exceptionHandler;

            mc.OnInvoke = delegate {
                if (function.GetMethodInfo(this).Name == ".ctor")
                {
                    eval.NewParameterizedObject(function, typeArgs, args);
                }
                else
                {
                    eval.CallParameterizedFunction(function, typeArgs, args);
                }
                process.SetAllThreadsDebugState(CorDebugThreadState.THREAD_SUSPEND, ctx.Thread);
                ClearEvalStatus();
                OnStartEvaluating();
                process.Continue(false);
            };
            mc.OnAbort = delegate {
                eval.Abort();
            };
            mc.OnGetDescription = delegate {
                System.Reflection.MethodInfo met = function.GetMethodInfo(ctx.Session);
                if (met != null)
                {
                    return(met.Name);
                }
                else
                {
                    return("<Unknown>");
                }
            };

            try {
                ObjectAdapter.AsyncExecute(mc, ctx.Options.EvaluationTimeout);
            }
            finally {
                process.OnEvalComplete  -= completeHandler;
                process.OnEvalException -= exceptionHandler;
            }

            if (exception != null)
            {
/*				ValueReference<CorValue, CorType> msg = ctx.Adapter.GetMember (ctx, val, "Message");
 *                              if (msg != null) {
 *                                      string s = msg.ObjectValue as string;
 *                                      mc.ExceptionMessage = s;
 *                              }
 *                              else
 *                                      mc.ExceptionMessage = "Evaluation failed.";*/
                CorValRef vref = new CorValRef(exception);
                throw new EvaluatorException("Evaluation failed: " + ObjectAdapter.GetValueTypeName(ctx, vref));
            }

            return(eval.Result);
        }