Exemple #1
0
        ///////////////////////////////////////////////////////////////////////

        public ReturnCode FireTraces(
            BreakpointType breakpointType,
            Interpreter interpreter,
            ITraceInfo traceInfo,
            ref Result result
            )
        {
            ReturnCode code = ReturnCode.Ok;

            if (traces != null)
            {
                //
                // NOTE: Save the current variable flags.
                //
                VariableFlags savedFlags = flags;

                //
                // NOTE: Prevent endless trace recursion.
                //
                flags |= VariableFlags.NoTrace;

                try
                {
                    //
                    // NOTE: Process each trace (as long as they all continue
                    //       to succeed).
                    //
                    foreach (ITrace trace in traces)
                    {
                        if ((trace != null) && !EntityOps.IsDisabled(trace))
                        {
                            //
                            // NOTE: If possible, set the Trace property of the
                            //       TraceInfo to the one we are about to execute.
                            //
                            if (traceInfo != null)
                            {
                                traceInfo.Trace = trace;
                            }

                            //
                            // NOTE: Since variable traces can basically do anything
                            //       they want, we wrap them in a try block to prevent
                            //       exceptions from escaping.
                            //
                            interpreter.EnterTraceLevel();

                            try
                            {
                                code = trace.Execute(
                                    breakpointType, interpreter, traceInfo, ref result);
                            }
                            catch (Exception e)
                            {
                                //
                                // NOTE: Translate exceptions to a failure return.
                                //
                                result = String.Format(
                                    "caught exception while firing variable trace: {0}",
                                    e);

                                code = ReturnCode.Error;
                            }
                            finally
                            {
                                interpreter.ExitTraceLevel();
                            }

                            //
                            // NOTE: Check for exception results specially because we
                            //       treat "Break" different from other return codes.
                            //
                            if (code == ReturnCode.Break)
                            {
                                //
                                // NOTE: Success; however, skip processing further
                                //       traces for this variable operation.
                                //
                                code = ReturnCode.Ok;
                                break;
                            }
                            else if (code != ReturnCode.Ok)
                            {
                                //
                                // NOTE: Some type of failure (or exception), stop
                                //       processing for this variable operation.
                                //
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    //
                    // NOTE: Restore the saved variable flags.
                    //
                    flags = savedFlags;
                }
            }

            return(code);
        }